Ruby selection

Ruby selection

Postby yalhassanpro » Wed Mar 08, 2017 9:33 am

Hello forum,
I have a model which consists of faces and unconnected lines. How do I select the lines only using Ruby? I have attached an image file.
Thanks
0

yalhassanpro 
 

Re: Ruby selection

Postby TIG » Wed Mar 08, 2017 1:04 pm

First we set up some references.
model = Sketchup.active_model
ss = model.selection


Then depending on how you want to 'start' off your plugin...

edges = model.active_entities.grep(Sketchup::Edge)
An array of all edges in the active context***

OR

edges = ss.grep(Sketchup::Edge)
An array of all edges in the current selection.***

Now resolve the selection:
ss.clear
ss.add(edges)


***The 'rep' finds all edges, including those bordering faces.
So if you want to select just those edges without faces then you can extend the 'grep' code thus
... .grep(Sketchup::Edge).find_all{|e| e.faces.length == 0 }
The array 'edges' then just lists those edges without faces...
1
TIG
User avatar
TIG 
Global Moderator
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: Google Bot, Yahoo Bot and 10 guests

Visit our sponsors: