How to set a custom BOM quantity + units in SOLIDWORKS

You can make 5 units of a part show up in a BOM. Even when you just add one.

But this feature is just a bit hidden in SOLIDWORKS.

I’ll show you how you can do it manually and via the API.

How to add 5ml of lubricant to an assembly

Suppose you have this assembly model of a planetary gearbox. We are going to add some lube to this assembly.

Planetary fearbox (I like that typo, so I’ll leave it in)

This is the bill of materials in the drawing:

Add an empty part for lubricant

The first step to adding lubricant to this assembly is 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).

As a result, the BOM now looks slightly more complete:

custom BOM quantity liquid

Setting the BOM Quantity

The feature that SOLIDWORKS built for the quantity is the BOM Quantity. You can find it at the top of the Custom Properties window.

This is where you select an existing custom property that acts as the quantity. However, the default is none.

Secretly, this is a custom property as well.

bill of materials quantity solidworks

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.

I decided to add a custom property called Amount and give it a value of five. The type needs to be a number.

bom quantity solidworks

Five lubricants, please!

Now what? Five grams, five hectoliters, five gallons?

There is no built-in functionality for this. So we’re adding a custom property called Unit.

bill of materials quantity and units solidworks

The quantity in the BOM usually updates automatically.

If you want to show the units, you need to add a column (right-click > Insert > Column right > Custom Property > Unit. This results in the following bill of materials:

Bill of materials including the quantity and unit

This is how weldments set the length as the quantity

Weldments use this trick to set the body length as the quantity in a bill of materials.

Weldment parts also have a value for Unit Of Measure. It seems to be set to the part unit when the part was created.

I have not been able to manually set this value in other parts or change it in weldment parts.

weldment quantity length UnitOfMeasure

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. But how would you handle that?

I once joined a topic on the SOLIDWORKS forums to get this working and this question originally inspired me to write this post.

The resulting code has the following steps:

  1. We set the SOLIDWORKS application, the model and the model doc extension
  2. Then we set up a Custom Property Manager
  3. Add a custom property called Amount with a value of 5.
  4. Add a custom property called UNIT_OF_MEASURE with a value of  “Amount”
  5. Add the Unit property

The UNIT_OF_MEASURE is the protected custom property that sets the BOM quantity variable. It does not exist in new parts, so you have to add it first.

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.

Don't miss the next post. Get a free add-in.

Subscribe to our newsletter and get our TimeSavers add-in for free.