sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    [Code] Change Axes of a Group

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 1.1k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      kwalkerman
      last edited by kwalkerman

      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

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Make a transformation that resets the axes and transform! to group ?

        TIG

        1 Reply Last reply Reply Quote 0
        • K Offline
          kwalkerman
          last edited by

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

          Thanks.

          1 Reply Last reply Reply Quote 0
          • K Offline
            kwalkerman
            last edited by

            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 
            
            
            
            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement