Howto get object centers?

I’m trying to get started with Rhino Python and I’m stuck with basics . For a start I’m trying to create a script that would print centers of selected items.
This does not work:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

objects = rs.GetObjects("Select objects ",preselect=True)

for object in objects:
    center = item.Geometry.GetBoundingBox(True).Center

What’s the correct way to do it?
I’m trying with this simple thing as it would allow me to loop thorugh things and do repetitive tasks per item using the item center.

Hi @przemek,

You are calling the GetBoundingBox method from the object GUID. This is why you get an error.
To fix this you first have to search for the actual Rhino geometry with sc.doc.Objects.Find(obj).Geometry and then call the method as you did. I commented your script to show where this happens.

import Rhino
import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
import scriptcontext as sc

def Main():
    objectsId = rs.GetObjects("Select objects ",preselect=True) #This returns the object Id

    for obj in objectsId:
        objGeo = sc.doc.Objects.Find(obj).Geometry #This returns the rhino geometry
        center = objGeo.GetBoundingBox(True).Center #Call the method on the geometry
        print(center) #Result

if __name__ == "__main__":

Hope this helps! :slight_smile:


thank you! That makes sense :slight_smile: .