Then, you can use a reverse Axis transformation.
[image: VgWn_Transformxyplane2.jpg]
The following code would for instance transform any given face to be in the XY plane, with its barycentre at the Origin.
axes = face.normal.axes
origin = face.bounds.center
t = Geom;;Transformation.axes(origin, axes[0], axes[1], axes[2]).inverse
Sktechup.active_model.entities.transform_entities t, face
The drawback of the above method is that the orientation of the transformed face in the XY plane is not predetermined.
So, if you wish to have a privileged direction, for instance an edge of the face to define the X axis, then use the following code instead, which will ensure that the selected <edge> defines the X axis, and that the Origin corresponds to the Start vertex of the edge.
origin = edge.start.position
xvec = origin.vector_to edge.end.position
zvec = face.normal
yvec = zvec * xvec
t = Geom;;Transformation.axes(origin, xvec, yvec, zvec).inverse
[image: 23wv_Transformxyplane.jpg]
Note that you can use the transformation <t> to calculate the coordinates of points to reconstruct a copy of the face, instead of transform it.
entities = Sketchup.active_model.entities
face.loops.each do |loop|
f = entities.add_face loop.vertices.collect { |v| t * v.position }
entities.erase_entities f unless loop.outer? # for holes
end
Hope this help!
Fredo