Rotating a Group to Align a Material


This topic may be covered in previous posts but I couldn’t seem to find a concise answer to my question so I’ll post it anyways.

Basically I have an array with some points for my stair stringer. I am creating the group/solid as below:

group1 = Sketchup.active_model.active_entities.add_group
entities1 = group1.entities
new_face1 = entities1.add_face @Stringer_points
new_face1.pushpull @Stair_stringer_thickness

Very simple code. The problem of course is that if I specify a texture for the material it aligns per the horizontal axis and not per the long axis of the stringer which is inclined at some angle (theta) from the horizontal.

The problem is that once I have the array of points I need to somehow create the face (in the group), rotate the face by negative theta, ungroup the geometry regroup it, then rotate the group back into place by positive theta.

This just seems like a lot of messing around to get a very simple result. I’m looking for ideas or suggestions on how to accomplish this with a little less juggling.


I was thinking it might make sense to transform the array of points before actually utilizing them to create the face. The transform method does exist for a 3D point.

Is it possible to transform more than one point at one (an array of points)?


When you group and ungroup geometry via Ruby during a single operation, there’s usually another way to do it.

Are you using face.material= instead of face.position_material? The latter let you control how the texture is oriented. The former just applied default UVs.


The SketchUp API adds to the core Array class but assumes “point/vector-like” 3 element arrays of Float or Length, not arrays of points (or nested arrays).

So you’d need to use the core Array#map method to return a new array of transformed points.

# ary is an array of Geom::Point3d objects
new_ary = {|pt| pt.transform(transformation) }

Note that some of the API’s #transform methods will also take a 3-element array in leu of the transformation object


I’ll give this one a go.

Transform the points, create the face and group, then transform the group back into the correct orientation.


That works great, thank-you.

In the case of my stair tread where I’m including a rounded bull nose I had to use a slightly different method:

group1 = Sketchup.active_model.active_entities.add_group
entities1 = group1.entities

tread_rot_trans1 = Geom::Transformation.rotation(rotpt, Z_AXIS, -1.57079632679)
tread_rot_trans2 = Geom::Transformation.rotation(rotpt, Z_AXIS, 1.57079632679)

angle1 = PI * 0.5
angle2 = PI * -0.5
r1 = 0.5 * @Stair_tread_thickness

normal1 = 0,1,0
xaxis1 = 1,0,0

line1 = entities1.add_line pt1, pt2
line2 = entities1.add_line pt3, pt4
line3 = entities1.add_line pt1, pt4

edgearray1 = entities1.add_arc cpt, xaxis1, normal1, r1, angle1, angle2, 6

tread_profile = line1.all_connected
entities1.transform_entities(tread_rot_trans1, tread_profile)
new_face1 = entities1.add_face(tread_profile)
new_face1.reverse! if new_face1.normal.x < 0
new_face1.pushpull @Stair_width

group1.transform! tread_rot_trans2


This method may be what you need to move axes: