Axes tool by code II

  1. You need to apply the old group transformation onto the new group instance - considering the new group instance own transformation ( the add_group method is creating it with IDENTITY )
  2. Then you need to apply the old group transformation inverse onto the new group (definition) entities.

If you have such a simple model, where the new group you created have its origin in an ORIGIN, but geometries in a “same location” than the old group geometries


test_ax_tr.skp (16.4 KB)

then something like this:


def transform_obj_axes(obj, tr_ax)
  obj.definition.entities.transform_entities( tr_ax.inverse, obj.definition.entities.to_a )
  obj.transformation = obj.transformation * tr_ax
end


model = Sketchup.active_model
entities = model.active_entities
old_group = entities.find{|e| e.is_a?(Sketchup::Group) && e.name == "old_group"}
new_group = entities.find{|e| e.is_a?(Sketchup::Group) && e.name == "new_group"}

tr_o = old_group.transformation

#this may not needed, 
# you can use 'tr_o' directly as parameter for transform_obj_axes:
tr_ax = Geom::Transformation.axes(tr_o.origin, tr_o.xaxis, tr_o.yaxis, tr_o.zaxis)

model.start_operation("tr obj axes", true)
#just to make sure you will do as the UI does:
new_group.make_unique

transform_obj_axes(new_group, tr_ax)
model.commit_operation

__
Other references:

Get and move group axes - Developers / Ruby API - SketchUp Community :stuck_out_tongue_winking_eye:

https://extensions.sketchup.com/extension/446870d8-0755-4d0b-963d-7219ef236c7a/axes-tools

2 Likes