Is it possible to rotate textures using Ruby API?

Rather than creating duplicate textures in various rotations, we would like to be able to rotate a texture programmatically. Is this possible?

Yes this is possible:

   def rotated_material(face)
      material = face.material
      pt_array = []

      edge = longest_edge(face)
      return unless edge.is_a?(Sketchup::Edge)

      length = edge.start.position.distance(edge.end.position)
      vector = Geom::Vector3d.new length,0,0
      t = Geom::Transformation.translation vector

      tw = Sketchup.create_texture_writer
      uvHelp = face.get_UVHelper(true, true, tw)

      p1 = uvHelp.get_front_UVQ(edge.start.position)
      p2 = uvHelp.get_front_UVQ(edge.start.position.transform(t))
      d = p1.distance(p2)

      pt_array[0] = edge.start.position
      pt_array[1] = Geom::Point3d.new(0,0,0)
      pt_array[2] = edge.end.position
      pt_array[3] = Geom::Point3d.new(d,0,0)

      face.position_material(material, pt_array, true)
    end
1 Like

Thank you Guy, we are going to give this approach a whirl. Looks like it should the trick. :slight_smile:

You can find the answer here -
Rotate texture, not on a face - Developers / Ruby API - SketchUp Community

The function that he provided can rotate your material by exactly 90 degrees

Since this topic was started the API added the ImageRep class, which can be gotten directly from a texture assigned to a material. Then the pixel data can be retrieved, rotated or otherwise manipulated, then set back to the ImageRep. Lastly the modified ImageRep can be set as the texture to the original or a new material.