Sketchup::Group#transformation. What is (or where is) the logic?

Two groups at the model root.

[grp0, grp1].map &:class
> [Sketchup::Group, Sketchup::Group]
[grp0, grp1].map &:parent
> [#<Sketchup::Model:0x000001c35ffb98d8>, #<Sketchup::Model:0x000001c35ffb98d8>]
Sketchip.active_model.active_path = []
grp0.transformation.identity?
> true
grp1.transformation.identity?
> false
Sketchup.active_model.active_path = [grp0]
> [#<Sketchup::Group:0x000001c378600940>]
grp0.transformation.identity?
> true
grp1.transformation.identity? # expected false
> false
Sketchup.active_model.active_path = [grp1]
> [#<Sketchup::Group:0x000001c379d8fd90>]
grp1.transformation.identity?
> true
grp0.transformation.identity? # unexpected true
> true

Obviously result of Group#transformation depends on the Model#active_path. But what in the case with grp0?

You didn’t share your model, but apparently grp0 was created that way, where its axes and origin are the same (coincide) with the global axes and global origin.

1 Like

Yes, it is. Otherwise it .transformatrion.identity? returns false

for example

pts = ORIGIN, ORIGIN + X_AXIS, ORIGIN + X_AXIS + Y_AXIS, ORIGIN + Y_AXIS
grp0 = Sketchup.active_model.entities.add_group
grp0.entities.add_face pts
trn = Geom::Transformation.new Geom::Point3d.new 3,3
grp1 = Sketchup.active_model.entities.add_instance grp0.definition, trn

Spot on, because …

… Entities.add_group() creates the empty group with an IDENTITY transform.

So @mike09 why would you not expect grp0 to have an identity transform when you are in another edit context?

Read the API Note in the Model#active_path= setter method regarding the change in coordinate system whenever the user (or the API) has drilled down away from the top model entities context.

It is very important to understand that this edit mode change into model coordinates affects all API methods accepting or returning coordinates, scaling or lengths, etc.

However, if the active entities is still the top level model entities, and you are inspecting the groups entities members then the definition’s local coordinates will apply.

Thank you, Dan, your answers are always helpful. Maybe you’re right and I didn’t make it clear enough what confused me.
In my mind, transformation is a description (position, direction and scaling) of local coordinates space in which entities, included in group (component definition) are lying. Agree that to determine these properties (position and so on) we must have a point of reference - a kind of global (root) coordinate space. This code (and documentation)

Sketchip.active_model.active_path
> []
grp1.transformation.identity?
> false
Sketchup.active_model.active_path = [grp1]
> [#<Sketchup::Group:0x000001c379d8fd90>]
grp1.transformation.identity?
> true

confirms that it is not constant (and that’s not a problem). Perhaps I am mistaken, that is indicated by rgb axes and returned by Model#edit_transform. In case active_path.empty? it equal to model coordinates space, in edit mode - to editing groups (instance) transformation. It seemed strange to me that two clearly mismatched groups both have same (IDENTITY) transformation at same time.

I think this handling of coordinates within the active context derives from what happens in the GUI when you open a group or component instance for edit: you see and interact with it through the view window, which always shows model coordinates. Otherwise you couldn’t snap to inferences from anything outside the context. I think the devs put a thin wrapper around this for the Ruby API, assuming that coders would figure it out.