Working with selection - ungrouped or within a group
-
(Posted this at the SketchUp forum but since its dissapearing I'd thought I'd post it here also)
If I want a script to work with a selection of either ungrouped objects or within a group.
Could something like this work?if selection.typename == "Group" { entities=group.entities }
else { entities=model.active_entities } -
No.
You cannot have a selection of entities in and out a group/component at the same time.Shetchup.active_model.active_entities returns the whole model if you aren't editing a group/component, and returns the collection of entities of the group/component if you are editing a group/component.
Shetchup.active_model.selection is completely different from that.
Hope this helps, -
I'll try to explain what I'm after.
Is it possible to make a script work with either the edges/faces in a selected group or the ungrouped edges/faces if there is no group?
I don't mean at the same time, but to recoginize if the selection is a group or not and be able to work either way.If not, I guess I'll have to make two scripts, one for groups and one without.
-
Yes it is doable.
For instance:
def editing_group?
if Sketchup.active_model.active_entities.parent.class == Sketchup::ComponentDefinition and Sketchup.active_model.active_entities.parent.group?
return true
else return false
endWill return a boolean to tell the script if the user is currently editing a group. BUT using methods of the selection class is independant of that.
Even if the user is editing a group, Sketchup.active_model.entities can be accessed the usual way, and Sketchup.active_model.active_entities will return a collection of entities of the active group/component.If you have to check wether selection is a group or not, use this test:
Sketchup.active_model.active_entities.parent.class == Sketchup::ComponentDefinition
(because group are stored as if they are components !)
and if you have to check wether a particular selected object is part of a group or not, use this test:if editing_group? and Sketchup.active_model.active_entities.include?( object_id ) ...
Hope this helps,
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