How to change axes inside a component? (error in code fixed)

Although a component definition is quite similar to a SketchUp model of its own, my_component_instance.model refers to the one and single outer model. It is a reference to the model on which you change again the global axes.

When a user changes axes at the global level, the displayed axes will be changed (not the coordinate system).
When a user changes axes inside a component or group, the component definition’s axes will be changed (the coordinate system).

If you want to change the coordinate system of a component definition, you have to apply the transformation to all component instances and the reverse transformation to all entities within the component definition to compensate for it again. The coordinate system and axes change, but the entities stay where they were.

transformation = Geom::Transformation.axes([10,0,0], xaxis, yaxis, Z_AXIS)
my_component_definition = my_component_instance.definition
# Transform all instances
my_component_definition.instances.each{ |instance|
  instance.transform!(transformation)
}
# Apply the inverse transformation to the contained entities
my_component_definition.entities.transform_entities(transformation.inverse, 
                                                    my_component_definition.entities.to_a)

1 Like