Apply a model transformation to an entity in a component instance

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.