• Login
sketchucation logo sketchucation
  • Login
โš ๏ธ Libfredo 15.4b | Minor release with bugfixes and improvements Update

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.
  • G Offline
    Garry K
    last edited by 30 May 2014, 19:57

    I have a door maker plugin which makes cabinet doors. I want to create doors with left hand swings and doors with right hand swings.

    It appears that I need to create some doors with the axes on the other side of the door.
    I can't figure out how to do this in code.

    I start out with a group to which I add stiles, rails and a panel all as groups. Each group is then converted to component instances so that these components will work with cutlist plus or cutmasterpro.

    Finally I convert the first group to a component. This main group gets some dictionary attributes assigned to it.

    What does it take to either move the axes to the other side or to create the door in the first place with the axes on the otherside?

    1 Reply Last reply Reply Quote 0
    • G Offline
      Garry K
      last edited by 3 Jun 2014, 18:37

      I have found an old plugin called axiscomp.rb. This plugin changes component axes in code after the fact.

      The code has a lot of cut and paste - So I have simplified it - and I have completed and organized the menu selection. There are now 27 choices which represent 8 corners, 1 center, 6 center of faces and 12 mid points of edges.

      I did not move the code into a module.

      The problem I find with the code (and with the original) is that it only works for unique component. It does not currently work for copies.

      I believe that some modification of this code may work for my door axes.


      axiscomp.rb

      1 Reply Last reply Reply Quote 0
      • J Offline
        JQL
        last edited by 3 Jun 2014, 22:25

        I know nothing about code but this question intrigued me. You know what I do when modeling those right hand and left hand doors that are actually the same component?

        Context Menu > Flip Along > XYZ Axis that way the axis will reverse.

        Isn't flip along available in ruby or api or whatever you brilliant guys are able to deal with?

        www.casca.pt
        Visit us on facebook!

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

                            Advertisement