Python Bill of Materials Script

I am using Rhino Version 8 SR18 (8.18.25100.11001, 2025-04-10) Commercial and I’m using Claude 3.7 Sonnet to write this python script to create a BOM. It is working almost perfectly, except I can’t get it to justify the text using the vertical center alignment. If anyone can help me figure this out it would be much appreciated. It’s a simple fix of after the fact I select all the text and change the justification to center, but I am certain there’s a way to do this in the code, as I was able to get it to get it aligned left to right on center. This is what it gives me…



this is what I want to see…

BOM.py (31.6 KB)

3 Likes

A little more work and this this will be one of the handiest tools out there. It does not like Rhino 7 very much, but spit out a something that looked like a BOM in 8 in less than a minute. With out much poking around to figure out how to make it work.

2 Likes

Hi @kervert,

Very cool script. You can “Vertically” center your text like so:

        # 2=Center alignment (horizontal) + 131072=Center alignment (vertical) = 131074 when added together
        text_obj = rs.AddText(text, point, height, justification=131074)

image

rs.AddText API docs:

Cheers!

1 Like

Hey that worked! Thank you very much! Here’s the script if anybody else would like it.
BOM.py (30.9 KB)

2 Likes

For anyone that wants to use the BOM script, know that in order for it to work you need to organize your building materials via layers, ie: i have a layer for 1x6, a layer for 2x10, etc, and it determines length via the longest edge.

1 Like

…and you need to place the BOM in layouts for the scale to be right. here’s a short video showing the flow.

2 Likes

I’m guessing (hoping) there’s some logic to this seemingly random pattern. 1,2…65536… :face_with_diagonal_mouth:

1 Like

Out of my knowledge base.. probably some kind of “byte” sequence describing an enum or something but totally a guess.

2 Likes

Helpful to see it in action, looks handy! Thanks for sharing!

Or in Document Properties under Annotation Settings turn off the Model Space Scaling and it will be scaled correctly in model space (at least in the limited testing I did)

2 Likes