Transform_entities not updating origin

Hi guys,

I’m working on a Tool that align elements, but when using entities#transform_entities, the origin of the element doesn’t update.

When perform a transform! over the element it updates (is this a rigid transformation?).

Some example code:

#element = best picked
element.definition.entities.transform_entities(Geom::Transformation.translation [0, 12, 0], element.definition.entities.to_a)

Then, when go to Ruby Console and perform the code below (with element selected), the origin came with the old position:

puts Sketchup.active_model.selection[0].transform.origin

When execute $dc_observers.get_latest_class.redraw_with_undo element the element translate to the old position too.
Is there a way to “commit” this transformation?

Thank you.

Because you are transforming the definition’s entities with respect to the origin of the definition. So you are moving the objects away from the component origin.

Apply the translation transformation to the component instance instead.

if element.is_a?(Sketchup::ComponentInstance)
  element.transform!(Geom::Transformation.translation([0, 12, 0]))
end

P.S.: Only global methods defined in Kernel and Object should be called without wrapping the arguments in parentheses.

I need to move a rotated element in your own x,z axis, that’s why I’m using Entities#transform_entities.
With element.transform! if the element is rotated 45º, for example, when perform translation[0,12,0] the element won’t move in diagonal in relation to the global axes.

Alright, thanks.

I don’t understand what your trying to say. Perhaps a image cropped from a SketchUp screenshot ?

How about ?

if element.is_a?(Sketchup::ComponentInstance)
  t1 = element.transformation
  t2 = Geom::Transformation.translation([0, 12, 0])
  t = t1 * t2
  element.transform!(t)
end

This cause a weird behavior, rotates the element and translation at same time

I’m trying to do the second move: Move element to front (Y move in the case).

How about ?

vec = element.transformation.yaxis
vec.length = 12
vec.reverse!
t = Geom::Transformation.translation(vec)
element.transform!(t)
2 Likes

Well… @DanRathbun. That’s exactly what I’m looking for.
Great way to work with vector, don’t knew about it.

Thanks a lot!!!

1 Like