Customizing the bill of materials quantity

Parametric 3D CAD makes the life of the engineer so much better.

It doesn’t necessarily make it easier, nor does the first iteration of a design go much faster. But revisions will happen. And when they do, parametric designs will certainly be updated significantly quicker than 2D AutoCAD designs or drawings by hand.

But sometimes you just want to do something that was a piece of cake when drawn by hand. Adding a few milliliters of oil to the bill of materials (BOM) of a gearbox assembly  is such a matter.

It can be done however. I’ll show you how to do it manually and by using the API.

Suppose you have this assembly model of a planetary gearbox:

SolidWorks bill of materials quantity
Planetary fearbox (I like that typo)

The parts will show up in a drawing bill of materials as follows:

SolidWorks bill of materials quantity
Drawing with BOM
Manually

The first step to add lubricant to this assembly would be to add another part. I have chosen to add a part without any features (if your OCD requires you to add mates to get rid of those awful minuses, try adding a single Origin mate).

The BOM now looks slightly more complete:

SolidWorks bill of materials quantity
An empty part added so you don’t forget to order the lube
One lubricant please!

Now what? One gram, one hectoliter, one gallon? I can’t keep to remember the conversion from those Freedom Units to metric because they are so random.

The feature that SolidWorks has built for quantifying the amount of such items is called the BOM Quantity. You can find it at the top of the Custom Properties window.

SolidWorks bill of materials quantity
Custom properties window

As default it is set to none. You can’t fill in a number here, you first need to add a custom property, then select that custom property to be the BOM quantity.

We’re also adding a custom property called Unit. We will add this to the BOM to clarify the amount of lubricant. The custom properties window then looks something like this:

SolidWorks bill of materials quantity
Including the BOM quantity and units

The quantity in the BOM will have updated already. In addition, you need to add a column (right click > Insert > Column right) and select the custom property Unit. This will give you the following bill of materials:

SolidWorks bill of materials quantity
Including the quantity and units in the BOM
Changing the bill of materials quantity via the API

Now suppose you want to set or change these values from a macro or add-in that you wrote so the task can be automated. How would you handle that? I recently joined a topic on the SolidWorks forums to get this working  and this question inspired me to write this post.

The resulting code has the following steps:

  1. Set the SolidWorks application, the part and an extension
  2. Set up a Custom Property Manager also
  3. Next add a custom property with the amount using the custom property manager so we can access the model’s custom properties
  4. Now add the custom property UNIT_OF_MEASURE and tell it to look at the Amount property
  5. Add the Unit property

The UNIT_OF_MEASURE is the protected custom property that sets the BOM quantity variable. Somehow you still have to add it though, just setting it won’t work the first time.

Final words

There it is. Another feature that you probably didn’t even know existed. Now you know how to add those weird exceptions to your bill of materials properly.

You probably have knowledge of a feature that everybody should know about as well. Please let me know in the comments, because I want everyone to learn one more thing today.