[Code] Change Axes of a Group
-
Hi,
I have a script that automatically creates groups out of existing elements. The only problem is that sometimes the axes don't match the global axes, and this is causing problems for me down the road. Is there any way to specify or change the axes of a group using ruby? I'd like to do it once when the group is created instead of having to deal with it forever down the road.
Thanks,
--
Karen -
Make a transformation that resets the axes and transform! to group ?
-
Not quite sure how to do this. Can you give me any more details?
Thanks.
-
OK, here is the solution for anyone who needs it in the future:
# accepts either one or two arguments. The first is always the group or component where the axes needs to be corrected # the second can be a parent group or component (something that has a transformation). If nothing is passed in, the global # model x,y, and z axes will be used. The parent attribute should be used any time there is a nested component. def change_axes_to_parent(*args) if args.length == 1 g = args[0] p_t = Geom;;Transformation.new else g = args[0] p_t = args[1].transformation end t = g.transformation #p_t = parent.transformation if t.xaxis != p_t.xaxis || t.yaxis != p_t.yaxis || t.zaxis != p_t.zaxis o = t.origin # different axes, require that all components inside be rotated tran = Geom;;Transformation.axes o, t.xaxis,t.yaxis,t.zaxis t_o = Geom;;Transformation.new o if g.is_a? Sketchup;;Group ents = g.entities elsif g.is_a? Sketchup;;ComponentInstance ents = g.definition.entities end ents.transform_entities tran, ents.to_a ents.transform_entities t_o.inverse, ents.to_a g.transform! tran.inverse g.transform! o end end
Advertisement