CamBam

Resources => Scripts and Plugins => Topic started by: dh42 on September 10, 2011, 16:10:40 pm

Title: Select by kind of object
Post by: dh42 on September 10, 2011, 16:10:40 pm
Hello,

I begin to play with script in VB, the thing I wish to do is a "select by object type".

the goal is to select all objects of a same kind (circles, points, polylines) on the visible layers

After exploration of the script in the CB folder, if found how to test the kind of an object in a selection list, how to unselect all, but not how to unselect the current object or, other way to do, to get a list of all objects on visible layers (even unselected objects) and select or unselect it.

I try to write this : test object by object in the selection and unselect the current object if not a circle ... but that don't works  :'(

Code: [Select]
sub main

'unselect other than Circle object in current selection

if view.SelectedEntities.Length > 0 then

for each ent as Entity in view.SelectedEntities

if typeof ent is Circle

ent.Selected=true

else

ent.Selected=false

end if

next ent

end if

view.RefreshView()

end sub

Is there someone that can help my to write that ? 

thanks

++
David
Title: Re: Select by kind of object
Post by: 10bulls on October 04, 2011, 21:38:37 pm
Sorry for overlooking this one David,

Here is a solution:

Code: [Select]
sub main
'unselect other than Circle object in current selection
dim newselection as ArrayList = new ArrayList()

for each ent as Entity in view.SelectedEntities
if typeof ent is Circle
newselection.Add(ent)
end if
next ent

view.Select(newselection.ToArray())
view.RefreshView()

end sub

I hope this helps!
Title: Re: Select by kind of object
Post by: dh42 on October 04, 2011, 21:46:50 pm
Hello Andy,

Yes !! nice thats help me  ;D

thanks

++
David
Title: Re: Select by kind of object
Post by: dh42 on October 08, 2011, 21:16:44 pm
Hello,

I add a windows for selection of the kind of shape.

Why the shapes are not selected in the layer tree ?  the tree must be refreshed too ?

++
David

Title: Re: Select by kind of object
Post by: 10bulls on October 08, 2011, 21:53:01 pm
Anywhere within your script, add this line...

Code: [Select]
CamBamConfig.Defaults.ReloadTreeAfterScript = false

Normally, after a script has finished executing some code is run to reload the drawing tree view (in case the script has changed anything within the drawing).
ReloadTreeAfterScript = false will prevent this happening, so your selections will stay in place.

I also notice the 'after script' code also does a view.RefreshView(), so you could also leave out that line in your script.

The ReloadTreeAfterScript property is not saved in the configuration file, so the next time CamBam is restarted it's value will revert back to 'True'.
Title: Re: Select by kind of object
Post by: dh42 on October 09, 2011, 00:36:34 am
Hello,

OK, thanks Andy  ;)

++
David
Title: Re: Select by kind of object
Post by: dh42 on November 29, 2012, 21:37:13 pm
Hello,

My script don't works on N, I get this message.

Une exception a été levée par la cible d'un appel.
Impossible d'effectuer un cast d'un objet de type 'System.Object[]' en type 'CamBam.CAD.Entity[]'.  :o

Help !!!   ;D

++ ;)
David
Title: Re: Select by kind of object
Post by: 10bulls on November 29, 2012, 22:21:53 pm
Sorry about that one!  :-[

Change this line...

Code: [Select]
view.Select(newselection.ToArray())
to
Code: [Select]
view.Select(newselection.ToArray(GetType(Entity)))

OR,
you can change

Code: [Select]
dim newselection as ArrayList = new ArrayList()
to
Code: [Select]
dim newselection as Generic.List(of Entity) = new Generic.List(of Entity)()

but not both!  ;)
Title: Re: Select by kind of object
Post by: dh42 on November 29, 2012, 22:39:08 pm
Hello,

Thanks  ;D

No chances that I found that myself  :o

There is a change ; when I choose "polyline", the polyrectangles are selected too (but if I choses "polyrectangle" the polylines are not selected)

The polyrectangles are assimilated to polylines in rev N ?

Nice that ability to resize the rectangle by mouse  ;D

It would be nice if we could draw and place the stock bloc in the same way  ;)

++
David
Title: Re: Select by kind of object
Post by: dh42 on July 12, 2014, 20:34:32 pm
Hello,

Here is the plugin version for this tool.

++
David
Title: Re: Select by kind of object
Post by: lloydsp on July 12, 2014, 20:59:27 pm
Thanks, David.  I'll try it ASAP.

Lloyd
Title: Re: Select by kind of object
Post by: lloydsp on July 13, 2014, 01:33:53 am
NICE, David!  I'll be using that frequently.

Can you make the selection of type "clickable"?

That's neat.  Is source coming?

Lloyd
Title: Re: Select by kind of object
Post by: dh42 on July 13, 2014, 13:17:39 pm
Hello Lloyd,

Quote
Can you make the selection of type "clickable"?

Yes, it's planed for next release (and with multiple choice)

the sources is attached ;)  see reply #18

++
David
Title: Re: Select by kind of object
Post by: lloydsp on July 13, 2014, 14:12:38 pm
Thank you sir!  New tricks to learn!

Lloyd
Title: Re: Select by kind of object
Post by: dh42 on July 14, 2014, 18:26:18 pm
Hello,

A little release that add buttons to select the shape type.

++
David
Title: Re: Select by kind of object
Post by: dh42 on June 11, 2015, 16:55:11 pm
Hello,

A new release that add a filter for arcs and circle (min and max radius/diameter)

http://www.atelier-des-fougeres.fr/Cambam/Aide/Plugins/select_by_objtype.html

++
David
Title: Re: Select by kind of object
Post by: lloydsp on June 11, 2015, 17:48:01 pm
Marvelous, David! (and fast!) Thank you for the work.

Lloyd
Title: Re: Select by kind of object
Post by: EddyCurrent on June 11, 2015, 17:50:26 pm
Marvelous, David! (and fast!) Thank you for the work.

Lloyd

+1
Title: Re: Select by kind of object
Post by: dh42 on June 11, 2015, 17:55:17 pm
And the source  ;)

++
David
Title: Re: Select by kind of object
Post by: lloydsp on June 11, 2015, 21:02:29 pm
A very minor problem, David.

You're rounding the range window entries to "thousandths", which might be OK for mm measures, but is too great a tolerance for inch measures.  We need it to 'tenths' (of thousandths... 4 digits past the decimal).

Lloyd
Title: Re: Select by kind of object
Post by: dh42 on June 11, 2015, 21:13:39 pm
Quote
A very minor problem, David.

repaired ;)

download version 1.101 on the web site

++
David
Title: Re: Select by kind of object
Post by: lloydsp on June 11, 2015, 21:35:49 pm
Thank you so much!  I've already used this feature to benefit.

Lloyd
Title: Re: Select by kind of object
Post by: Marek on October 14, 2017, 21:17:28 pm
Hi David

Please add filter to lines length to your plugin. The Inkscape's DXF contains a lot of zero length lines. It could be great to have a tool which allows to select and remove all of them.
Title: Re: Select by kind of object
Post by: dh42 on October 14, 2017, 23:05:19 pm
Hello

I think that maybe this other plugin can do the trick for this usage.

http://www.atelier-des-fougeres.fr/Cambam/Aide/Plugins/FileCleaner.html

++
David
Title: Re: Select by kind of object
Post by: Dragonfly on December 18, 2017, 20:02:04 pm
David,
any chance for a version for CB 1.0? It happened so that I needed selective selection - to remove surfaces from an imported .stp file and leave the 'skeleton' geometry.
Somewhere in this thread I found a script from your early work, downloaded it, modified it with what Andy wrote as advice and did the work anyway. :)
Title: Re: Select by kind of object
Post by: dh42 on December 18, 2017, 20:32:28 pm
Hello

This plugin is also working on CB 1.0 (I use it regularly)

++
David
Title: Re: Select by kind of object
Post by: Dragonfly on December 20, 2017, 09:25:20 am
Forgot to say that I had CamBam for Linux in mind. Didn't work when I tried.
Title: Re: Select by kind of object
Post by: EddyCurrent on December 20, 2017, 09:40:01 am
Were there any error messages indicating why it didn't work ?
Title: Re: Select by kind of object
Post by: Dragonfly on December 20, 2017, 11:50:14 am
No, the moment I click on 'select by object type' in the Edit menu CB simply terminates without any error message.
No complaining messages on starting CB.
Now it came to my mind - could it be because I am running 64 bit version?
Title: Re: Select by kind of object
Post by: dh42 on December 20, 2017, 19:48:14 pm
Hello

Quote
Now it came to my mind - could it be because I am running 64 bit version?

No, this plugin is not working on Linux 32 too (on both 0.98 and 1.0)

++
David
Title: Re: Select by kind of object
Post by: dh42 on December 20, 2017, 21:37:24 pm
Re

Try with this new version
http://www.atelier-des-fougeres.fr/Cambam/Aide/Plugins/select_by_objtype.html

++
David
Title: Re: Select by kind of object
Post by: Dragonfly on December 20, 2017, 21:58:11 pm
Already tried and it works.

Special thanks, again!
Title: Re: Select by kind of object
Post by: Dragonfly on August 04, 2020, 17:26:11 pm
Anywhere within your script, add this line...

Code: [Select]
CamBamConfig.Defaults.ReloadTreeAfterScript = false

Normally, after a script has finished executing some code is run to reload the drawing tree view (in case the script has changed anything within the drawing).
ReloadTreeAfterScript = false will prevent this happening, so your selections will stay in place.

I also notice the 'after script' code also does a view.RefreshView(), so you could also leave out that line in your script.

The ReloadTreeAfterScript property is not saved in the configuration file, so the next time CamBam is restarted it's value will revert back to 'True'.

Sorry about that one!  :-[

Change this line...

Code: [Select]
view.Select(newselection.ToArray())
to
Code: [Select]
view.Select(newselection.ToArray(GetType(Entity)))

OR,
you can change

Code: [Select]
dim newselection as ArrayList = new ArrayList()
to
Code: [Select]
dim newselection as Generic.List(of Entity) = new Generic.List(of Entity)()

but not both!  ;)

Alleluia!  :)
I knew I've seen a clue how to make a selection editable after a script is used to select objects by some criteria.
Took me half a day of searching though.

Now, if someone can show me how those lists of entity are initialized in Python ...  ::)
Title: Re: Select by kind of object
Post by: dh42 on August 05, 2020, 05:38:44 am
Hello

We also talk about this a few month ago here

https://cambamcnc.com/forum/index.php?topic=8488.msg67361#msg67361

But I've no idea for the python syntax ... sorry.

I'll add this tips to the snippet page ;) it can be useful for others ;)

++
David