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.
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)
brep=rs.coercebrep(obj)
vmp=Rhino.Geometry.VolumeMassProperties.Compute(brep)
if vmp: print vmp.Centroid
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.