Object Centroid Script - works on all objects based on bounding box cen

VolumeCentroid Won’t work with curves.

Is there a script or option to get it work based on bounding box. Thanks

The Gumball center should be the bb center of selected curves… Or make a bounding box and use volume centroid on that.

Hi Mitch thank you for writing on this.

I mean a command that would create VolumeCentroids despite the object as with planar curves this approach would not work.

Just a Center/Centroid function for all — no concept of Area Centroid or Volume Centroid - just automatic based on context.

Thank you

The problem is that all of these are potentially different.

A closed surface/polysurface can have

  • a volume centroid
  • an area centroid
  • a bounding box center

All three of those can be different points.

An open surface/polysurface can have

  • an area centroid
  • a bounding box center

Both of those can be different points.

An planar curve can have

  • an area centroid
  • a bounding box center
    And if it is a polyline it can also have
  • the average of its vertices
  • the average of its edges

All of those can be different points.

An arbitrary 3D curve can have

  • a bounding box center

So you can see that the only one that is common to all of the above is the bounding box center - which is what Gumball uses. And for the objects that have multiple possibilities - practically all of the above - which method should Rhino choose?

Edit - if you want a simple script you can put on an alias to create a point at selected objects’ bounding box center, here you go:

import rhinoscriptsyntax as rs

obj_ids=rs.GetObjects("Select objects for bounding box centroid",preselect=True)
if obj_ids:
    bb=rs.BoundingBox(obj_ids)
    if bb: rs.AddPoint((bb[0]+bb[6])/2)
1 Like

Mitch! So good, we have to mention for newbies to take the script data and paste them into a text file and name it ObjectCentroid.py and move it into the scripts folder and bind an Alias to it as OC

Thanks a lot for this works like a charm!

Well, there are a number of ways to install and run scripts:
https://wiki.mcneel.com/rhino/macroscriptsetup

Well, that might be a bit of a misnomer, as it doesn’t find the object centroid, it only finds the bounding box center (as mentioned above).

1 Like

Hey Mitch, as always — sharp as a katana.