Get Volume Centroid without creating the point


I’m trying to pull the volume centroid of polysurface using the code below and I get the following error: “Message: getset_descriptor is not callable”. Can anyone explain what I am doing wrong. I only want the coordinates and not the physical point (the Rhino Command creates a physical point). Yes I know I can get the bounding box and calculate it myself. If I can do it in less code that would be better for me.



import Rhino
import rhinoscriptsyntax as rs

obj = rs.GetObject(“Select”,0)
pt = Rhino.Geometry.VolumeMassProperties.Centroid(obj)

You can’t combine rhinoscriptsyntax and RhinoCommon like that - rhinoscriptsyntax returns an object id (GUID) and RhinoCommon wants an actual geometry object. However, it is not necessary to use RhinoCommon in this case…

import rhinoscriptsyntax as rs

obj = rs.GetObject("Select", 8+16)
centroid = rs.SurfaceVolumeCentroid(obj)
if centroid: print centroid[0]

If you want to do it in RhinoCommon, you need to first get the RhinoCommon geometry from the object’s id, then run the VolumeMassProperties calculation:

import rhinoscriptsyntax as rs
import Rhino

obj = rs.GetObject("Select",8+16)
if vmp: print vmp.Centroid

As @Helvetosaur mentioned you’d better use rs.SurfaceVolumeCentroid, however, if you prefer using Rhinocommon you can use the following script.

import Rhino
import rhinoscriptsyntax as rs
obj = rs.coercegeometry(rs.GetObject("Select", 0))
centroid = Rhino.Geometry.VolumeMassProperties.Compute(obj).Centroid

Unlike rs.SurfaceVolumeCentroid, this script also will be working for Mesh objects.

Thanks again. Beginners mistake. I’ll try them both out.




I did have a few problems with the RhinoScript version. I tried it on polysurfaces but some of them would return nothing. The RhinoCommon version worked in all cases and this is what I will use.

Thanks for the feedback.