Python Message: index out of range: 2

Hello all,

I’m trying to automate a few things by exporting dimensions from python to text objects. I’m very new to python…
Test.py (1008 Bytes)

Hi @Sethaba,

you are trying to access a list index that does not exist. In the documentation you’ll see that rs.SurfaceArea() returns a list of 2 number values. Your script tries to acces a third value dimensions[2], which is out of range and causes an ‘index out of range’ exception.

If the object you want to get dimensions of is world-aligned, you could use it’s boundingBox

cheers,
Tim


bb = rs.BoundingBox(TextObject)

# for each world-aligned axis, get the bounding-box dimension
dim_x = bb[6].X - bb[0].X
dim_y = bb[6].Y - bb[0].Y
dim_z = bb[6].Z - bb[0].Z

Oh, I see. The issue with bounding box is if I have multiple objects to dimension, I have to select them individually. If there are 100’s that’s a real pain.

you can just iterate over all objects in a selection like so:

def main():
    # get object selection
    objs = rs.GetObjects(preselect = True)
    if not objs:
        print( 'abort' )
        return

    # loop over all objects in selection
    for obj in objs:
        bb = rs.BoundingBox(obj)
        # ... rest of code that creates a text for each bb

if __name__ == '__main__':
    main()

This is my 1st day, so I have no idea what I’m doing wow. :smiling_face_with_tear:

Test 2.py (718 Bytes)