for i in 0...tsn
s_grp2 = s_grp.copy
s_pt = [0, 0, (i + 1) * delta]
tr = Geom::Transformation.new s_pt
s_grp2.transform! tr
end
Codes make some groups from first one. Now I wish to have all of these groups as one group. How can I do it? This is general question to merge some groups together. I can also explode all of groups also I can move then to a especial layer but I don’t know how can I add all of entities in one group? Thank you in advance for your help.
# Will merge the groups
# Paramater (Array<Sketchup::Group>)
# if nothing is specified all group will
# be merged in active context
# Returns: <Sketchup::Entities>
def merge_groups( groups = Sketchup.active_model.active_entities.grep(Sketchup::Group) )
model = Sketchup.active_model
ents = model.active_entities
merged_group = ents.add_group( groups.each{|g| g.entities} )
merged_group.entities.each{ |e| e.explode if e.respond_to?(:explode) }
end
#usage example
merge_groups
#or
merge_groups([s_grp, s_grp2])
Dear Dezmo,
You codes work right and at the end we will have one group just one problem. explode make codes too slow even more than 10 second for a normal usage. Can you suggest another faster solution?
Not really.
However just an idea, you can try:
If you are wrapping to undo stack with disabled UI - which you must to do anyway on a “full” code where you make modell geometry changes - maybe helps a little… Model#start_operation-instance_method (The second parameter must be true )
# Paramater (Array<Sketchup::Group>)
# if nothing is specified all group will
# be merged in active context
# Returns: <Sketchup::Entities>
def merge_groups( groups = Sketchup.active_model.active_entities.grep(Sketchup::Group) )
model = Sketchup.active_model
ents = model.active_entities
model.start_operation('Merge Groups', true)
merged_group = ents.add_group( groups.each{|g| g.entities} )
merged_group.entities.each{ |e| e.explode if e.respond_to?(:explode) }
model.commit_operation
end
#usage example
merge_groups
#or
merge_groups([s_grp, s_grp2])
I did it before and takes more than 10 second. Also used following code but same result.
groups = []
groups << s_grp
for i in 0...tsn
s_grp2 = s_grp.copy
s_pt = [0, 0, (i + 1) * delta]
tr = Geom::Transformation.new s_pt
s_grp2.transform! tr
groups << s_grp2
end
ents = Sketchup.active_model.active_entities
merged_group = ents.add_group( groups.each{|g| g.entities} )
# merged_group.entities.each{ |e| e.explode if e.respond_to?(:explode) }
merged_group.entities.grep(Sketchup::Group) { |g| g.explode }
Delay for an average usage is too much even user think SU is terminated. Maybe from beginning I should make all in one group. Let me try for it. Always your solution teach me something new. Thank you so much for it.
SUPER! Thank you.
But…I’ve some faces with “sub” faces (like a window in a wall).
I merged the groups but I can’t obtain this result (face “wall” and face “windows”).