We are having some problems getting the transformation correct when adding a child group to a parent group when that parent group is active. If the parent group isn't active then it works fine.
Has anyone else had this problem. Details and technique to duplicate are below.
Our workflow is that the user adds child groups to a parent group while the parent is open. The script below shows my problem, you have to enter it line by line in the ruby console because there are steps (Steps A and B) where you have to click around to change the current active group. I have tried calling make unique on both groups to no avail and can’t even do a work around of setting the child’s transformation to the parent’s inverse transformation because when I try to get the parent’s transformation it comes back as identity. I would really appreciate any help in finding a work around for this, I don’t want to have to go to components instead of groups unless I really have to.
Script is below:
# clear everything out
Sketchup.active_model.entities.clear!
# add the parent group
group1 = Sketchup.active_model.entities.add_group
# didn’t work
# group1.make_unique
# set parent’s transformation
group1.transformation = Geom;;Transformation.translation(Geom;;Point3d.new(10.m, 0, 0))
# add some points to the parent group
group1.entities.add_cpoint(Geom;;Point3d.new(0.m, 0.m, 0.m))
group1.entities.add_cpoint(Geom;;Point3d.new(5.m, 5.m, 3.m))
# the parent group’s transformation shows the correct translation
puts group1.transformation.to_a.join(', ')
# step A) double click group1 to open it
# parent’s transformation now shows as identity?
puts group1.transformation.to_a.join(', ')
# add the child group
group2 = group1.entities.add_group
# didn’t work
# group2.make_unique
# we want the child group’s axes to be the same as the parent group’s axes, unfortunately this seems to put it at the absolute origin
group2.transformation = Geom;;Transformation.new
# add some points to the child group
group2.entities.add_cpoint(Geom;;Point3d.new(0.m, 0.m, 1.m))
group2.entities.add_cpoint(Geom;;Point3d.new(5.m, 5.m, 4.m))
# step B) exit out of all groups to top level model
# the parent group’s transformation is correct
puts group1.transformation.to_a.join(', ')
# the child group has a negative translation to bring it back to the origin? Why?
puts group2.transformation.to_a.join(', ')
# this will put group2 where it is supposed to be
group2.transformation = Geom;;Transformation.new
# group transformations are now correct
puts group1.transformation.to_a.join(', ')
puts group2.transformation.to_a.join(', ')