How to get transformation.origin of a internal component
-
We need to measure the [x,y,z] beetween the red’s circle’s marked in the picture.
How we need to do that? We have 2 components, one inside another. We need to know how to measure the distance of the x,y,z axis of the inside red block to the zero ground of the model. But to do that, we CAN’T add the values of the big gray box and the values of the red block inside, because we’re going to have too many elements one inside another, and calculate all this can be slow and it’s not a good solution.` Sketchup.active_model.entities.each{|ent|
puts "BigBox #{ent.transformation.origin.to_s}" if ent.is_a?(Sketchup::ComponentInstance) }Sketchup.active_model.entities.each{ |ent|
puts ent.definition.entities.each{ |e|
puts "RedBox #{e.transformation.origin.to_s}" if e.is_a?(Sketchup::ComponentInstance)
} if ent.is_a?(Sketchup::ComponentInstance) }` -
First find the insertion point of the Redbox instance in its current context.
Next find the transformation of the Bigbox container instance.
You need to get a handle on the 'Redbox'.
Let's assume there is only one instance and that's inside Bigbox.
redbox = model.definitions['Redbox'].instances[0]
Now get its insertion point
pt = redbox.transformation.origin
Now let's assume there's only one instance of 'Bigbox'.
bigbox = model.definitions['Bigbox'].instances[0]
Get its transformation
tr = bigbox.transformation
Apply that to the point 'pt'
pt.transform!(tr)
The point 'pt' is now relative to the model's origin, NOT the Bigbox's internal origin...
Advertisement