If I do
- Code: Select all
union_result = group_a.union(group_b)
I can't seem to refer to union_result when I try to run union again for subsequent objects.
Here is the total picture that may provided more insight...
Disclaimer: this seems like a dumb way to do this but, because when I loop through all my target groups, I need something to union the first one with, I am creating a small dummy group like so...
- Code: Select all
mod = Sketchup.active_model
ent = mod.active_entities
# create a dummy object for initiating union
dummy_face = ent.add_face([0,0,0],[1,0,0],[1,1,0],)
dummy_group = ent.add_group(dummy_face)
dummy_group.name = 'DUMMY GROUP'
dummy_face.pushpull(1,true)
Then here is the actual iterating (WARNING - BUG SPLATS!):
- Code: Select all
ent.grep(Sketchup::Group).each_with_index do |item, i|
next if item.name!='MY_TARGET_GROUPS'
if i <= 1 # first run so union with dummy
union_temp = item.union(dummy_group)
union_temp.name = 'TEMP_RESULT'
else # subsequent runs can union with prior union result
union_final = item.union(union_temp)
union_final.name = 'UNION_RESULT'
end
end
I also tried using entities[-1] for the last created entity and that ALSO BUG SPLATS:
- Code: Select all
union_final = item.union(ent[-1])
Perhaps there is something I am misunderstanding about iterating that "clears" the variables created during each loop? Do I need a global or something using the @ designation?
Also, instead of using a dummy object, perhaps I should just skip the first group - but then I would need a handle to be able to refer to it during the next iteration?
Your thoughts would be appreciated.