sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Get Current Axes Position/Orientation

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 4 Posters 2.5k 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.
    • D Offline
      debracey
      last edited by

      Hello everyone,

      is it possible to get the model's axes/orientation through the Ruby API? I used the axes button (under the construction toolbar) and moved the axes so that:

      1. They are in the dead center of the model (vs the corner)
      2. Rotated 90 degrees clockwise

      All I need to do is get this info into Ruby so I can push it out into some XML that I'm writing, is there any way to do this?

      Thanks

      Dan

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

        Although you can temporarily reset axes manually - useful for manual-drafting - there is no direct access to the axes in the API.
        The model's axes are fixed and everything is inserted around them.
        In code you can't move the real model's axes but you can move objects...

        To put this another way... what you want to do is relocate all of the model.entities so they are located centered on the origin...
        You know the Sketchup.active_model.bounds.center
        You know the ORIGIN
        You can get the vector between them...
        vector=Sketchup.active_model.bounds.center.vector_to(ORIGIN)
        From that you can make a translation transformation...
        tr=Geom::Transformation.translation(vector)
        You can now apply that to the model's entities...
        Sketchup.active_model.entities.transform_entities(tr, Sketchup.active_model.entities.to_a)
        All of the model should move to be centered... you might want to think about non-visible and/or locked objects - as without testing it I unsure if they'd move too...
        Once you have everything relocated use a rotation transformation
        tr=Geom::Transformation.rotation(ORIGIN, Z_AXIS, -90.degrees)
        and
        Sketchup.active_model.entities.transform_entities(tr, Sketchup.active_model.entities.to_a)
        to do a cw rotation of the model [-ve=cw/+ve=ccw] - BUT if you mean 'relatively' rotate the axes 90 cw then you reverse the tr so its 90.degrees rather than -90...
        If you do all of this after a Sketchup.active_model.start_operation("XML"), do the changes and the export and then finally call Sketchup.active_model.abort_operation ALL of the changes are then undone, BUT the exported XML code be unaffected as it's outside of the SKP, and it will reflect these temporary relationships of axes/geometry...

        TIG

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          I use this hack:

          <span class="syntaxdefault"><br /></span><span class="syntaxcomment">#&nbsp;SU7&nbsp;only&nbsp;-&nbsp;incorrect&nbsp;in&nbsp;older&nbsp;versions.<br />#&nbsp;A&nbsp;hack&nbsp;to&nbsp;get&nbsp;the&nbsp;current&nbsp;model&nbsp;axis.<br />#<br />#&nbsp;@return&nbsp;[Boolean]<br />#&nbsp;@since&nbsp;1.0.0<br /></span><span class="syntaxdefault">def&nbsp;get_model_axis<br />&nbsp;&nbsp;</span><span class="syntaxkeyword">@</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_operation</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Get&nbsp;Model&nbsp;Axis&nbsp;(Hack)'</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;</span><span class="syntaxdefault">entities&nbsp;</span><span class="syntaxkeyword">=&nbsp;@</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities<br />&nbsp;&nbsp;t&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_group</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_group</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">transformation<br />&nbsp;&nbsp;</span><span class="syntaxkeyword">@</span><span class="syntaxdefault">xaxis&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">t</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">xaxis<br />&nbsp;&nbsp;</span><span class="syntaxkeyword">@</span><span class="syntaxdefault">yaxis&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">t</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">yaxis<br />&nbsp;&nbsp;</span><span class="syntaxkeyword">@</span><span class="syntaxdefault">zaxis&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">t</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">zaxis<br />ensure<br />&nbsp;&nbsp;</span><span class="syntaxkeyword">@</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">abort_operation<br />end<br /></span>
          

          NOTE: Since this creates temp geometry and temp operation it cannot be used at any time. You must be careful. It will interrupt any started operations - so use it right before your own .start_operations.

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

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

            To recap.
            The Model's axes are fixed; however, the axes inside a group/component edit context [active_entities versus entities] can differ.
            So thomthom's 'hack' will return the axes of that context.
            If you create a temporary empty group and get its transformation axes as tt showed I don't think you need to abort the operation because an empty group will not survive the rest of the code's processing anyway...
            Alternatively you could make a reference to the temporary group [tgp=...] and then tgp.erase! it immediately after you have got tgp.transformation axes into the three @variables.
            A converse issue when making a new group that you want to keep - you need to add entities t it quickly or else you'll find in no longer exists

            TIG

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @tig said:

              To recap.
              The Model's axes are fixed;

              So the model's origin will always equal ORIGIN (unless some dumb coder changes this constant.)
              So the model's transformation will always equal:
              Geom::Transformation.new(ORIGIN)
              and it's axes will always be the unit vectors:
              xvec = Geom::Transformation.new(ORIGIN).xaxis() yvec = Geom::Transformation.new(ORIGIN).yaxis() zvec = Geom::Transformation.new(ORIGIN).zaxis()

              Note: Changing the NorthAngle does not affect the x or y axis vector.

              @tig said:

              however, the axes inside a group/component edit context [active_entities versus entities] can differ.
              So thomthom's 'hack' will return the axes of that context.

              But.. an edit context of a group or component, is not actually a UCS (user Co-ordinate System.) When you move the axis indicators with the AxisTool, you are setting a temporary UCS. The API does NOT expose this "Axes Object" either for setting it, saving it, or getting it.

              This IS one of the Feature Requests that I remember filing (both for UI integration and API integration.)
              What I had proposed (from memory,) was a Geom::Axes (or Geom::AxesSet,) object, that I think would be an Array of 3 Geom::Vector3d objects (x, y and z.) For the UI, I requested that the user be able to save and restore named AxesSets (just as is possible in AutoCAD.)

              Unfortunately.. we cannot even "hack" the current AxisTool on Windows, because the tool does not use the VCB ("Measurements") box.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                @tig said:

                The Model's axes are fixed;

                You can change the axis of the root context... I've always called that the model axis..

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  Just a note, that in playing around (I did not realize this before,) that custom "User" Axes can be saved within a ScenePage. (I and others, have been after the Developemnt Team to allow saving a UCS like we can in AutoCAD.)

                  Although this not "exactly" what we have been asking for... it can work for now.

                  1) Add a new ScenePage, .. name it what ever you want.
                  2) Use the AxisTool to set a custom axes.
                  3) Click the update button on the Scenes Inspector toolbar (or right-click the SceneTab > choose "Update", if you have Scenetabs on.)

                  You can now switch back to this page anytime you wish to work with in this custom axes.

                  If you want the scenepage to be "Axis-Aligned",.. then with it the active page,...
                  1) Right click one of the axis, choose "Align View"
                  2) Choose on the menu: "Camera" > "Parallel Projection"
                  3) Update the scenepage.

                  The custom axes scenepage will now always initially display in "aligned mode"... but can temporarily change it to Iso (click the "Iso" button,) or just use the Orbit / Zoom tools to change the camera location. Just do not update the page.
                  Anytime you wish to return the the "axis aligned" camera, just double-click the scenetab (if you have Scenetabs on.) or double-click the scene's title in the list within the Scenes inspector.

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    @thomthom said:

                    @tig said:

                    The Model's axes are fixed;

                    You can change the axis of the root context... I've always called that the model axis..

                    Or sometimes it's referred to as "WorldAxis".

                    How?? I tried it. Any of the Entities add methods still use the old Axes.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      @dan rathbun said:

                      @thomthom said:

                      @tig said:

                      The Model's axes are fixed;

                      You can change the axis of the root context... I've always called that the model axis..

                      Or sometimes it's referred to as "WorldAxis".

                      How?? I tried it. Any of the Entities add methods still use the old Axes.

                      Thomas Thomassen β€” SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        @dan rathbun said:

                        Just a note, that in playing around (I did not realize this before,) that custom "User" Axes can be saved within a ScenePage.

                        Yea, I often set up Scenes that adjust just the axis. All though, with SU8 now automatically adjusting the model axis to match component axis there's less need of it for my use. Works well when you have a building with axis in various directions.

                        Thomas Thomassen β€” SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        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