Hi, I would like to take the volume centroids of lots of boxes (closed solid polysurfaces).
When I select all the boxes (hundreds of them) and use VolumeCentroid, it gives me the centroid of their grouped bounding box. I need the individual centroid of each object selected. It’s easy enough if I’m just selecting a few boxes but I need to do it for hundreds of them.
Option Explicit
'adds a Dot at the selected objects' centroid
'with the object volume in current file units
' Rhino.AddStartupScript Rhino.LastLoadedScriptFile
' Rhino.AddAlias "VolumeTag","_NoEcho _-Runscript (VolumeTag)"
Call VolumeTag()
Sub VolumeTag()
Dim arrObj, strObj, strVol, arrVolume, strVolume, arrCent, arr3dCent, arrThings, strDot, strGroup
arrObj = Rhino.GetObjects("Select closed objects for volume tag", 8 + 16 + 32,, True)
If IsArray(arrObj) Then
For Each strObj In arrobj
arrvolume = Null
arrCent = Null
arr3dCent = Null
If Rhino.IsSurface(strObj) Or Rhino.isPolysurface(strObj) Then
If Rhino.isObjectSolid(strObj) Then
arrVolume = Rhino.SurfaceVolume(strObj)
strVolume = Round(arrVolume(0), 4)
arrCent = Rhino.SurfaceVolumeCentroid(strObj)
arr3dCent = arrCent(0)
End If
ElseIf Rhino.IsMesh(strObj) Then
If Rhino.IsMeshClosed(strObj) Then
arrVolume = Rhino.MeshVolume(strObj)
strVolume = Round(arrVolume(1), 4)
arr3dCent = Rhino.MeshAreaCentroid(strObj)
End If
End If
If IsArray(arr3dCent) Then
strDot = Rhino.AddTextDot("Vol = " & strVolume, arr3dCent)
strgroup = Rhino.addGroup
arrThings = array(strDot, strObj)
Rhino.AddObjectsToGroup arrThings, strGroup
End If
Next
End If
End Sub
Hi Bahji, I am trying to accomplish same thing. Can you please share a gh file or a screenshot of how exactly you used the script (new to grasshopper). Thank you
I thought this would solve my problem, but the script doesn’t seem to work with open meshes, or bad polysurfaces which is what I have to work with at the moment. Is there a script that would work in my situation?
objects that are open don’t contain a volume (if you tip a jar without its top on, the sauce falls on the floor) and bad objects are constructed in a way that creates ambiguity about what’s inside/outside. if the geometry is relatively simple, rhino can calc a centroid, but in general both open objects and bad objects lead to unpredictable volume centroid calculations.
ie, fix the geometry to be closed before running volume centroid. if on R8, you can run shrink-wrap to get a general volume