• Login
sketchucation logo sketchucation
  • Login
Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

How to orient component in space using ruby?

Scheduled Pinned Locked Moved Developers' Forum
11 Posts 3 Posters 476 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 31 Mar 2009, 01:07

    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
    • C Offline
      Chris Fullmer
      last edited by 31 Mar 2009, 01:17

      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 31 Mar 2009, 01:36

        @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
        • P Offline
          pilou
          last edited by 31 Mar 2009, 01:40

          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
          • C Offline
            Chris Fullmer
            last edited by 31 Mar 2009, 01:43

            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
            • C Offline
              Chris Fullmer
              last edited by 31 Mar 2009, 01:44

              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 31 Mar 2009, 01:50

                @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
                • C Offline
                  Chris Fullmer
                  last edited by 31 Mar 2009, 01:51

                  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
                  • C Offline
                    Chris Fullmer
                    last edited by 31 Mar 2009, 01:53

                    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 31 Mar 2009, 02:04

                      @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
                      • C Offline
                        Chris Fullmer
                        last edited by 31 Mar 2009, 03:17

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

                        Advertisement