Set BOM Quantity (Unit Of Measure) property using SOLIDWORKS API

Edit ArticleEdit Article
Comments

This example demonstrates how to modify the BOM quantity field in the properties dialog using SOLIDWORKS API.

Option to specify the property linked to Unit Of Measure
Option to specify the property linked to Unit Of Measure

This option allows overwriting the quantity value of the component in the BOM table

Bill Of Materials table displaying the altered quantity of the components
Bill Of Materials table displaying the altered quantity of the components

In order to change this property it is required to set the hidden UNIT_OF_MEASURE custom property via ICustomPropertyManager SOLIDWORKS API interface.

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Const BOM_QTY_PRP_NAME As String = "UNIT_OF_MEASURE"
Const QTY_PRP_NAME As String = "Qty"

Sub main()

    Set swApp = Application.SldWorks
    
    Set swModel = swApp.ActiveDoc
    
    If Not swModel Is Nothing Then
    
        Dim swCustPrpMgr As SldWorks.CustomPropertyManager
        
        Set swCustPrpMgr = swModel.Extension.CustomPropertyManager("")
            
        Dim bomQtyPrp As String
        swCustPrpMgr.Get3 BOM_QTY_PRP_NAME, False, "", bomQtyPrp
        
        Debug.Print bomQtyPrp
        
        swCustPrpMgr.Add2 BOM_QTY_PRP_NAME, swCustomInfoType_e.swCustomInfoText, QTY_PRP_NAME
        swCustPrpMgr.Set2 BOM_QTY_PRP_NAME, QTY_PRP_NAME
    
    Else
        
        MsgBox "Please open model"
        
    End If
    
End Sub

Notifications

All articles and code at CodeStack are now open-source and hosted on GitHub. If you want to contribute by modifying existing articles and code snippets, submitting new ones, reporting errors and bugs etc. please follow this blog post for more information. We appreciate any contribution.


Product of Xarial Product of Xarial