grouping and ungrouping

grouping and ungrouping

Postby Remmel » Tue Apr 24, 2018 12:08 pm

Hi There, i wonder..... when you make an group with ruby in sketchup.... you can explode
that group.... but is it possible to make the same group egain...???
can anyone help me...?

see the following simple exaample

#create a group and add a line into the group
model = Sketchup.active_model # Open model
entities = model.entities # All entities in model
selection = model.selection # Current selection
group = entities.add_group #make emplty group

#create a line in group
line = group.entities.add_line [0,0,0], [100,50,20]

#explode group


Re: grouping and ungrouping

Postby juju » Tue Apr 24, 2018 12:49 pm

That would probably require some method of recording what was previously selected. I'm not a developer, so I can't help you on the coding, but I recall a plugin / extension called "selection memory" (by Thom-Thom) that does more-or-less what may be required, in part at least. Maybe also take a look at "selection manager" for reference.
Save the Earth, it's the only planet with chocolate.
User avatar
Premium Member
Premium Member

Re: grouping and ungrouping

Postby TIG » Tue Apr 24, 2018 12:53 pm

Use model.active_entities, working in model.entities IF it's not the current context will BugSplat.

You can get references to the objects which result from the explode operation [any previous reference to that line etc will get lost as it explodes]
exps = group.explode
Gives you an array - in your case it'll probably be an array containing one line...

You could then remake a group in the active_entities with group2 = entities.add_group(exps) or perhaps exps.grep(Sketchup::Edge)[0]

If you want to replicate the group then after the first group is made you simply add a copy of it, then explode the original, so that the edge is now in the copied group, and it is replicated back in the active_entities...

group2 = entities.add_instance(group.definition, group.transformation)

Now explode the original 'group' back to the edge in the active_entities...
The second copy 'group2' remains, it contains the replicated edge...
User avatar
Global Moderator

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Ad Machine 


Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 6 guests