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

    Create component with different axes

    Scheduled Pinned Locked Moved Developers' Forum
    13 Posts 3 Posters 376 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      Place the group/instance in code then use:
      group.... OR instance.transform!(Geom::Transformation.scaling(instance.transformation.origin, -1, 1, 1))
      To flip along the X.
      Use ...1, -1, 1 to flip along Y...
      Just the same as Scale -1 along an axis or the Flip methods...

      TIG

      1 Reply Last reply Reply Quote 0
      • G Offline
        Garry K
        last edited by

        JQL
        Flip along axis is great however, if the component has an interaction like rotate to simulate a door opening then you will find that the component reverts back to it's original state (you loose the flip).

        What I need to do is change axes.

        1 Reply Last reply Reply Quote 0
        • G Offline
          Garry K
          last edited by

          Tig

          I faintly remember you writing about inverse when writing code to move axes. I've searched for this but can't find it.

          What I want to do is move the axes after the component and it's nested elements have been created.

          Any thoughts on this?

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

            Let ' point' be the new insertion point of the component.
            Let vector=ORIGIN.point.vector_to(point)
            Let tr=Geom::Transformation.translation(vector)
            Then use...
            component.entities.transform_entities(tr)
            All of the component's innards jump to suit, so the instance is now in the wrong place relative to its container's contents...
            To fix any instances so the contents are placed back as they were, inside their individual container...
            component.instances.each{|instance| instance.transform!(tr.inverse) }

            TIG

            1 Reply Last reply Reply Quote 0
            • G Offline
              Garry K
              last edited by

              Thanks Tig,

              I was able to modify your algorithm to work. If I ran it the way it was it put the new origin off to the left of the door by exactly the width of the door. So I reversed the transforms and it worked.

              I modified the axescomp.rb and it works as well.

              Here is the code I used.

              def do_set_origin(component, new_origin)

              Let 'point' be the new insertion point of the component.

              Let vector=ORIGIN.point.vector_to(point)

              Let tr=Geom::Transformation.translation(vector)

              vector = component.transformation.origin.vector_to(new_origin)
              tr = Geom::Transformation.translation(vector)

              component.definition.entities.transform_entities(tr.inverse, component.definition.entities.to_a)

              All of the component's innards jump to suit, so the instance is now in the wrong place relative to its container's contents...

              To fix any instances so the contents are placed back as they were, inside their individual container...

              component.definition.instances.each{ |inst| inst.transform!(tr) }
              end

              I am having this issue with the door. The selection for the door is not quite right. If I save the skp and reload it - the problem goes away. If I double click as if to perform an edit then the problem goes away.

              What is happening and how can it be fixed?


              door_axes.JPG

              1 Reply Last reply Reply Quote 0
              • G Offline
                Garry K
                last edited by

                This is wierd - if I rem out these 2 lines then the door is ok.
                But I can't do that because the plugin needs a proper undo.

                model.start_operation
                model.commit_operation

                1 Reply Last reply Reply Quote 0
                • G Offline
                  Garry K
                  last edited by

                  I figured it out.

                  Need to add this line at the bottom of the do_set_origin function

                  component.definition.invalidate_bounds

                  Everything is now working !!!!

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

                    Yes, sorry I was away after quickly posting my untested code snippet. 😒
                    I thought that I did actually edit vector=ORIGIN.point.vector_to(point) to read vector=point.vector_to(ORIGIN) but somehow the update didn't stick 😕
                    I did get the transformation vector 'backwards'... and of course you do need to invalidate the definition's bounds to get the instances bounding-box to sort itself out...
                    Glad that I at least put you on the right path, albeit in the wrong direction 😉
                    At least you have now learnt something useful...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • G Offline
                      Garry K
                      last edited by

                      No problem - I just wanted to post the complete solution for other users.

                      Thanks for the help.

                      1 Reply Last reply Reply Quote 0
                      • JQLJ Offline
                        JQL
                        last edited by

                        @garry k said:

                        JQL
                        Flip along axis is great however, if the component has an interaction like rotate to simulate a door opening then you will find that the component reverts back to it's original state (you loose the flip).

                        What I need to do is change axes.

                        Funny doesn't happen to me. But I don't question your need to change axis.

                        www.casca.pt
                        Visit us on facebook!

                        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