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

    Active_path.last original transformation

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 3 Posters 1.1k 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.
    • T Offline
      tomasz
      last edited by

      When a component is being edited, then the model.active_path.size>0.

      Unfortunately the component transformation is being modified in comparison with exactly same component transformation read from a selection.

      I cannot find a way to get the very original transformation of the active_path.last...
      When iterating through the model tree I get same active_path.last transformation. I am afraid there is none.

      I checked mod.axes.transformation, but it gives me just the correct origin of active_path.last, but other parts of the transformation are orthonormal.

      Any ideas?


      Animated GIF - click me to show the action

      Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

      1 Reply Last reply Reply Quote 0
      • jiminy-billy-bobJ Offline
        jiminy-billy-bob
        last edited by

        I don't think there's a way to get it easily.

        You have to iterate through the model, searching for each child at each level, and multiply each transformation.
        At least, that's how I do it.

        25% off Skatter for SketchUcation Premium Members

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

          You could perhaps use a 'pick helper' to get the 'current transformation' taking into account any 'containers'...
          ` view = Sketchup.active_model.active_view
          ph = view.pick_helper
          x, y, z = view.screen_coords(some_point).to_a
          ph.do_pick(x, y)
          tr = ph.transformation_at(0) if ph.picked_edge

          or whatever test needed etc`

          TIG

          1 Reply Last reply Reply Quote 0
          • T Offline
            tomasz
            last edited by

            @jiminy-billy-bob said:

            You have to iterate through the model, searching for each child at each level, and multiply each transformation.
            At least, that's how I do it.

            This doesn't work. I gives me exactly the "wrong" transformation.

            @tig said:

            You could perhaps use a 'pick helper' to get the 'current transformation' taking into account any 'containers'...

            Thanks for the advice. Unfortunately I am not in a tool context and I am also afraid that is would still give me "wrong" transformation.

            My scenario is following:

            • I export a component into an "external file"
            • replace it with a "proxy" - say a wireframe cube
            • when a rendering starts I replace the "proxy" with original model....

            The problem is that the original model has all coordinates of the initial(non-edited)definition, but the transformation and the definition of SU component changes while it is in edit mode! This causes wrong position/scaling of all instances of a component being edited.

            The ring has (proper) coordinates for non-edit scenario, but when proxy is being edited, the transformation is wrong

            Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

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

              If you have a transformation within a context can't you get the transformation.inverse and apply that to the transformation of the other object to 'correct' it ??

              TIG

              1 Reply Last reply Reply Quote 0
              • T Offline
                tomasz
                last edited by

                I could use the SU2016 Axes.origin and at least bring the component to a correct location when there is no scaling used in the component instance. I cannot call it a solution though.


                Test model

                Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                1 Reply Last reply Reply Quote 0
                • T Offline
                  tomasz
                  last edited by

                  No. It won't work.

                  Sketchup.active_model.entities[0].transformation.to_a
                  =>[1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 10.0, 10.0, 10.0, 1.0]

                  When in edit:
                  Sketchup.active_model.entities[0].transformation.inverse.to_a
                  [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -0.0, -0.0, -0.0, 1.0]

                  Sketchup.active_model.active_path[0].transformation.inverse.to_a
                  [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -0.0, -0.0, -0.0, 1.0]

                  Those inverted transformations won't bring the origin to [10.0,10.0,10.0] either give correct rotation/scaling. SU simply resets the transformation to identity:
                  [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
                  and re-do the definition in global coordinates...

                  Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    tomasz
                    last edited by

                    I don't understand why:

                    mod.entities[0].transformation.to_a

                    gives different results when I am inside the entities[0] then when I am outside it.

                    SU engineers have had a reason to do this, but this makes developers life worse.
                    What is the point in modifying a thing? EDIT: To allow drawing in global coordinates, so in this regards, it is beneficial. 😄

                    When the transformation is modified, then it is obvious that the definition has to be modified also, to keep the model consistent!

                    mod.entities[0].definition.entities[6].start.position.to_a
                    =>[10.0, 0.0, 0.0]
                    mod.entities[0].definition.entities[6].start.position.to_a
                    =>[20.0, 10.0, 10.0]
                    

                    Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                    1 Reply Last reply Reply Quote 0
                    • jiminy-billy-bobJ Offline
                      jiminy-billy-bob
                      last edited by

                      Good to know, thanks!

                      25% off Skatter for SketchUcation Premium Members

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        tomasz
                        last edited by

                        It is good to do something else. When reading about model observers I have found the answer:

                        Sketchup.active_model.edit_transform

                        There is a mistake in the documentation though:

                        @unknownuser said:

                        ModelObserver.onActivePathChangedSketchUp 7.0+
                        ...
                        When in "edit mode" (aka a Component is being edited), the Ruby API returns object transformations and locations in context of the "local" component axes instead of the global axes.

                        It is other way round. In "edit mode" we are in global context. If one wants to have the local then use edit_transformation. When you want original transformations for the rest of instances then you have to go through the whole "tree" and use edit_transformation for the last group/component.

                        Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                        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