For some time now I have been trying to obtain the global coordinates of nested component instances.
I had some success when the instances have the axes with the same positions, the problem is when there are instances with different or rotated axes.
Could anyone help me with this issue? Is this possible?
References used:
My code example:
model = Sketchup.active_model
selection = model.selection
def get_all_instances(entities, path, other)
entities.grep(Sketchup::ComponentInstance).concat(entities.grep(Sketchup::Group)).each do |dc|
other = dc if dc.parent.is_a?(Sketchup::Model)
pt = dc.transformation.origin
ptt = pt.transform(dc.parent.is_a?(Sketchup::Model) ? Geom::Transformation.new(ORIGIN) : other.transformation)
puts "#{ptt} - #{dc.definition.name} - #{path}"
get_all_instances(dc.definition.entities, path + [dc], other)
end
rescue StandardError => error
puts error.backtrace
raise
end
path = model && model.active_path ? model.active_path : []
get_all_instances(selection, path, other = nil)
Note that in the first case (left of the video) the coordinates are correct, in the second case the coordinates are incorrect because the instances were grouped into a group with a different axis than the others.