7 Replies Latest reply on Jun 27, 2018 3:15 PM by Chris Manger

    Set configuration when inserting BOM into drawing

    Chris Manger

      I am using the VBA example in the help file (LINK).   The API help states when using TopLevelOnly, that the BomFeature property must be used.   I added some some to get the configuration used in the selected view.   How do I set to BOM to this configuration?    If I use the code from the help file, the configuration using in the view does not get set in the BOM table properties.  For example, if the selected view is referencing a configuration called "XYZ", how do I set the BOM to configuration XYZ?

       

      ' Because BOM type is swBomType_TopLevelOnly,
        ' then work with BomFeature to get and set configurations
        Set swBomFeat = swBomAnn.BomFeature
        Names = swBomFeat.GetConfigurations(False, Visible)
        Visible(0) = True
        boolstatus = swBomFeat.SetConfigurations(True, Visible, Names)
      

       

      Message was edited by: Chris M.

        • Re: Set configuration when inserting BOM into drawing
          Amen Allah Jlili

          Take a look at this:

           

          SOLIDWORKS API Help
          SetConfigurations Method (IBomFeature)

          Although this method works on all styles of BOM tables (top-level only, parts-only, indented subassemblies), it is only necessary for top-level only style tables. For the other style tables, where only a single configuration is shown at a time, using IBomFeature::Configuration is simpler and more efficient.

          NOTE: If the Restrict top-level only BOMs to one configuration option on the Document Properties > Tables > Bill of Materials dialog or IModelDocExtension::GetUserPreferenceToggle(swUserPreferenceToggle_e.swOneConfigOnlyTopLevelBom) returns true, then only the active or default configuration of the drawing view is inserted in the BOM.

          The view associated with this BOM can contain a model with multiple configurations. For a top-level only style BOM table, there can be several Quantity columns, each showing the results for a different configuration. For the other styles of BOM tables, only a particular configuration can be shown in the table, and that configuration can be changed. To determine the BOM table style, use the IBomFeature::TableType property.

           

           

             

          If OnlyVisible is...

          Then Names contains the names of...

          And Visible...

          True

          Only the configurations currently shown in the BOM table. 

          For a top-level only style BOM table, this could be any number of configurations. For the other styles of BOM tables, it is one configuration name.

          Can be passed in as null or nothing.

          If it is passed in as non-null or non-nothing, then the array contains true for all items.

          False

          All configurations available.

          Contains Booleans that correspond to each item in Names indicating if that particular configuration is shown in the BOM table or not.

           

           

          To get the number of configurations, use IBomFeature::GetConfigurationCount.

          • Re: Set configuration when inserting BOM into drawing
            Raghvendra Bhargava

            Try this:

            Dim swApp As SldWorks.SldWorks

            Dim Part As ModelDoc2

            Dim boolstatus As Boolean

            Dim longstatus As Long, longwarnings As Long

             

            Option Explicit

            Sub main()

            Set swApp = Application.SldWorks

             

            Set Part = swApp.ActiveDoc

            Dim swdrw As DrawingDoc

            Set swdrw = Part

             

            boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.52514, 0.55463, 0, False, 0, Nothing, 0)'Change Drawing view name as per your view name.

             

            Dim swview As View

            Set swview = Part.SelectionManager.GetSelectedObject6(1, -1)

             

            Dim ViewCongNme As String

            ViewCongNme = swview.ReferencedConfiguration

             

            boolstatus = Part.Extension.SelectByID2("Bill of Materials1", "BOMFEATURE", 0, 0, 0, False, 0, Nothing, 0)'Chnage BOM name as per your selection

             

            Dim BOMFeat As BomFeature

            Set BOMFeat = Part.SelectionManager.GetSelectedObject6(1, -1)

             

            Dim confNme(0) As String

            confNme(0) = ViewCongNme 'We need can also add other configuration like confNme(1)="Some other configuration"

             

            Dim NewCOnfNme As Variant

            NewCOnfNme = confNme

             

            boolstatus = BOMFeat.SetConfigurations(True, Nothing, NewCOnfNme)

             

            Part.ForceRebuild3 True

            End Sub