Adding groups to an existing group
-
What am I missing. When the following code is executed it creates groups from each face but grpA, which I thought I was adding groups to, is empty?
mod = Sketchup.active_model ent = mod.active_entities sel = mod.selection grpA = ent.add_group; grpA.name="container" for f in ent.grep(Sketchup;;Face) grpB=grpA.entities.add_group f grpB.name="#{f.bounds.width} X #{f.bounds.height}" end puts "grpA contains #{grpA.entities.length} entities"


-
The '
entities.add_group(xxx)' ONLY works if the 'xxx' is in the 'active_entities' AND 'entities' IS the 'active_entities'...
So you need to add those faces [that are also in the 'active_entities'] directly into a group as you add it into the 'active_entities', then add that new group directly into a second group that you then add into the 'active_entities' etc...
Otherwise get a references to the group and use something like:
tr=Geom::Transformation.new()another_things_entities.add_instance(group.entities.parent, tr)
then erase the original group
group.erase!
leaving a 'clone' of it inside this other group...
???You are lucky not to get a Bugsplat when 'crossing entities'

-
Thanks TIG. I sure there is a logical explination as to why you have to add an instance to the container group and delete the original but seems strange to me. Anyway, using your suggestions, this is the modified code and it works just like I wanted.
mod = Sketchup.active_model ent = mod.active_entities sel = mod.selection grpA = ent.add_group; grpA.name="container" tr=Geom;;Transformation.new() for f in ent.grep(Sketchup;;Face) grpB=ent.add_group f; tr=grpB.transformation grpB.name="#{f.bounds.width} X #{f.bounds.height}" grpC=grpA.entities.add_instance(grpB.entities.parent,tr) grpC.name=grpB.name grpB.erase! end puts "grpA contains #{grpA.entities.length} entities"
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