Python - Object has no attribute 'XYZ'

Hi all,

Fairly simple question I hope. I am very new to Python but know a bit of Design Script.

I am trying to get the Min/Max points of a viewport as described in this post: Get height and widht for door/window in linked ifc

I am just getting started with python in dynamo and have followed the setup guidelines in the Dynamo Python Primer & have used their (quite long) boiler plate code - so am only showing the body of the code. When I try access the API CropBox property of the view I am being told the object does not have this attribute.

Here is the code.

views = UnwrapElement(IN[0])

bbox = views.CropBox()

OUT = bbox

I understand that this error can occur if you do not unwrap the dyanmo elements, or if you call an API property/method that is not associated with the objects class. However, I’m not sure if this is the cause of the issue or not.

Thanks for your help!

You are feeding a list of views into the Python node, instead of an individual element.

As such Python is looking at the list and trying to pull the crop box from that rather than iterating over the list to pull the crop box from each view.

To overcome this you need to use a for loop or list comprehension to tell Python that you want it to use the items in the list to perform the action.

Try this, which uses list comprehension to ensure the iteration (though I may have a typo - writing this on my phone):
bBox = [ view.CropBox() for view in views ] OUT = bBox

This is one area where the associative nature of Design Script makes things easier to learn - looping is handled by the built in lacing capabilities.

Hi Jacob, thanks for the reply.

Okay that makes sense. I’ve managed to learn a bit about the Imperative environment Design Script via the its PDF guide - which has been useful, but has its limitations due to no API integration.

I’ll need to have a look at list comprehension in Python to start getting my head around that.

Unfortunately I am now receiving this error - again it could be a class issue but I’m not sure.


1 Like

Actually, I figured this one out. The “()” after view.CropBox had to be removed as this is not a “callable” class - not sure what that quite is yet but for now the peroblem is resolved. Thanks!

1 Like