Add an object to the selection based on a attrib.
-
Hello all,
In the attribute dictionary of all my objects in the model i have added a unique identifier for each object (since i have noticed that the ID's created by SU itself are not solid over several sessions)
Now if i want to add an entity-group-whatever with a specific unique id to the selection (so it shows selectedin SU) do I need to loop through all the available objects in SU?
Or is it possble to directly get that object and add it to the selection? (like:
object= select where ent.get_attribute "attrdict", "attrname" = xxx
selection_add objectThx again
-
@pout said:
Hello all,
In the attribute dictionary of all my objects in the model i have added a unique identifier for each object (since i have noticed that the ID's created by SU itself are not solid over several sessions)
Correct.
@unknownuser said:
Now if i want to add an entity-group-whatever with a specific unique id to the selection (so it shows selectedin SU) do I need to loop through all the available objects in SU?
Yes. If there are a small number of entities, you could just loop over them. But it would be better to loop over them once, and hash the entities by your ID so you can just look them up.
@unknownuser said:
Or is it possble to directly get that object and add it to the selection? (like:
object= select where ent.get_attribute "attrdict", "attrname" = xxx
selection_add objectThis line is the same as looping over everything in the model:
Sketchup.active_model.selection.add( Sketchup.active_model.entities.select{|e| e.get_attribute("Dict", "key") == "value"} )
@unknownuser said:
Thx again
-
Excellent,
Thank you very much!Also, could you point me out a good book for ruby for SU?
i have this one book here now 'Learning Ruby' from O'reilly but it doesn't seem to contain the info i need.Regards,
-
This is no book for Ruby in SketchUp, per se. There are Ruby books and there are SketchUp books. The book I use as a reference for Ruby is called the Pickaxe book. An older copy is available online here: http://phrogz.net/ProgrammingRuby/frameset.html
Todd
Advertisement