Create component with different axes
-
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