# Script to rotate objects 90 degrees around their center

**URL:** <https://discourse.mcneel.com/t/script-to-rotate-objects-90-degrees-around-their-center/8231>\
**Category:** Scripting\
**Created:** [May 8, 2014, 1:24pm UTC](https://discourse.mcneel.com/t/script-to-rotate-objects-90-degrees-around-their-center/8231 "2014-05-08T13:24:24Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [April 26, 2018, 1:15pm UTC](https://discourse.mcneel.com/t/script-to-rotate-objects-90-degrees-around-their-center/8231/21 "2018-04-26T13:15:03Z")

</div>

> [@heiwayuuri](#):
>
> I use this script.
> 
> Ocjects use Rectangle.

Dunno, seems to work OK here. Are you trying to use it in normal Rhino or in a Grasshopper script component? The script is not designed for Grasshopper.

---

<div class="post-metadata">

**Author:** ![heiwayuuri](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/heiwayuuri/32/89594_2.png) [@heiwayuuri](https://discourse.mcneel.com/u/heiwayuuri)\
**Post date:** [April 26, 2018, 1:23pm UTC](https://discourse.mcneel.com/t/script-to-rotate-objects-90-degrees-around-their-center/8231/22 "2018-04-26T13:23:03Z")

</div>

Sorry, I gave you a misunderstanding.

I can select many objects.but This code selects only one.

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [April 26, 2018, 1:41pm UTC](https://discourse.mcneel.com/t/script-to-rotate-objects-90-degrees-around-their-center/8231/23 "2018-04-26T13:41:15Z")

</div>

OK, I hacked together a fix to use multiple objects…

```auto
#original script by djordje 2014, modified by Mitch 2018
python
import rhinoscriptsyntax as rs

def rot_ctr(id):
    centroid=None
    if rs.IsCurve(id) and rs.IsCurveClosed(id):
        centroid = rs.CurveAreaCentroid(id)[0]
    elif rs.IsCurve(id) and not rs.IsCurveClosed(id):
        d = rs.CurveDomain(id)
        centroid = rs.EvaluateCurve(id, (d[0]+d[1])/2)
    elif rs.IsSurface(id) or rs.IsPolysurface(id):
        centroid = rs.SurfaceAreaCentroid(id)[0]
    elif rs.IsMesh(id):
        centroid = rs.MeshAreaCentroid(id)
    return centroid

def RotateObjects90():
    ids = rs.GetObjects("Pick objects to rotate", preselect=True)
    if not ids: return
    
    choices=["lz","rz","ly","ry", "lx", "rx"]
    dirAxis = rs.GetString("Choose rotation direction and axis", "lz", choices)
    if (dirAxis is None) or (dirAxis not in choices): return
    
    rs.EnableRedraw(False)
    for id in ids:
        if rot_ctr(id):
            if dirAxis == "lz":
                rs.RotateObject(id, rot_ctr(id), 90, [0,0,1])
            elif dirAxis == "rz":
                rs.RotateObject(id, rot_ctr(id), -90, [0,0,1])
            elif dirAxis == "ry":
                rs.RotateObject(id, rot_ctr(id), 90, [0,1,0])
            elif dirAxis == "ly":
                rs.RotateObject(id, rot_ctr(id), -90, [0,1,0])
            elif dirAxis == "lx":
                rs.RotateObject(id, rot_ctr(id), 90, [1,0,0])
            elif dirAxis == "rx":
                rs.RotateObject(id, rot_ctr(id), -90, [1,0,0])
RotateObjects90()

```

HTH, --Mitch

---

<div class="post-metadata">

**Author:** ![heiwayuuri](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/heiwayuuri/32/89594_2.png) [@heiwayuuri](https://discourse.mcneel.com/u/heiwayuuri)\
**Post date:** [April 26, 2018, 2:36pm UTC](https://discourse.mcneel.com/t/script-to-rotate-objects-90-degrees-around-their-center/8231/24 "2018-04-26T14:36:51Z")

</div>

I’m so happy!!  
Thank you Helvetosaur.

Finally, hear only one wish.  
I want to rotate with the height of the object being the lowest.  
I do not know how to evaluate objects and rotate.

 ![1](https://global.discourse-cdn.com/mcneel/original/3X/5/2/52d5ba714b02bd2cfc75d3e3aa602e31e6936f8c.PNG)

I really appreciate your kindness.

---

<div class="post-metadata">

**Author:** ![Helvetosaur](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/helvetosaur/32/635974_2.png) [@Helvetosaur](https://discourse.mcneel.com/u/Helvetosaur)\
**Post date:** [April 27, 2018, 2:01pm UTC](https://discourse.mcneel.com/t/script-to-rotate-objects-90-degrees-around-their-center/8231/25 "2018-04-27T14:01:39Z")

</div>

> [@heiwayuuri](#):
>
> I want to rotate with the height of the object being the lowest.

I don’t quite understand this - you want to rotate around each object’s center, but projected to the object’s lowest point?

---

<div class="post-metadata">

**Author:** ![Sebastien\_Mau](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sebastien_mau/32/436027_2.png) [@Sebastien\_Mau](https://discourse.mcneel.com/u/Sebastien_Mau)\
**Post date:** [January 27, 2023, 1:20am UTC](https://discourse.mcneel.com/t/script-to-rotate-objects-90-degrees-around-their-center/8231/26 "2023-01-27T01:20:29Z")

</div>

Exactly what i’m looking for.  
But Could i ask you for some help to tweek it a little bit ?  
I’ve made a custom Keyboard for a 3D navigation mouse, and i’ve added a rotary encoder. I can assign a Keyboard input when turning the rotary encoder one way or another. My Idea would be to be able to assign a keyboard shortcut to the encoder in order to turn my objet, by increments of 18 Degrees, since i’ve got 20 Steps on my encoder. Is there a way to assign the LX (For example) as a keyboard Alias ?  
Many Thanks

[Previous page](https://discourse.mcneel.com/t/script-to-rotate-objects-90-degrees-around-their-center/8231.md?page=1)
