0 Replies Latest reply on Apr 24, 2015 2:57 PM by Bruce Perry

    Activating a view getting configuration and insert single config BOM

    Bruce Perry

      Here is the code for inserting a BOM of a view in a drawing.

      I haven't clean it up for redundant information that I was using to build it but it works.

       

      Option Explicit

       

      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swSelMgr As SldWorks.SelectionMgr

      Dim swFeatMgr As SldWorks.FeatureManager

      Dim swView As SldWorks.view

      Dim swBomAnn As BomTableAnnotation

      Dim swBomFeat As SldWorks.BomFeature

      Dim anchorType As Long

      Dim bomType As Long

      Dim configuration As String

      Dim tableTemplate As String

      Dim Names As Variant

      Dim visible As Variant

      Dim boolStatus As Boolean

      Dim swDraw As SldWorks.DrawingDoc

      Dim swSheet As SldWorks.Sheet

       

      Sub AddBOM()

       

      Dim swConfig As SldWorks.configuration

      Dim MyConfig As String

      Dim MyConfiguration As Object

      Dim selMgr As SldWorks.SelectionMgr

      Dim view As SldWorks.view

         

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

      Set swSelMgr = swModel.SelectionManager

      Set swFeatMgr = swModel.FeatureManager

      Set swDraw = swModel

      Set swSheet = swDraw.GetCurrentSheet

      Set selMgr = swModel.SelectionManager 'Select View

       

      Set swModel = swApp.ActiveDoc

       

          boolStatus = swModel.EditRebuild3()

          boolStatus = swModel.ActivateSheet("Sheet1")

          boolStatus = swModel.ActivateView("Drawing View4")

      Set swView = swModel.ActiveDrawingView

      'I have four view at the standard view names. I want to create the BOM based on "Drawing View 4"

      'I want the BOM to be from the configuration (Drawing View 4), so you have to make it the active

      'or selected view

      'Insert BOM Table

      anchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_BottomRight

      bomType = SwConst.swBomType_e.swBomType_PartsOnly 'SwConst.swBomType_e.swBomType_TopLevelOnly

       

      swModel.ClearSelection2 True

       

      configuration = swView.ReferencedConfiguration

       

      tableTemplate = "C:Some location"

       

      Set swBomAnn = swView.InsertBomTable2(False, 0.8501, 0.07, anchorType, bomType, configuration, tableTemplate)

      'Inserted in the lower right over the Title Block

      Set swBomFeat = swBomAnn.BomFeature

      Names = swBomFeat.GetConfigurations(False, visible)

      visible(0) = True

      boolStatus = swBomFeat.SetConfigurations(True, visible, Names)

       

      swFeatMgr.UpdateFeatureTree

      End Sub