Author Topic: Select by kind of object  (Read 28274 times)

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Select by kind of object
« 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

Offline 10bulls

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 2163
  • Coding Jedi
    • View Profile
    • www.cambam.info
Re: Select by kind of object
« Reply #1 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!

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Select by kind of object
« Reply #2 on: October 04, 2011, 21:46:50 pm »
Hello Andy,

Yes !! nice thats help me  ;D

thanks

++
David

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Select by kind of object
« Reply #3 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


Offline 10bulls

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 2163
  • Coding Jedi
    • View Profile
    • www.cambam.info
Re: Select by kind of object
« Reply #4 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'.

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Select by kind of object
« Reply #5 on: October 09, 2011, 00:36:34 am »
Hello,

OK, thanks Andy  ;)

++
David

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Select by kind of object
« Reply #6 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

Offline 10bulls

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 2163
  • Coding Jedi
    • View Profile
    • www.cambam.info
Re: Select by kind of object
« Reply #7 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!  ;)

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Select by kind of object
« Reply #8 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

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Select by kind of object
« Reply #9 on: July 12, 2014, 20:34:32 pm »
Hello,

Here is the plugin version for this tool.

++
David
« Last Edit: June 11, 2015, 16:53:42 pm by dh42 »

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Select by kind of object
« Reply #10 on: July 12, 2014, 20:59:27 pm »
Thanks, David.  I'll try it ASAP.

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Select by kind of object
« Reply #11 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
"Pyro for Fun and Profit for More Than Fifty Years"

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Select by kind of object
« Reply #12 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
« Last Edit: June 11, 2015, 17:58:48 pm by dh42 »

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8969
    • View Profile
Re: Select by kind of object
« Reply #13 on: July 13, 2014, 14:12:38 pm »
Thank you sir!  New tricks to learn!

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Online dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7408
    • View Profile
    • Cambam V1.0 French Doc
Re: Select by kind of object
« Reply #14 on: July 14, 2014, 18:26:18 pm »
Hello,

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

++
David
« Last Edit: June 11, 2015, 16:53:10 pm by dh42 »