How to move a component

sketchup

#1

i want to move component to the new position(new_component_pos). but the component is upside-down.

new_component_instance.move! Geom::Transformation.new(new_component_pos - new_component_instance.transformation.origin)

#2

There are two ways to use transformations. They can be used as:

  • Absolute data that represents the local coordinate system of a grouped object (appropriate for grouped objects only); and
  • Relative or update data that applies a relative increment

The “move!” method replaces the entities transformation with the supplied argument. Taking the difference between two positions results in a vector, and the transformation you create is a translate. The translate is more of a relative operation. You are replacing the object’s position with the difference between two positions. It would descale, de-rotate, and the transformation’s origin would be position of the entity. In addition, “move!” does not support edit undo: Below are three options for grouped objects:

  1. Continue to use move! (the argument is interpreted as absolute data, and a relative operation requires multiplying the original transformation) the operation will not support edit…undo:
translate = Geom::Transformation.new(new_component_pos - new_component_instance.transformation.origin)
new_component_instance.move! translate * new_component_instance.transformation
  1. Instead of “move!”, use "transformation = " as it logs operations for “edit…endo”:
translate = Geom::Transformation.new(new_component_pos - new_component_instance.transformation.origin)
new_component_instance.transformation = translate * new_component_instance.transformation

  1. Use transform!, as it applies a transformation to the existing one (and supports edit…undo):
translate = Geom::Transformation.new(new_component_pos - new_component_instance.transformation.origin)
new_component_instance.transform! translate

#3
new_component_instance.tranform! Geom::Transformation.new(
  new_component_instance.transformation.origin.vector_to(new_component_pos)
)

#5

thank you. your answer is very helpful for me.


#6

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.