1 Reply Latest reply on Oct 4, 2017 9:40 AM by Deepak Gupta

    HOW TO LINK BOM PART NUMBER TO DETAIL DRAWING

    Sai Pistule

      HI EVERYBODY

       

      I WANT UPDATE MY BOM QTY. IN DETAIL DRAWING AUTOMATICALLY. I GET MACRO WHICH WAS DEVLOPED BY WARD DEVIS BUT I NOT GETTING HOW USE THIS MACRO. .

       

       

      PLEASE PROVIDE DETAIL PROCEDURE FOR IT

       

       

      MACRO CODING AS FOLLOWS

       

      Sub UpdateQtys()

      Dim swApp as SldWorks.SldWorks 'added this line

      Dim Assembly as ModelDoc2 'added this line

      Dim myAsy As AssemblyDoc

      Dim myCmps

      Dim Cfg As String

      Dim CmpDoc As ModelDoc2

      Dim i As Long

      Dim j As Long

      Dim cCnt As Long

      Dim NoUp As Long

      Dim myCmp As Component2

      Dim tCmp As Component2

      dim tm as double

      tm = timer

      Set swApp = Application.Sldworks 'added this line

      Set Assembly = swApp.ActiveDoc 'added this line

      Set myAsy = Assembly

      If Assembly.ConfigurationManager.ActiveConfiguration.Name <> Assembly.CustomInfo2("", "Cfg4Qty") Then

      Assembly.Extension.ShowSmartMessage "Qtys not updated due to config", 1000, True, True

      Exit Sub

      End If

      NoUp = 0

      myCmps = myAsy.GetComponents(False)

      For i = 0 To UBound(myCmps)

      Set myCmp = myCmps(i)

      If (myCmp.GetSuppression = 3) Or (myCmp.GetSuppression = 2) Then

      cCnt = 0

      Set CmpDoc = myCmp.GetModelDoc

      Cfg = myCmp.ReferencedConfiguration

      For j = 0 To i 'originally was "For j = 0 To UBound(myCmps)", I just changed it to make it faster, and it works (Riccardo)

      Set tCmp = myCmps(j)

      If tCmp.GetSuppression <> 0 Then

      If tCmp.GetModelDoc2 Is CmpDoc Then

      If tCmp.ReferencedConfiguration = Cfg Then

      cCnt = cCnt + 1

      End If

      End If

      End If

      Next j

      CmpDoc.AddCustomInfo3 Cfg, "AutoQty", 30, ""

      CmpDoc.AddCustomInfo3 Cfg, "QtyIn", 30, ""

      CmpDoc.CustomInfo2(Cfg, "AutoQty") = cCnt

      CmpDoc.CustomInfo2(Cfg, "QtyIn") = Assembly.GetTitle & " Cfg " & Assembly.ConfigurationManager.ActiveConfiguration.Name

      Else

      NoUp = NoUp + 1

      End If

      Next i

      Assembly.Extension.ShowSmartMessage NoUp & " Parts not updated due to lightweight (" & timer - tm & "s)", 10000, True, True

      end sub