sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Change axes from ruby

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 4 Posters 2.0k Views 4 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.
    • N Offline
      NewOne
      last edited by

      Hy ! I want to change a component's axes using a ruby script instead of using the right-click menu "Change Axes" command.
      In particular, what I want is to put the axe's origin in center of the component's boundingbox and rotate the coordonates around Z axis.

      Is there a posibility to use ruby for this?
      Thanks for any help!

      1 Reply Last reply Reply Quote 0
      • Didier BurD Offline
        Didier Bur
        last edited by

        Hi,

        @unknownuser said:

        Is there a posibility to use ruby for this?

        No 😞

        DB

        1 Reply Last reply Reply Quote 0
        • N Offline
          NewOne
          last edited by

          @didier bur said:

          Hi,

          @unknownuser said:

          Is there a posibility to use ruby for this?

          No 😞

          Your answer just cnocked me down 😒
          So the so-easy-to-do right-click command doesn't have any alternative to be executed without user intervention?
          You can see here an example of what I want to do here: http://bayimg.com/aaLjcAabj

          1 Reply Last reply Reply Quote 0
          • B Offline
            BillW
            last edited by

            The way I got around the problem in one of my tools was to call the axes tool as shown below

            Sketchup.send_action("selectAxisTool:") if @rotate
            status = model.place_component modcomp, false

            Regards

            Bill Wood

            1 Reply Last reply Reply Quote 0
            • C Offline
              CPhillips
              last edited by

              Here is a function to reset the components axis to the bounding box center.

                   
                  def resetAxis(ent)
                      cd=ent.definition
                      realBounds= Geom;;BoundingBox.new
                      cd.entities.each{|de| realBounds.add(de.bounds)} #Calculate the real bounding box of the entities in the component.
                      center=Geom;;Point3d.new(0,0,0)	#desired center. 
                      if(realBounds.center!=center)	#if not already centered
                              #transform all the entities to be around the new center
                          cd.entities.transform_entities(Geom;;Transformation.new( center-realBounds.center), cd.entities.to_a)
                              #move each instance of this component to account for the entities moving inside the component.
                          cd.instances.each{|ci|
                              newCenter=realBounds.center.transform(ci.transformation)
                              ci.transform!(newCenter-ci.transformation.origin)
                          }
                      end
                           
                  end
              
              
              1 Reply Last reply Reply Quote 0
              • N Offline
                NewOne
                last edited by

                @billw said:

                The way I got around the problem in one of my tools was to call the axes tool as shown below

                Sketchup.send_action("selectAxisTool:") if @rotate
                status = model.place_component modcomp, false

                Regards

                Bill Wood

                Would you, please explain me a little bit more? I'm on my first steps in programming.
                Thank you!

                1 Reply Last reply Reply Quote 0
                • N Offline
                  NewOne
                  last edited by

                  @cphillips said:

                  Here is a function to reset the components axis to the bounding box center.

                  Thanks CPhillips ! the code works great!
                  So, if I understand correctly, you can't move axi's origin in SU, instead the boundingbox can be manipulated around its origin, right?

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    CPhillips
                    last edited by

                    As far as I know the only way to "move an axis" in Sketchup is to move all the entities in the component so they are centered around the desired axis. That is what the function does.

                    1 Reply Last reply Reply Quote 0
                    • N Offline
                      NewOne
                      last edited by

                      @cphillips said:

                      As far as I know the only way to "move an axis" in Sketchup is to move all the entities in the component so they are centered around the desired axis. That is what the function does.

                      I've seen that. So, rotating the axis to obtain a different boundingbox see here: http://bayimg.com/BaLOIaABJ can be done in the same way? Using a transformation that rotates all entities in the component around the origin, then rotates the component back in its initial position?

                      P.S. what BillW wanted to say with

                      Sketchup.send_action("selectAxisTool;") if @rotate
                      status = model.place_component modcomp, false
                      

                      ? πŸ˜’
                      Easy things for you people as pure chinese for me, a newbie 😳

                      1 Reply Last reply Reply Quote 0
                      • B Offline
                        BillW
                        last edited by

                        Hi NewOne

                        It looks like I misunderstood what you were after.

                        I thought you wanted to change the Sketchup Axes before placing a component ie the orientation of a placed component is determined by the current axes orientation. There is no method for changing the axes as far as I am aware.

                        This statement invokes the Axes tool which allows the user to set the axes orientation prior to next call

                        Sketchup.send_action("selectAxisTool:")

                        The place_component method places a component "modcomp" in the Model using the component placement tool.

                        status = Sketchup.active_model.place_component modcomp, false

                        Apologies for the confusion.

                        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