If the material is positioned on the face it should stay in the same place. When faces have no given texture positioning however the texture is rendered according to the local axes. Since newly created group gets their origin in the bottom left corner of the bounding box the un-positioned materials will appear to have moved.
I haven’t been using the texture positioning part of the API for many years but remember I found it could hard to use. I don’t even think there is a way to determine whether a face actually have a texture position saved to it or not (but I could remember it wrong). One way to solve this could however be to make sure all faces have a defined texture position.
Another solution is to make sure the newly created groups’ axes all line up perfectly with the axes of the parent drawing context. To achieve this just transform all entities inside each group with the group’s own transformation and set the groups transformation to the identity transformation.
def faces_to_components(faces)
parent = faces.first.parent
entities = parent.entities
while !faces.empty?
connected_faces = faces.first.all_connected.grep(Sketchup::Face)
component = entities.add_group(connected_faces).to_component
child_entities = component.definition.entities
child_entities.transform_entities(component.transformation, child_entities.to_a)
component.transformation = IDENTITY
faces -= connected_faces
end
end
This code works for me. Beware that when faces are located inside a group or component and the user is inside that drawing context, SketchUp will suddenly use global coordinates, as opposed to returning the actual internal value. This may result in textures being positioned according to the model axes, not according to their former parent axes.