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

    How to orient component in space using ruby?

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 3 Posters 402 Views 3 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 move a simple component from one position to another and orient it in space. I know the position of all corners of a face. See attached image.
      Please help me with this. Moving the component is the easy part. But there is the alignment which is tricky. pt1 is located in origin (axis don't show up in exported image)
      thanks πŸ’š


      Place component from origin.jpg

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        How do you define where you want it to move? Is it meeting up with another face? or is it based on the orientation of other geometry?

        Chris

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

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

          @chris fullmer said:

          How do you define where you want it to move? Is it meeting up with another face? or is it based on the orientation of other geometry?

          Chris

          I know the position in space of each vertex of the face.

          1 Reply Last reply Reply Quote 0
          • pilouP Offline
            pilou
            last edited by

            Didier Bur has yet made a good one πŸ˜‰

            @unknownuser said:

            Align selection in 3D, starting from a clicked XYZ axis system to a target XYZ plane (Autocad-like). PDF doc included.

            Align Tool β˜€

            Frenchy Pilou
            Is beautiful that please without concept!
            My Little site :)

            1 Reply Last reply Reply Quote 0
            • Chris FullmerC Offline
              Chris Fullmer
              last edited by

              Yeah, but this is a function gets used in lots of ways other than just aligning components.

              Here is how you can do it if you know the new 3dpoint in space that you want to move the component axis to, and you need to know the axes for the new location. These can be found depending on what defines where you are moving the component to. But this code is useful:

              t = Geom::Transformation.axes point, xaxis, yaxis, zaxis component.transformation = t

              point is the new 3d location that component axis will be moved to.
              xaxis is the vector that represents the new x direction fo the component
              yaxis is the vector that represents the new y direction fo the component
              zaxis is the vector that represents the new z direction fo the component

              I can diagram it better if that doesn't make sense. I just learned how to use this transformation today, and I like it.

              Chris

              Lately you've been tan, suspicious for the winter.
              All my Plugins I've written

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                You don't need to know the positions of where the component is, but where it is going to move to.

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

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

                  @chris fullmer said:

                  You don't need to know the positions of where the component is, but where it is going to move to.

                  Whow! thanks πŸ˜„ In fact is really simple. And I don't need the position of each vertex, just component's final orientation.
                  How about inferencing, Chris? Did you figured out? I finally understood how inference_lock works.
                  Thanks again, Chris!

                  1 Reply Last reply Reply Quote 0
                  • Chris FullmerC Offline
                    Chris Fullmer
                    last edited by

                    point = [0,0,0]
                    xaxis = [1,0,0]
                    yaxis = [0,1,0]
                    zaxis = [0,0,1]

                    this represents the origin and the original axis. So take a component and move it off the origin, and rotate it all sorts of ways. Then select it and run this code:

                    comp = Sketchup.active_model.selection[0] point = [0,0,0] xaxis = [1,0,0] yaxis = [0,1,0] zaxis = [0,0,1] t = Geom::Transformation.axes point, xaxis, yaxis, zaxis comp.transformation = t

                    That will move any component, with any rotation put on it back to the origin. Now play around with the axis values. Use
                    zaxis = [0,0,-1]

                    and you'll see it will flip your component upside down. So if you can supply yourt own 3d point and your own new coordinate axes, you can move/rotate it all in one shot.

                    Chris

                    Lately you've been tan, suspicious for the winter.
                    All my Plugins I've written

                    1 Reply Last reply Reply Quote 0
                    • Chris FullmerC Offline
                      Chris Fullmer
                      last edited by

                      oh good, I hope you get it. post again if its not working. And no, I haven't been able to get to the inference yet. Its tricky. And transformations are what keep me awake at night - literally! I need a good book on 3d transformations...

                      Chris

                      Lately you've been tan, suspicious for the winter.
                      All my Plugins I've written

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

                        @chris fullmer said:

                        oh good, I hope you get it. post again if its not working. And no, I haven't been able to get to the inference yet. Its tricky. And transformations are what keep me awake at night - literally! I need a good book on 3d transformations...

                        Chris

                        Well, Chris you suddenly became my best friend ! I'll share my toys with you πŸ˜„
                        When you will fully understand transformations, maybe you will share with us, because I still look at them something like this πŸ˜• 😲 ❓

                        1 Reply Last reply Reply Quote 0
                        • Chris FullmerC Offline
                          Chris Fullmer
                          last edited by

                          Also, in case you know nothing about axes, like me, Fredo showed me that if you multiply 2 axes together, you get a perpendicular axis. This is helpful if you can find 2 axes, say the x and y, you can just multiply them together to get the z axis. Then you have all 3 axes needed for the transformation. It would look like this:

                          xaxis = Geom::Vector3d.new(10,-23,110) yaxis = Geom::Vector3d.new(23,52,9) zaxis = xaxis * yaxis

                          Gives the result of:

                          (-5927.0, 2440.0, 1049.0)

                          for the zaxis.

                          Chris

                          Lately you've been tan, suspicious for the winter.
                          All my Plugins I've written

                          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