Apply a model transformation to an entity in a component instance

I’m wondering if there is an easy way to change the transformation of an entity in a component instance, to match the transformation of an entity out side of the component. For example I have a component for a building. I glue a window component to the building. Now I want to create a component inside the building component to cut out the siding face. If I use the transformation from the window component it wont work because the building component has a different origin and rotation than the main model.

I’m interpreting your example as the reverse of the first sentence. I will discuss it from the point of view of the example. Given a building component and a window component whose transformations are in the same coordinate system:

A simple copy of the window can be nested in the building component and positioned correctly with the following Ruby statements:

  view = Sketchup.active_model.active_view

  building = Sketchup.active_model.entities[0]
  window   = Sketchup.active_model.entities[1]

  new_local_tform = building.transformation.inverse * window.transformation

  nested_window = building.definition.entities.add_instance(
                              window.definition, new_local_tform )

But the copied window is the default color and does not inherit the materials. Moving material and attributes are dicussed at: http://forums.sketchup.com/t/is-there-some-kind-of-set-parent-method-to-move-a-group-inside-a-container/11194

The second thing is that the new window is superimposed over the original. You could either hide, move, or erase the original.

I guess your question was about the transformation, with the short answer being:

building.transformation.inverse * window.transformation

Applying the inverse of the building’s transformation converts from extrinsic coordinates to the local intrinsic cords.

This is exactly what I was looking for. The reason I don’t want to nest the window component is, so it can easily be selected and moved. I create a component inside the building/porch to use to cut the siding out.

cutout.transformation = building.transformation.inverse * window.transformation

Thanks for your answer.

Another question since faces don’t have a transformation. How can I get the face.normal relative to the model rather than the building component? I want to search my component instance for all faces that are parallel to my window component.

if face.normal == window.transformation.zaxis then create_cut_out(face, window) end

This works unless the face is inside a component with a different axis.

Sorry i just figured out the solution myself.

tr = building.transformation.inverse * window.transformation
if face.normal == tr.zaxis then …

Just a FYI,… in SketchUp Ruby, Array, Geom::Point3d and Geom::Vector3d instance objects can be transformed (ie, have .transform and .transform! methods.)


And since a face’s normal is a vector object, …

Thanks.
Transformation and vectors are still a bit confusing to me but I’m learning.