8 Replies Latest reply on Sep 5, 2018 7:24 PM by Michael Carmenaty

    InsertBomTable BOM Configurations Not Matching Drawing View

    Michael Carmenaty

      Hi Everyone,


      I need some help. Our company has been using Excel BOMs. But trying to get away from that. They are to slow & cause the drawing file to perform really slow & crash.

      So figure I use SolidWorks BOMs. But a bit custom to match what we had using Excel Boms. So far Im about 90% done.


      The BOM is inserted with the Configurations Part number as the Title Matching the Drawing View Configuration.

      But for some reason. The BOM itself configuration dose not match.

      It defaults to the first configuration.


      The Reference Configurations is used to get the configuration & fill in the Tilte


      Configuration not matching to Reference View

      I must be missing something or there might be a bug.


      Thank You!!


      Here is the C# script


      using System;

      using System.Collections.Generic;

      using System.Linq;

      using System.Text;

      using System.Threading.Tasks;

      using SolidWorks.Interop.sldworks;

      using SolidWorks.Interop.swconst;

      using System.Diagnostics;





      namespace InsertBOM


          partial class Program


              public interface IConfiguration







              static void Main(string[] args)



                  ModelDoc2 swModel = default(ModelDoc2);

                  SelectionMgr swSelMgr = default(SelectionMgr);

                  FeatureManager swFeatMgr = default(FeatureManager);

                  View swView = default(View);

                  BomTableAnnotation swBomAnn = default(BomTableAnnotation);

                  BomFeature swBomFeat = default(BomFeature);

                  TableAnnotation swTable = default(TableAnnotation);


                  int AnchorType = 0;

                  int BomType = 0;     

                  string Configuration;

                  string TableTemplate;


                  object Names = null;

                  object Visible = null;

                  bool boolstatus = false;        



                  SldWorks swApp = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");


                  swModel = (ModelDoc2)swApp.ActiveDoc;

                  swSelMgr = (SelectionMgr)swModel.SelectionManager;

                  swFeatMgr = (FeatureManager)swModel.FeatureManager;



                  // Get selected drawing view//



                  swView = (View)swSelMgr.GetSelectedObject6(1, 0);


                  // Insert BOM table//



                  AnchorType = (int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_BottomRight;

                  BomType = (int)swBomType_e.swBomType_TopLevelOnly;


                  Configuration = swView.ReferencedConfiguration;

                  //Configuration = "286820-614";

                  TableTemplate = @"C:\Users\mcarmenaty\Desktop\NEW7 GOLD.sldbomtbt";        


                  swBomAnn = swView.InsertBomTable2(false, 0.0, 0.0, AnchorType, BomType, Configuration, TableTemplate);



                  swTable = (TableAnnotation)swBomAnn;

                  swTable.Title = "BOM FOR " + Configuration;







                  // Because BOM type is swBomType_TopLevelOnly,//

                  // then work with BomFeature to get and set configurations//

                    swBomFeat = swBomAnn.BomFeature;

                    Names = swBomFeat.GetConfigurations(false, ref Visible);          

                   Visible = true;     

                   boolstatus = swBomFeat.SetConfigurations(false, Visible, Names);



                  // Update FeatureManager design tree





        • Re: InsertBomTable BOM Configurations Not Matching Drawing View
          Alex Burnett

          I just put your code on my PC and ran it on my test print. It looks like it's set up right and it's passing the correct configuration to the Insert function. For whatever reason, this isn't updating the referenced configuration of your BOM table.


          I even tried to adjust the configuration after the fact by accessing the annotation table similar to the way you did at the end of your code and couldn't get it working. I believe your syntax for the get/set of configurations was incorrect but I created the correct variables and got a True return from the SetConfigurations and the table still did not display properly.


          I'm not sure where to go from here.


          Code section that I updated:

                  // Because BOM type is swBomType_TopLevelOnly,//
                  // then work with BomFeature to get and set configurations//
                  swBomFeat = swBomAnn.BomFeature;
                  Names = swBomFeat.GetConfigurations(false, ref Visible);
                  string[] sNames = (string[])Names;
                  Boolean[] bools = (bool[])Visible;
                  for (int i = 0; i< sNames.Length; i++)
                      Console.WriteLine($"CFG: {sNames[i]}\tVisible: {bools[i]}");
                      //Restructure the visibility array to set the Configuration variable to true, all others to false
                      bools[i] = sNames[i]==Configuration;
                  //Visible = true;
                  boolstatus = swBomFeat.SetConfigurations(false, bools, sNames);
                  Console.WriteLine($"Set Configs Worked?:  {boolstatus}");
                  // Update FeatureManager design tree
            • Re: InsertBomTable BOM Configurations Not Matching Drawing View
              Michael Carmenaty

              Hi Alex,


              Thank You for the reply.


              I did some more trouble shooting over the weekend. I found out that it is grabbing the assembly configurations not the drawing Reference Configuration.

              If I have the assembly open & what ever Configurations is active at that moment in the assembly that is the configurations the BOM is going to use.

              Another thing I notice is when I open the Drawing & run the code it works. But when I change the Drawing view Configuration run code again. The BOM defaults to the configurations that was active when first opened the drawing file.


              Could it be GetSelectedObject6 is getting the configuration of the Assembly & assigning it BOM?


              I ran normal operation of inserting a BOM works fine, Configuration Matches BOM

              I recorded Inserting BOM to see what VBA is using to make BOM. Its using ActiveDrawingView.


              I tried to replicate this code but couldn't get it to work.



              Sub main()



              Set swApp = _




              Set Part = swApp.ActiveDoc

              Part.ClearSelection2 True

              Dim swActiveView As Object

              Set swActiveView = Part.ActiveDrawingView

              Dim swBOMTable As Object

              Set swBOMTable = swActiveView.InsertBomTable2(False, -0.219504212611934, 8.35667306328371E-02, swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft, swBomType_e.swBomType_TopLevelOnly, "286820-614", "S:\Common\bom-standard.sldbomtbt")

              boolstatus = Part.EditRebuild3()

              boolstatus = Part.ActivateSheet("Sheet1")

              End Sub


              Thank You

            • Re: InsertBomTable BOM Configurations Not Matching Drawing View
              Nilesh Patel

              Hi Michael,


              You can try following:


              1. When you insert the BOM table, do not specify the configuration name and instead specify empty string.

              2. Instead of getting configuration name from IBomFeature::GetConfigurations, use IView::ReferencedConfiguration.


              Have a look at the attached macro. It works fine for me. You can remove table sorting and formatting. Macro uses standard SolidWorks BOM template.


              Hope this helps.