Active_path.last original transformation
-
When a component is being edited, then the model.active_path.size>0.
Unfortunately the component transformation is being modified in comparison with exactly same component transformation read from a selection.
I cannot find a way to get the very original transformation of the active_path.last...
When iterating through the model tree I get same active_path.last transformation. I am afraid there is none.I checked mod.axes.transformation, but it gives me just the correct origin of active_path.last, but other parts of the transformation are orthonormal.
Any ideas?
-
I don't think there's a way to get it easily.
You have to iterate through the model, searching for each child at each level, and multiply each transformation.
At least, that's how I do it. -
You could perhaps use a 'pick helper' to get the 'current transformation' taking into account any 'containers'...
` view = Sketchup.active_model.active_view
ph = view.pick_helper
x, y, z = view.screen_coords(some_point).to_a
ph.do_pick(x, y)
tr = ph.transformation_at(0) if ph.picked_edgeor whatever test needed etc`
-
@jiminy-billy-bob said:
You have to iterate through the model, searching for each child at each level, and multiply each transformation.
At least, that's how I do it.This doesn't work. I gives me exactly the "wrong" transformation.
@tig said:
You could perhaps use a 'pick helper' to get the 'current transformation' taking into account any 'containers'...
Thanks for the advice. Unfortunately I am not in a tool context and I am also afraid that is would still give me "wrong" transformation.
My scenario is following:
- I export a component into an "external file"
- replace it with a "proxy" - say a wireframe cube
- when a rendering starts I replace the "proxy" with original model....
The problem is that the original model has all coordinates of the initial(non-edited)definition, but the transformation and the definition of SU component changes while it is in edit mode! This causes wrong position/scaling of all instances of a component being edited.
-
If you have a transformation within a context can't you get the transformation.inverse and apply that to the transformation of the other object to 'correct' it ??
-
I could use the SU2016 Axes.origin and at least bring the component to a correct location when there is no scaling used in the component instance. I cannot call it a solution though.
-
No. It won't work.
Sketchup.active_model.entities[0].transformation.to_a
=>[1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 10.0, 10.0, 10.0, 1.0]When in edit:
Sketchup.active_model.entities[0].transformation.inverse.to_a
[1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -0.0, -0.0, -0.0, 1.0]Sketchup.active_model.active_path[0].transformation.inverse.to_a
[1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -0.0, -0.0, -0.0, 1.0]Those inverted transformations won't bring the origin to [10.0,10.0,10.0] either give correct rotation/scaling. SU simply resets the transformation to identity:
[1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
and re-do the definition in global coordinates... -
I don't understand why:
mod.entities[0].transformation.to_a
gives different results when I am inside the entities[0] then when I am outside it.
SU engineers have had a reason to do this, but this makes developers life worse.
What is the point in modifying a thing? EDIT: To allow drawing in global coordinates, so in this regards, it is beneficial.When the transformation is modified, then it is obvious that the definition has to be modified also, to keep the model consistent!
mod.entities[0].definition.entities[6].start.position.to_a =>[10.0, 0.0, 0.0] mod.entities[0].definition.entities[6].start.position.to_a =>[20.0, 10.0, 10.0]
-
Good to know, thanks!
-
It is good to do something else. When reading about model observers I have found the answer:
Sketchup.active_model.edit_transform
There is a mistake in the documentation though:
@unknownuser said:
ModelObserver.onActivePathChangedSketchUp 7.0+
...
When in "edit mode" (aka a Component is being edited), the Ruby API returns object transformations and locations in context of the "local" component axes instead of the global axes.It is other way round. In "edit mode" we are in global context. If one wants to have the local then use edit_transformation. When you want original transformations for the rest of instances then you have to go through the whole "tree" and use edit_transformation for the last group/component.
Advertisement