Transform_entities not updating origin

transform_entities
entities
transform
transformation

#1

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.


Transform an entity a given distance along a given vector
#2

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.


#3

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.


#4

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

#5

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).


#6

How about ?

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

#7

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

Thanks a lot!!!