Assign a name from bounding box

I would like to know if there is a script able to assign the name of an object from the size of the bounding box adding a prefix.
For example, if I have a plate like the one in the picture I would like to be able to automatically assign the name “plate 440x95x10”

HI, how’s this (use _EditPythonScript to launch the python script editor:

  • use this macro on a button or alias -

! _-RunPythonScript "Full path to script file in double quotes"

import rhinoscriptsyntax as rs

def name_by_bbox():
    prefix = rs.GetString(message = 'prefix to add', defaultString = 'plate')
    objects = rs.GetObjects('select objects to name')
    if not objects: 
    for obj in objects:
        bbox_points = rs.BoundingBox(obj)
        x0, y0, z0 = bbox_points[0]
        x1, y1, z1 = bbox_points[6]
        bbox_name = prefix + ('x'.join([str(int(x1-x0)), str(int(y1-y0)), str(int(z1-z0))]))
        rs.ObjectName(obj, bbox_name)
if __name__ == "__main__":

thanks, unfortunately, when I launch the script the following error appears to meerror%20message

You need to replace the text "Full path to script file in double quotes" with the full path to script file, written in double quotes !

ok now I try.

Ahh I think you have included that line in your script - You need to start your script file from import rhinoscriptsyntax as rs :smiley:

Note that this currently takes the dimensions without decimals and truncates so for instance 9.999999 becomes 9. This could be changed to include decimals or round to the nearest integer…?

perfect it’s what I need. Thanks so much

Prego !

would have another request: it is possible to draw the bounding box above the selected object and define its weight, for example, knowing that it is made of iron. This would help me to know the real weight of the “bounding box” plate from which the element is obtained. It would be useful to see it written in a dot