• 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

Create component with different axes

Scheduled Pinned Locked Moved Developers' Forum
13 Posts 3 Posters 489 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
    TIG Moderator
    last edited by 3 Jun 2014, 22:31

    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 3 Jun 2014, 22:56

      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 3 Jun 2014, 23:49

        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
        • T Offline
          TIG Moderator
          last edited by 4 Jun 2014, 09:41

          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 4 Jun 2014, 14:49

            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 4 Jun 2014, 15:11

              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 4 Jun 2014, 15:40

                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
                • T Offline
                  TIG Moderator
                  last edited by 4 Jun 2014, 16:59

                  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 4 Jun 2014, 17:03

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

                    Thanks for the help.

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      JQL
                      last edited by 4 Jun 2014, 18:43

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

                      Advertisement