Rotate object around bounding box centroid using rhinoscript

#1

I’m trying to rotate an object around it’s own center. So I have found the centroid of its bounding box, but I’m stumped as to how I should use the coordinate information of this centroid to define the rotation center:

baseObjects = flattenList(baseObjects)
cageObjects = rs.SelectObjects(baseObjects)
rs.Command("_BoundingBox _Enter")
rs.UnselectAllObjects()
Box = rs.LastCreatedObjects()
centroid = rs.SurfaceAreaCentroid(Box)
rs.RotateObjects(cageObjects, centroid, 45)

Obviously this rotation won’t work, I tried. But what way do I pass the coordinate info of the centroid on to the rotation command?

(Dale Fugier) #2

Hi @SNC,

How about this?

import rhinoscriptsyntax as rs
import Rhino

object_ids = rs.NormalObjects()
for id in object_ids:
    bbox = rs.BoundingBox(id)
    center = rs.PointDivide(rs.PointAdd(bbox[4], bbox[0]), 2.0)
    rs.RotateObject(id, center, 45.0, Rhino.Geometry.Vector3d.ZAxis)

– Dale

#3

Thanks, that will work!

(Graham) #4

Hi,

For info this is rhinoscriptsyntax in Python, which is different from the VBScript-based RhinoScript. You can label questions with Python and have more chances of getting an answer from someone who knows Python.

-g

#5

Thanks for the tip, I’ll keep it in mind.