ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
CSClaudia Streblau23/04/2020

I want to be able to change the item numbers of specific parts using a macro. I have been able to record this macro. So before running it, I neet to select the BOM on the drawing sheet first. And it works for the first item number change. But as soon as I run this sub a second time inside the main code, it won't work because the selection of the BOM is lost. How do I keep the BOM selected? Or is there another way?

Thank you in advance!

This was recorded by selecting the BOM and then double-clicking the respective item number I wanted to change and entering a random number. Then I modified it to have a PublicSub.

Public Sub ChangePOS(Row As Integer, NEW_POS As Integer)


    Dim swApp               As SldWorks.SldWorks
    Dim swModel             As SldWorks.ModelDoc2
    Dim BOM                 As Object
   
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    
    Set BOM = swModel.SelectionManager.GetSelectedObject6(1, -1)
   

    'changes the existing item number (1st value = row, 2nd value = column)
    BOM.Text(Row, 0) = NEW_POS

End Sub