# Rotating a Group to Align a Material

#1

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.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.

#2

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)?

#3

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.

#4

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 = ary.map {|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

#5

I’ll give this one a go.

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

#6

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

angle1 = PI * 0.5
angle2 = PI * -0.5

normal1 = Geom::Vector3d.new 0,1,0
xaxis1 = Geom::Vector3d.new 1,0,0

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