Create component with different axes
-
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?
-
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.
-
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?
-
Place the group/instance in code then use:
group.
... ORinstance.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... -
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.
-
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?
-
Let '
point
' be the new insertion point of the component.
Letvector=ORIGIN.point.vector_to(point)
Lettr=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) }
-
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) }
endI 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?
-
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 -
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 !!!!
-
Yes, sorry I was away after quickly posting my untested code snippet.
I thought that I did actually editvector=ORIGIN.point.vector_to(point)
to readvector=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... -
No problem - I just wanted to post the complete solution for other users.
Thanks for the help.
-
@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.
Advertisement