How can I get the DC component's measurements

how can I get the component measurements without adding lenx, leny, lenz in the attributes.

I want to show the values ​​on the screen

I also needed to show how many square meters per material in the project, like fredo’s report.

You might use the dimensions of the component’s bounding box via the #bounds method.
But a bounding box is always aligned with the model axis, so it will be incorrect if the instance is rotated.

Hey Dan, thks, but how does the sketchup report get this information?
I can get it to show the measurements.

If you are speaking of the web-based Generate Report feature, I could only guess as it’s implemented in the cloud. (Ie, I cannot see the code.)

But from my understanding, it is the user that chooses the attributes to populate the report with. For objects appearing as line items in the report, if they do not have a selected attribute then that column would be blank for that item.

Okay? So looking at the supplied example “Quantities Report” edit page, … we see that there are 2 types of attributes marked with icons.

Those with the SketchUp icon are (mostly) derived from entity properties. (The last 5: “Price”, “Size”, “URL”, “Owner” and “Status” are actually attributes of special “native” attribute dictionaries. The user would have to enter values into the fields for these in the Entity Info inspector panel. SketchUp does not populate these values.)
As I had said above, it is mostly likely that the LenX, LenY and LenZ values are either the dimensions of the objects bounding box, or if it is a component instance or group, then they might be derived from the object’s definition’s untransformed bounds multiplied by the object’s scale from it’s transformation. (The latter is better because instance rotation skews the dimensions of bounding boxes. If instead you first get the width[X], height[Y] and depth[Z] of the definition’s bounds and scale them to the instance’s scaling, you get correct values. If the instance’s bounds match it’s definition’s bounds dimensionally, then the instance is neither rotated nor scaled.)

Now, those attributes with a Dynamic Component icon, come from the “dynamic_attributes” dictionaries of definitions and their instances. If a selected attribute is not used by certain line items then that column will be blank for those object items.
So in order for any dynamic attribute to appear in a report on a line for any given object, that object’s definition must define that attribute and usually give it a default value. (Yes, some string values are blank and it is expected that the user will assign text to the attribute and this will be saved in the instance’s “dynamic_attributes” dictionary.)
So the rule is, if it’s a component instance or a nested DC group, check it’s “dynamic_attributes” dictionary first for an attribute. If it doesn’t exist (and it’s not a group) secondly check it’s definition’s “dynamic_attributes” dictionary.

1 Like