2 Replies Latest reply on Dec 29, 2014 9:44 AM by Yong Ning

    How to get BOM to  link view with API?

    Yong Ning



      Private Sub ll()

        Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

        Dim SwDraw As DrawingDoc, SwSelMgr As SelectionMgr

        Dim SwFeat As Feature, BomFeat As BomFeature

          Set SwApp = Application.SldWorks

          Set SwModel = SwApp.ActiveDoc

          Debug.Print SwModel.GetTitle

          Set SwSelMgr = SwModel.SelectionManager


          Set BomFeat = SwSelMgr.GetSelectedObject6(1, -1)

        Dim SwTabAnn As TableAnnotation, SwAnn As Annotation

          Set SwTabAnn = BomFeat.GetTableAnnotations(0)

          Set SwAnn = SwTabAnn.GetAnnotation   

      End Sub



      Swann.owner  → get sheet name

      but don't get view name?




      SolidWorks Forums: Bill of Material and Balloons


      SolidWorks Forums: How to get bill of materials to link to assembly/drawing view configurations?


        • Re: How to get BOM to  link view with API?
          Simon Turner

          Loop through the Views in the sheet and then use IView.GetKeepLinkedToBOMName

            • Re: How to get BOM to  link view with API?
              Yong Ning

              Private Sub llss()

                Dim Xls As Excel.Application, Rng As Range

                  Set Xls = GetObject(, "Excel.Application")

                  Set Rng = Xls.Selection


                Dim BomName, BomPath, ii, Xx, Yy

                  Xx = 420 - 5: Yy = 5

                  Xx = Xx / 1000: Yy = Yy / 1000

                  BomPath = "E:\MyWorkSummary\BESmodel\MatDot\"

                  BomName = BomPath & "MeBOM.sldbomtbt"

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

                  Set SwApp = Application.SldWorks

                  Set swModel = SwApp.ActiveDoc

                  Set SwDraw = swModel


                  RngToSheetViewBom SwDraw, Rng, BomName, Xx, Yy


              End Sub



              Function RngToSheetViewBom(SwDraw As DrawingDoc, Rng As Range, BomName, Xx, Yy)

                Dim SwView As View, vSheet, SwSheet As Sheet

                Dim SwBomAnn As BomTableAnnotation, SwBomFeat As BomFeature, SwFeat As Feature

                Dim Visible, Names, ii, jj

                  vSheet = SwDraw.GetSheetNames

                  For ii = 1 To Rng.Rows.Count

                     SwDraw.ActivateSheet vSheet(ii - 1)

                     Set SwSheet = SwDraw.GetCurrentSheet

                     SwSheet.SetName Rng(ii, 1)

                     SwSheet.SetSheetFormatName Rng(ii, 1) & "图纸"


                     Set SwView = SwDraw.GetFirstView

                     Set SwView = SwView.GetNextView

                     SwView.SetName2 Rng(ii, 2)


                     Set SwBomAnn = SwView.InsertBomTable2(False, Xx, Yy, 4, 2, "", BomName)


                     Set SwBomFeat = SwBomAnn.BomFeature

                     Set SwFeat = SwBomFeat.GetFeature

                     SwFeat.Name = Rng(ii, 4)


                     SwDraw.ForceRebuild3 True


                     Names = SwBomFeat.GetConfigurations(False, Visible)

                     For jj = 0 To UBound(Names)

                        If Names(jj) <> Rng(ii, 4) Then

                          Names(jj) = ""

                        End If

                     Next jj


                     SwBomFeat.SetConfigurations True, Visible, Names


                  Next ii    '

              End Function