[Code] Change Axes of a Group

[Code] Change Axes of a Group

Postby kwalkerman » Tue Aug 16, 2011 9:00 pm

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
0
Last edited by kwalkerman on Tue Aug 16, 2011 11:31 pm, edited 1 time in total.

kwalkerman 
 

Re: Change Axes of a Group

Postby TIG » Tue Aug 16, 2011 9:02 pm

Make a transformation that resets the axes and transform! to group ?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: Change Axes of a Group

Postby kwalkerman » Tue Aug 16, 2011 9:44 pm

Not quite sure how to do this. Can you give me any more details?

Thanks.
0

kwalkerman 
 

Re: Change Axes of a Group

Postby kwalkerman » Tue Aug 16, 2011 10:29 pm

OK, here is the solution for anyone who needs it in the future:

Code: Select all
# 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

0

kwalkerman 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 11 guests

Visit our sponsors: