# Is it possible to rotate textures using Ruby API?

**URL:** <https://forums.sketchup.com/t/is-it-possible-to-rotate-textures-using-ruby-api/7511>\
**Category:** Ruby API\
**Created:** [February 23, 2015, 7:15pm UTC](https://forums.sketchup.com/t/is-it-possible-to-rotate-textures-using-ruby-api/7511 "2015-02-23T19:15:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![petersaal](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@petersaal](https://forums.sketchup.com/u/petersaal)\
**Post date:** [February 23, 2015, 7:15pm UTC](https://forums.sketchup.com/t/is-it-possible-to-rotate-textures-using-ruby-api/7511/1 "2015-02-23T19:15:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Guy](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/guy/32/88_2.png) [@Guy](https://forums.sketchup.com/u/Guy)\
**Post date:** [February 23, 2015, 7:57pm UTC](https://forums.sketchup.com/t/is-it-possible-to-rotate-textures-using-ruby-api/7511/2 "2015-02-23T19:57:00Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![petersaal](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@petersaal](https://forums.sketchup.com/u/petersaal)\
**Post date:** [February 23, 2015, 8:40pm UTC](https://forums.sketchup.com/t/is-it-possible-to-rotate-textures-using-ruby-api/7511/3 "2015-02-23T20:40:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Divyanshu](https://avatars.discourse-cdn.com/v4/letter/d/e495f1/32.png) [@Divyanshu](https://forums.sketchup.com/u/Divyanshu)\
**Post date:** [January 13, 2021, 10:33am UTC](https://forums.sketchup.com/t/is-it-possible-to-rotate-textures-using-ruby-api/7511/4 "2021-01-13T10:33:30Z")

</div>

You can find the answer here -  
[Rotate texture, not on a face - Developers / Ruby API - SketchUp Community](https://forums.sketchup.com/t/rotate-texture-not-on-a-face/14326)

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

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [January 13, 2021, 11:14am UTC](https://forums.sketchup.com/t/is-it-possible-to-rotate-textures-using-ruby-api/7511/5 "2021-01-13T11:14:50Z")

</div>

Since this topic was started the API added the [`ImageRep`](https://ruby.sketchup.com/Sketchup/ImageRep.html) 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`](https://ruby.sketchup.com/Sketchup/ImageRep.html). Lastly the modified [`ImageRep`](https://ruby.sketchup.com/Sketchup/ImageRep.html) can be set as the texture to the original or a new material.
