How to make components origin attached to the component instead of the model origin

You said you want the local Z axis in the same direction as the push pull, but you are sometimes reversing the face normal, which will affect the transformation. We would like to figure out if the face’s normal is being reversed before the face is created. Since I don’t understand the entire process, I will attempt to create the face first, and then convert the component’s entities to local coordinates:

comp = Sketchup.active_model.definitions.add("TEST")
face = comp.entities.add_face( @pts )
if face.normal.samedirection?( @lenvec ) then
  face_normal = @lenvec
else
  face_normal = @lenvec.reverse
  face.reverse!
end
face.pushpull( @length )
# The face is now defined, but not assigned to a component instance,
# lets work with it a bit more.
. . .
trans = Geom::Transformation.new( @pts[0], face_normal )
comp.entities.transform_entities( trans.inverse, comp.entities.to_a ) # Put into local coords
instance = Sketchup.active_model.active_entities.add_instance(comp, trans)

I can’t load this into Sketchup to check my logic or even the syntax, so keep us updated.

1 Like