2 Replies Latest reply on Jun 23, 2014 4:20 AM by Yong Ning

    SwView.GetBomTable → Nothing

    Yong Ning

      0.jpg

       

       

      Sub ll1()

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

          Set SwApp = GetObject(, "SldWorks.Application")

          Set SwModel = SwApp.ActiveDoc

          Set SwDraw = SwModel

        Dim SwView As View, SwBomTab As BomTable

          Set SwView = SwDraw.GetFirstView

          Set SwView = SwView.GetNextView

          Set SwBomTab = SwView.GetBomTable

          Stop

      End Sub

       

      Help me.

      How to use the SwView.GetBomTable statement

       

      SolidWorks Forums: Change in Bend Deduction property not committing.

      https://forum.solidworks.com/message/378049#378049

        • Re: SwView.GetBomTable → Nothing
          Jim Sculley

          The GetBomTable method will only return results if you are using Excel based BOMs.  If you are using normal SolidWorks BOMs, this is not the correct method to use.  You can use IView::GetTableAnnotations or you can use the FeatureManager to walk through the feature tree looking for BomFeature objects.

           

          Jim S.

            • Re: SwView.GetBomTable → Nothing
              Yong Ning

              Thanks your tips

               

              Private Sub Getann()

                Dim SwModel As ModelDoc2

                  Set SwModel = Application.SldWorks.ActiveDoc

                Dim SwSelMgr As SelectionMgr, SwBomFeat As BomFeature

                  Set SwSelMgr = SwModel.SelectionManager

                  Set SwBomFeat = SwSelMgr.GetSelectedObject5(1)

                  'Debug.Print SwBomFeat.GetFeature.Name

                Dim SwTabAnn As TableAnnotation, ss

                  ss = SwBomFeat.GetTableAnnotations

                  Set SwTabAnn = ss(0)

                  Debug.Print SwTabAnn.Title

                  With SwTabAnn

                     For ii = 0 To .RowCount

                        For jj = 0 To .ColumnCount

                           Debug.Print .Text(ii, jj),

                        Next jj

                        Debug.Print

                     Next ii

                  End With

              End Sub

              *********************

               

              Private Sub Main2()

                  Dim Wk As Workbook, Sht As Worksheet, Rng As Range

                    Set Wk = connectXls

                    Set Sht = Wk.Sheets(1)

                    nn = Sht.Range("A65536").End(3).Row

                    Set Rng = Sht.Range("A3:A" & nn)

                  Dim swApp As SldWorks.SldWorks, SwModel As SldWorks.ModelDoc2

                  Dim vConfigNameArr, vConfigName

                  Dim Str, ii, PrtAsm, Conf

                 

                  PrtAsm = "Ellipse.SldPrt"

                  PrtAsm1 = "Shell.SldPrt"

                  PrtAsm2 = "支座BI-F-四六筋.sldasm"

                 

                  Set swApp = Application.SldWorks

                  Set SwModel = swApp.ActiveDoc

                  vConfigNameArr = SwModel.GetConfigurationNames

                  ''

                  For ii = 0 To UBound(vConfigNameArr)

                      vConfigName = vConfigNameArr(ii)

                      With SwModel

                         .ShowConfiguration vConfigName

                         Str = "SW-Mass@@" & vConfigName & "@" & SwModel.GetTitle

                         .AddCustomInfo3 vConfigName, "质量", 30, "12"

                         .CustomInfo2(vConfigName, "质量") = """" & Str & """"

                       

                         Conf = Rng(ii + 1, 1)

                         ''

                         Str = "SW-Mass@@" & Rng(ii + 1, 2) & "@" & PrtAsm

                         .AddCustomInfo3 Conf, "封头质量", 30, "12"

                         .CustomInfo2(Conf, "封头质量") = """" & Str & """"

                         ''

                         Str = "SW-Mass@@" & Rng(ii + 1, 4) & "@" & PrtAsm1

                         .AddCustomInfo3 Conf, "筒体质量", 30, "12"

                         .CustomInfo2(Conf, "筒体质量") = """" & Str & """"

                         ''

                         Str = "SW-Mass@@" & Rng(ii + 1, 5) & "@" & PrtAsm2

                         .AddCustomInfo3 Conf, "支座质量", 30, "12"

                         .CustomInfo2(Conf, "支座质量") = """" & Str & """"

                        

                        

                      End With

                  Next ii

              End Sub