Select all in layer
-
Hi everyone,
I was wondering if it was possible to select all objects in a given layer in code, without having to pre-select an object in the same layer?
I know it's possible through various plugins to add to the selection all the objects that are in the same layer as the selected one, but I would like to do it without having to make this pre-selection.
Thanks for your help!
-
All you need is a reference to the required layer - that's all you get from the preselected object with
layer=object.layerin any case.
So if you know its name (e.g. "MyLayer") then you can usexlayer=Sketchup.active_model.layers["MyLayer"].
Now you can select all active entities that share that layer with
Sketchup.active_model.selection.clear Sketchup.active_model.active_entities.each{|e|Sketchup.active_model.selection.add(e) if e.layer==xlayer}
or alternatively do it by layer name directly [comparing strings is probably slower]
Sketchup.active_model.selection.clear Sketchup.active_model.active_entities.each{|e|Sketchup.active_model.selection.add(e) if e.layer.name=="MyLayer"}
etc etc... -
Thanks a lot that was helpful!
-
@tig said:
comparing strings is probably slower
It is. Much slower! At all times avoid string comparisons if possible.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement