I have many components in a model and want to mass-relocate all their individual axes to the 0,0,0 model origin. The axes would also need to be rotated so as to align with the model origin axis as well.
Here is the script I’m working with - which has issues: (its a Chat GTP output.)
require 'sketchup'
# Function to set the axes of a component or group to the origin
def set_axes_to_origin(entity)
# Get the transformation of the entity
tr = entity.transformation
# Create a new transformation that only changes the axes
new_transformation = Geom::Transformation.new(tr.xaxis, tr.yaxis, tr.zaxis, ORIGIN)
# Set the new transformation to the entity
entity.transformation = new_transformation
end
# Main script
model = Sketchup.active_model
entities = model.active_entities
ORIGIN = Geom::Point3d.new(0,0,0)
# Start an operation that can be undone in one step
model.start_operation('Set Axes to Origin', true)
# Iterate through entities in the model
entities.each do |entity|
# Check if the entity is a group or component instance
if entity.is_a?(Sketchup::Group) || entity.is_a?(Sketchup::ComponentInstance)
set_axes_to_origin(entity)
end
end
# Commit the operation
model.commit_operation
puts "Axes of all components and groups have been set to the origin."
All this does is to move all model groups and components to the 0,0,0 point, when what I want is to merely move the axes here.
Edit: This extension moves the components to the origin, basically what you allready have…
Edit 2: Do you mean you want to leave the components in place and move only their axes to the origin?
1: Why do you want to do that?
2: Be aware that having the components axis a long way from the components geometry can sometimes cause trouble. The same applies to components with their axis close by that are a great distance from the origin.
I’m exporting them all to Lumion and will be pulling in each one in a phased animation. The component axes have to be in the same place for the whole thing to start and finish correctly.
This will affect ALL instances of a group or component. If there are multiple instances, then the code will need to make each have a unique definition before doing any of the above. Ie …
grp.make_unique if grp.definition.instances.size > 1
# ... Adjust the axes per above ...