1 Reply Latest reply on May 21, 2015 5:26 AM by Yong Ning

    How to get Item No. in BomTable?

    Yong Ning

      0.jpg

       

       

       

      Private Sub del20150115()

         Dim SwApp As SldWorks.SldWorks, swModel As ModelDoc2, SwDraw As DrawingDoc

            Set SwApp = Application.SldWorks

            Set swModel = SwApp.ActiveDoc

            swModel.ClearSelection2 True

            Set SwDraw = swModel

         Dim SwFeat As Feature, SwBomFeat As BomFeature

            Set SwFeat = SwDraw.FeatureByName("Bill Of Materials1")

            SwFeat.Select True

            Set SwBomFeat = SwFeat.GetSpecificFeature2

            'Debug.Print SwBomFeat.GetFeature.Name

         Dim SwBomTabAnn As BomTableAnnotation, SwComp As Component2

            Set SwBomTabAnn = SwBomFeat.GetTableAnnotations(0)

            With SwBomTabAnn

               Debug.Print .BomFeature.GetFeature.Name

               Arr = .GetAllCustomProperties

               Set SwComp = .GetComponents(1)(0)

               Debug.Print SwComp.GetModelDoc.GetTitle

               Set SwComp = .GetComponents(2)(0)

               Debug.Print SwComp.GetModelDoc.GetTitle

               Arr = .GetAllCustomProperties  

               arr1 = .GetColumnCustomProperty(1) 

               arr2 = .GetColumnCustomProperty(0)        

              

               For kk = 0 To 10

                  Debug.Print kk, .GetColumnUseTitleAsPartNumber(kk),

                  Debug.Print .GetColumnCustomProperty(kk)

               Next kk

               Stop

            End With

       

       

      End Sub

        • Re: How to get Item No. in BomTable?
          Yong Ning

          Private Sub ll()

             Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                Set SwApp = Application.SldWorks

                Set SwModel = SwApp.ActiveDoc

             Dim SwSelMgr As SelectionMgr, Vv, ii, jj, Vv1, Vv2

                Set SwSelMgr = SwModel.SelectionManager

             Dim SwBomTabAnn As BomTableAnnotation

                Set SwBomTabAnn = SwSelMgr.GetSelectedObject5(1)

                With SwBomTabAnn

                   Vv = .GetAllCustomProperties

                   .SetColumnCustomProperty 3, Vv(2)

                   .SetColumnCustomProperty 2, Vv(2)      

                End With

          End Sub

           

          ''

          Private Sub ll()

             Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                Set SwApp = Application.SldWorks

                Set SwModel = SwApp.ActiveDoc

             Dim SwSelMgr As SelectionMgr, Vv, ii, jj, Vv1, Vv2

                Set SwSelMgr = SwModel.SelectionManager

             Dim SwBomTabAnn As BomTableAnnotation

                Set SwBomTabAnn = SwSelMgr.GetSelectedObject5(1)

             Dim Arr, SwTabAnn As TableAnnotation

                 Arr = Array("序号", "标准号", "名称", "数量", "材料", "质量", "", "下料尺寸", "下料质量", "", "")

             Dim cArr

                 cArr = Array("序号", "标准号", "名    称", "数量", "材料", "模型质量", "小计①", "下料尺寸", "下料质量", "小计②", "②-①")

             Dim wArr

                 wArr = Array(8, 20, 50, 8, 25, 15, 15, 40, 15, 15, 15, 15)

             Dim Str: Str = "Arr=array("

             Dim SwBomFeat As BomFeature, Ww As Double

                ''

                With SwBomTabAnn

                   For jj = 0 To 10

                      Str = Str & Chr(34) & .GetColumnCustomProperty(jj) & Chr(34) & ","

                      Debug.Print jj, .GetColumnCustomProperty(jj)

                   Next jj

                   Str = Left(Str, Len(Str) - 1) & ")"

                   Debug.Print Str

                   Vv = .GetAllCustomProperties

                   '''

                   For jj = 0 To UBound(Arr)

                      .SetColumnCustomProperty jj, Arr(jj)          

                   Next jj

                   Set SwBomFeat = .BomFeature

                   ''

                End With

                Set SwTabAnn = SwBomFeat.GetTableAnnotations(0)

                Str = "wArr=array("

                With SwTabAnn

                   For ii = 0 To .ColumnCount - 1

                      'Debug.Print ii, .GetColumnTitle(ii),

                      Debug.Print ii, .GetColumnWidth(ii), .GetColumnTitle(ii)

                      Ww = Ww + wArr(ii)

                      .SetColumnWidth ii, wArr(ii) / 1000, 0

                      .SetColumnTitle ii, cArr(ii)

                      Str = Str & .GetColumnWidth(ii) * 1000 & ","

                      'Stop

                   Next ii

                   Str = Left(Str, Len(Str) - 1) & ")"

                   Debug.Print Str, Ww

                End With

          End Sub