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.
Suppose you have this assembly model of a planetary gearbox. We are going to add some lube to this assembly.
This is the bill of materials in the drawing:
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:
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.
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.
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.
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:
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.
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:
Dim swApp As ISldWorks
Dim swModel As ModelDoc2
Dim swModelDocExt As ModelDocExtension
Dim propMan As CustomPropertyManager
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set propMan = swModelDocExt.CustomPropertyManager("")
propMan.Add3 "Amount", swCustomInfoNumber, 5, 0
propMan.Add3 "UNIT_OF_MEASURE", swCustomInfoText, "Amount", 0
propMan.Add3 "Unit", swCustomInfoText, "mL", 0
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.
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.