AnsweredAssumed Answered

InsertBomTable BOM Configurations Not Matching Drawing View

Question asked by Michael Carmenaty on Aug 31, 2018
Latest reply on Sep 5, 2018 by 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;

          

           //Console.WriteLine(swTable.Title);

          

            swModel.ClearSelection2(true);

 

 

            // 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

            swFeatMgr.UpdateFeatureTree();          

        }

    }     

}

Outcomes