30 Replies Latest reply on Aug 3, 2017 2:09 PM by Deepak Gupta

    First Macro - Insert BOM API

    David Dickens

      Hi Everyone!!!!

      I thank you all in advance for all your comments and help.

      I started here where I was inquiring in another's thread about adding blank rows to a BOM (to be filled in with shop supply items later.  Long and short of this is that we heavily use the routing tool here at work in which we use the "identify spools" feature that consumes the model and would have required me to insert quite a few of the virtual dummy parts etc etc etc.  I just didn't find a feasible way to make actual modeling work without more work than it should be which brought me back to the BOM and just wanting to add these two rows of parts that go into everything we do.  Mr Deepak Gupta offered up some suggestions, one of which was a macro for parts but since I had determined the modeling route would have taken more steps than necessary I decided to explore using a macro to just insert and manipulate the BOM to add my two rows Mr. Gupta also said should work for me. And here I am.  I read up some on macros and saw some others trying to do similar things and also saw some of the trouble they were having so I am going to start small and cross the first bridge of just being able to get the macro to insert my BOM.  I found another thread that someone had some code inserting a BOM that worked so I copied it since I could not get my recorded macro to work.  My recorded macro did not have a quarter of the lines this other one did.  So I copied it, tweaked it a little and it inserts a BOM.  Hurray!!!   But......... it doesn't insert my BOM template and not at the anchor point.  It appears to insert a generic three column template.  Not sure if the line pointing to the server location for the template isn't enough and its defaulting or what.  So that is my first hurdle.  To get it to insert my BOM, at the anchor point.  Any help you all can offer as to what I need to fix in order to get my template to insert will be greatly appreciated!!!            CODE BELOW FOR SCREWTENIZING

       

       

      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 main()

      Set swApp = Application.SldWorks
      Set swModel = swApp.ActiveDoc
      Set swSelMgr = swModel.SelectionManager
      Set swFeatMgr = swModel.FeatureManager
      Set swDraw = swModel
      Set swSheet = swDraw.GetCurrentSheet

      'Select View
      swModel.ClearSelection2 True
      Set swView = swDraw.GetCurrentSheet.GetViews()(0)

       

       

      'Insert BOM Table
      tableTemplate = "" ' "\P:\Engineering\Templates\CryoWorks_ASM_BOM REV C.sldbomtbt"
      anchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight
      bomType = SwConst.swBomType_e.swBomType_Indented

      swModel.ClearSelection2 True

      configuration = "" '"Default"

       

      Set swBomAnn = swView.InsertBomTable2(False, 0, 0, anchorType, bomType, configuration, tableTemplate)
      Set swBomFeat = swBomAnn.BomFeature
      Names = swBomFeat.GetConfigurations(False, visible)
      visible(0) = True
      boolStatus = swBomFeat.SetConfigurations(True, visible, Names)

       

      swFeatMgr.UpdateFeatureTree

       

       

      End Sub

        • Re: First Macro - Insert BOM API
          David Dickens

          Woo Hoo!!!!  This Forum rocks!!!!  was able to find the coding issues in another thread (here) thanks to Peter Brinkhuis along with how to fix the flat numbering and detail cutlist coding.  Now on to part 2 of my macro; actually adding in the two rows I need.

            • Re: First Macro - Insert BOM API
              Christian Chu

              I strongly recommend you to visit Keith Rice site which include many samples and tutorials

              • Re: First Macro - Insert BOM API
                Peter Brinkhuis

                Thanks for the mention Maybe I can be of some assistance here as well.

                 

                You are using this line:

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

                 

                According to the help file, there are two new versions of this command, so I advise you to use InsertBomTable4 (IView). By setting the first parameter to false, you are using the point 0,0 as an anchor point. If you have a BOM anchor in your drawing template, you can set the first parameter to true and the BOM will snap to that anchor. SolidWorks adds anchors for every table type to each template, they might just still be at the wrong position for your template. I suggest you improve your template once so the anchors are at the right place.

                 

                If your part/assembly has only one configuration, you could just pass an empty string for the configuration. If you really like to keep "Default", remove the rubble in the front of the string like Deepak shows in a comment here.

                 

                You probably don't need those ClearSelection2 lines in there. That just makes it look like something the macro recorder made, that thing splashes a ClearSelection2 in its code about every other line

              • Re: First Macro - Insert BOM API
                Deepak Gupta

                This line

                tableTemplate = "" ' "\P:\Engineering\Templates\CryoWorks_ASM_BOM REV C.sldbomtbt"

                should be

                tableTemplate = "\P:\Engineering\Templates\CryoWorks_ASM_BOM REV C.sldbomtbt"
                • Re: First Macro - Insert BOM API
                  David Dickens

                  The Macro flawlessly drops the BOM(my template too!) right in place now and with the flat numbering and detailed cutlist as well.  Outstanding!!  Thanks guys!!!

                   

                  I'm still working thru how to get the macro to now edit the BOM as it drops it in.  I need the macro to add two lines(rows) and override 3 fields(cells) per line.  From what I've read and seen in other codes the modify command seems to need to identify the table first, then the row, then the cells.

                   

                  Post edited to add working code:

                   

                  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 bomTemplate As String
                  Dim Names As Variant
                  Dim visible As Variant
                  Dim boolStatus As Boolean
                  Dim swDraw As SldWorks.DrawingDoc
                  Dim swSheet As SldWorks.Sheet
                  Dim vfeature As Variant

                  Sub main()

                  Set swapp = Application.SldWorks
                  Set swmodel = swapp.ActiveDoc
                  Set swSelMgr = swmodel.SelectionManager
                  Set swFeatMgr = swmodel.featuremanager
                  Set swDraw = swmodel
                  Set swSheet = swDraw.GetCurrentSheet

                  'Select View
                  swmodel.ClearSelection2 True
                  Set swView = swDraw.GetCurrentSheet.GetViews()(0)

                  'Insert BOM Table
                  bomTemplate = "P:\Engineering\Templates\CryoWorks_ASM_BOM REV C.sldbomtbt"
                  anchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight
                  bomType = SwConst.swBomType_e.swBomType_Indented
                  configuration = "Default"

                  Set swBomAnn = swView.InsertBomTable4(True, 0, 0, anchorType, bomType, configuration, bomTemplate, False, swNumberingType_e.swNumberingType_Flat, True)
                  Set swBomFeat = swBomAnn.bomfeature
                  Names = swBomFeat.GetConfigurations(False, visible)
                  visible(0) = True
                  boolStatus = swBomFeat.SetConfigurations(True, visible, Names)

                  swFeatMgr.UpdateFeatureTree

                   

                  End Sub

                  • Re: First Macro - Insert BOM API
                    David Dickens

                    okay guys (Deepak Gupta, Peter Brinkhuis)  below is the code as I have it thus far.  I am a novice at best so any help you guys can offer would be great.  I have been reading thru more threads from others and found a working code suggested by Deepak Gupta that adds a line to a BOM.  I have been trying to combine my code thus far (post above about halfway down) and the "add a line" code.  It is getting stuck on the line highlighted below and I cant figure out what definition it needs for this variable.  The code works as stand alone but not when I combine them.

                     

                      • Re: First Macro - Insert BOM API
                        Deepak Gupta

                        David, glad to know that you progressing well.

                         

                        Please share the full macro codes as from picture it would be hard to debug. And better attach the SWP instead of posting the codes.

                          • Re: First Macro - Insert BOM API
                            David Dickens

                            ABSOLUTELY!!!

                             

                            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 bomTemplate As String
                            Dim Names As Variant
                            Dim visible As Variant
                            Dim boolStatus As Boolean
                            Dim swDraw As SldWorks.DrawingDoc
                            Dim swSheet As SldWorks.Sheet
                            Dim vfeature As Variant

                            Sub main()

                            Set swapp = Application.SldWorks
                            Set swmodel = swapp.ActiveDoc
                            Set swSelMgr = swmodel.SelectionManager
                            Set swFeatMgr = swmodel.featuremanager
                            Set swDraw = swmodel
                            Set swSheet = swDraw.GetCurrentSheet

                            'Select View
                            swmodel.ClearSelection2 True
                            Set swView = swDraw.GetCurrentSheet.GetViews()(0)

                            'Insert BOM Table
                            bomTemplate = "P:\Engineering\Templates\CryoWorks_ASM_BOM REV C.sldbomtbt"
                            anchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight
                            bomType = SwConst.swBomType_e.swBomType_Indented
                            configuration = "Default"

                            Set swBomAnn = swView.InsertBomTable4(True, 0, 0, anchorType, bomType, configuration, bomTemplate, False, swNumberingType_e.swNumberingType_Flat, True)
                            Set swBomFeat = swBomAnn.bomfeature
                            Names = swBomFeat.GetConfigurations(False, visible)
                            visible(0) = True
                            boolStatus = swBomFeat.SetConfigurations(True, visible, Names)

                            swFeatMgr.UpdateFeatureTree

                            On Error GoTo handler:
                            Dim BomFeatureName As String: BomFeatureName = "Bill of Materials1"
                            Dim swannotationtable As TableAnnotation
                            Dim result As Boolean
                            Dim featuremanager As featuremanager
                            Dim feature As feature
                            Dim vfeatures As Variant
                            Set swapp = Application.SldWorks
                            Set swmodel = swapp.ActiveDoc
                            Set featuremanager = swmodel.featuremanager
                            vfeatures = featuremanager.GetFeatures(True)
                            For i = 0 To UBound(vfeatures)
                            Set feature = vfeatures(i)
                            If feature.Name = BomFeatureName Then
                            Dim bomfeature As bomfeature
                            Set bomfeature = feature.GetSpecificFeature2
                            Dim bomtableannotation As bomtableannotation
                            Set bomtableannotation = bomfeature.GetTableAnnotations(0)
                            Set swannotationtable = bomtableannotation
                            Exit For
                            End If
                            Next i
                            result = swannotationtable.InsertRow(4, swannotationtable.RowCount)
                            Dim rowletter As String
                            rowletter = ChrW(64 + swannotationtable.ColumnCount)
                            swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 1) = _
                            "=SUM(" & rowletter & "1:" & rowletter & swannotationtable.RowCount - 1 & ")"
                            Exit Sub
                            handler:
                            swapp.SendMsgToUser ("Cannot find BOM with the name: " + BomFeatureName)

                            End Sub

                              • Re: First Macro - Insert BOM API
                                Deepak Gupta

                                You'e not defined i variable. Add this line and try again

                                Dim i As Long

                                  • Re: First Macro - Insert BOM API
                                    David Dickens

                                    BINGO!!!!!!!!!!!!!!      That's all it needed Deepak Gupta Thank You !!!!!!!!!!!!!!!

                                    it was just missing that one definition one definition.

                                     

                                    Deepak, after I edited the macro and ran it the "add a line" process got hung up looking for the name "bill of materials1".  Is there a way to make it accept any bill of material it finds?  or do I need to add in the code to have the macro name the BOM as it inserts it so that the code further down is able to find the correctly named BOM?

                                      • Re: First Macro - Insert BOM API
                                        Deepak Gupta

                                        David, yes it can be done. Check the macro by Matt here: Macro To link all views to BOM on Sheet 1

                                          • Re: First Macro - Insert BOM API
                                            David Dickens

                                            Okay Deepak Gupta.  Now I'm way over my head, the carrot is dangling in front of me but I'm not good enough at this stuff to get it to work.  I read thru the thread you linked and checked out the code and extracted what I think I needed and inserted it into my code and get this error.  It looks as if the process runs as far as needing the function to identify the string it has found out which is coming up empty and giving the error.  Any advice on how to fix what I have broken here?

                                            Oh, and any advice on how to fix my trying to insert customProperty code (see red text in code).

                                             

                                             

                                             

                                             

                                            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 bomTemplate As String
                                            Dim Names As Variant
                                            Dim visible As Variant
                                            Dim boolStatus As Boolean
                                            Dim swDraw As SldWorks.DrawingDoc
                                            Dim swSheet As SldWorks.Sheet
                                            Dim vfeature As Variant
                                            Dim BomName As String

                                             

                                            Sub main()

                                            Set swapp = Application.SldWorks
                                            Set swModel = swapp.ActiveDoc
                                            Set swSelMgr = swModel.SelectionManager
                                            Set swFeatMgr = swModel.featuremanager
                                            Set swDraw = swModel
                                            Set swSheet = swDraw.GetCurrentSheet
                                            BomName = getBomName(swModel)
                                                Debug.Print BomName

                                            'Select View
                                            swModel.ClearSelection2 True
                                            Set swView = swDraw.GetCurrentSheet.GetViews()(0)

                                            'Insert BOM Table
                                            bomTemplate = "P:\Engineering\Templates\CryoWorks_ASM_BOM REV C.sldbomtbt"
                                            anchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight
                                            bomType = SwConst.swBomType_e.swBomType_Indented
                                            configuration = "Default"

                                            Set swBomAnn = swView.InsertBomTable4(True, 0, 0, anchorType, bomType, configuration, bomTemplate, False, swNumberingType_e.swNumberingType_Flat, True)
                                            Set swBomFeat = swBomAnn.bomfeature
                                            Names = swBomFeat.GetConfigurations(False, visible)
                                            visible(0) = True
                                            boolStatus = swBomFeat.SetConfigurations(True, visible, Names)

                                            swFeatMgr.UpdateFeatureTree

                                            On Error GoTo handler:
                                            Dim BomFeatureName As String: BomFeatureName = BomName
                                            Dim swannotationtable As TableAnnotation
                                            Dim result As Boolean
                                            Dim featuremanager As featuremanager
                                            Dim feature As feature
                                            Dim vfeatures As Variant
                                            Set swapp = Application.SldWorks
                                            Set swModel = swapp.ActiveDoc
                                            Dim i As Long
                                            Set featuremanager = swModel.featuremanager
                                            vfeatures = featuremanager.GetFeatures(True)
                                            For i = 0 To UBound(vfeatures)
                                            Set feature = vfeatures(i)
                                            If feature.Name = BomFeatureName Then
                                            Dim bomfeature As bomfeature
                                            Set bomfeature = feature.GetSpecificFeature2
                                            Dim bomtableannotation As bomtableannotation
                                            Set bomtableannotation = bomfeature.GetTableAnnotations(0)
                                            Set swannotationtable = bomtableannotation
                                            Exit For
                                            End If
                                            Next i
                                            result = swannotationtable.InsertRow(4, swannotationtable.RowCount)
                                            Dim rowletter As String
                                            rowletter = ChrW(64 + swannotationtable.ColumnCount)
                                            swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 4) = _
                                            "SIEVE"
                                            swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 5) = _
                                            "TBD"
                                            swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 6) = _
                                            "$PRP:" '"Sieve Packs""
                                            On Error GoTo handler:
                                            Set swapp = Application.SldWorks
                                            Set swModel = swapp.ActiveDoc
                                            Set featuremanager = swModel.featuremanager
                                            vfeatures = featuremanager.GetFeatures(True)
                                            For i = 0 To UBound(vfeatures)
                                            Set feature = vfeatures(i)
                                            If feature.Name = BomFeatureName Then

                                            Set bomfeature = feature.GetSpecificFeature2

                                            Set bomtableannotation = bomfeature.GetTableAnnotations(0)
                                            Set swannotationtable = bomtableannotation
                                            Exit For
                                            End If
                                            Next i
                                            result = swannotationtable.InsertRow(4, swannotationtable.RowCount)

                                            rowletter = ChrW(64 + swannotationtable.ColumnCount)
                                            swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 4) = _
                                            "ZEOLITE"
                                            swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 5) = _
                                            "TBD"
                                            swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 6) = _
                                            "$PRP:Grams of Zeolite"
                                            handler:
                                            swapp.SendMsgToUser ("Cannot find BOM with the name: " + BomFeatureName)

                                             

                                            End Sub
                                            'function that traverses the feature manager tree looking for the BOM feature and returns name as string
                                            Function getBomName(swModel As ModelDoc2)
                                                Dim BomName As String
                                                Dim swFeat As SldWorks.feature
                                                Dim swBomFeat As SldWorks.bomfeature
                                               
                                                Set swFeat = swModel.FirstFeature
                                                Do While Not swFeat Is Nothing
                                                    Debug.Print swFeat.GetTypeName
                                                    If "BomFeat" = swFeat.GetTypeName Then
                                                        'Set swBomFeat = swFeat.GetSpecificFeature2
                                                        Exit Do
                                                    ElseIf "WeldmentTableFeat" = swFeat.GetTypeName Then
                                                        'Set swBomFeat = swFeat.GetSpecificFeature2
                                                        Exit Do
                                                    End If
                                                    Set swFeat = swFeat.GetNextFeature
                                                Loop
                                                'Set swFeat = swBomFeat.GetFeature
                                                getBomName = swFeat.Name

                                            End Function

                                              • Re: First Macro - Insert BOM API
                                                Deepak Gupta

                                                You can not simply put the property there. Better assign two more variables as strings. Then set them to required property value and use them in the places of the red text.

                                                 

                                                Let me share an example quickly.

                                                • Re: First Macro - Insert BOM API
                                                  Deepak Gupta

                                                  Check this example code and use as needed

                                                   

                                                  Option Explicit
                                                  Dim swapp       As SldWorks.SldWorks
                                                  Dim swModel     As SldWorks.ModelDoc2
                                                  Dim swDraw      As SldWorks.DrawingDoc
                                                  Dim swCustProp  As SldWorks.CustomPropertyManager
                                                  Dim val(1)      As String
                                                  Dim valout(1)   As String
                                                  
                                                  Sub main()
                                                  Set swapp = Application.SldWorks
                                                  Set swModel = swapp.ActiveDoc
                                                  Set swDraw = swModel
                                                  Set swCustProp = swDraw.Extension.CustomPropertyManager("")
                                                  
                                                  swCustProp.Get4 "Sieve Packs", False, val(0), valout(0)
                                                  swCustProp.Get4 "Grams of Zeolite", False, val(1), valout(1)
                                                  
                                                  Debug.Print valout(0)
                                                  Debug.Print valout(1)
                                                  
                                                  End Sub
                                                  
                                                    • Re: First Macro - Insert BOM API
                                                      David Dickens

                                                      Deepak Gupta, I already have values driven from the Custom Properties Tab and need to override that cell(which is normally driven from the models quantity) on he BOM so it populates with the value the designer enters.  Its all part of my work around to only have these two line items require the need for simple 2 digit data entry on the drawing properties tab.

                                                        • Re: First Macro - Insert BOM API
                                                          Deepak Gupta

                                                          David Dickens wrote:

                                                           

                                                          Its all part of my work around to only have these two line items require the need for simple 2 digit data entry on the drawing properties tab.

                                                           

                                                          David, that is what I'm suggesting. You can not enter the PRP Property name like that. So instead of that, get the desired value from the drawing custom properties and then add them to the table.

                                                           

                                                          To get the values from drawing custom properties, use the codes I've shared above and then replace those red text (PRP property name) with the strings to get the desired result..

                                                            • Re: First Macro - Insert BOM API
                                                              David Dickens

                                                              Deepak Gupta

                                                               

                                                              Holy smoke Deepak!  I'm glad you know what you're talking about cause I just keep digging this whole deeper and deeper!

                                                               

                                                                • Re: First Macro - Insert BOM API
                                                                  David Dickens

                                                                  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 bomTemplate As String
                                                                  Dim Names As Variant
                                                                  Dim visible As Variant
                                                                  Dim boolStatus As Boolean
                                                                  Dim swDraw As SldWorks.DrawingDoc
                                                                  Dim swSheet As SldWorks.Sheet
                                                                  Dim vfeature As Variant
                                                                  Dim swCustProp  As SldWorks.CustomPropertyManager
                                                                  Dim val(1)      As String
                                                                  Dim valout(1)   As String

                                                                  Sub main()

                                                                  Set swapp = Application.SldWorks
                                                                  Set swmodel = swapp.ActiveDoc
                                                                  Set swSelMgr = swmodel.SelectionManager
                                                                  Set swFeatMgr = swmodel.featuremanager
                                                                  Set swDraw = swmodel
                                                                  Set swSheet = swDraw.GetCurrentSheet
                                                                  Set swCustProp = swDraw.Extension.CustomPropertyManager("")

                                                                  'Select View
                                                                  swmodel.ClearSelection2 True
                                                                  Set swView = swDraw.GetCurrentSheet.GetViews()(0)

                                                                  'Insert BOM Table
                                                                  bomTemplate = "P:\Engineering\Templates\CryoWorks_ASM_BOM REV C.sldbomtbt"
                                                                  anchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight
                                                                  bomType = SwConst.swBomType_e.swBomType_Indented
                                                                  configuration = "Default"

                                                                  Set swBomAnn = swView.InsertBomTable4(True, 0, 0, anchorType, bomType, configuration, bomTemplate, False, swNumberingType_e.swNumberingType_Flat, True)
                                                                  Set swBomFeat = swBomAnn.bomfeature
                                                                  Names = swBomFeat.GetConfigurations(False, visible)
                                                                  visible(0) = True
                                                                  boolStatus = swBomFeat.SetConfigurations(True, visible, Names)

                                                                  swFeatMgr.UpdateFeatureTree

                                                                  On Error GoTo handler:
                                                                  Dim BomFeatureName As String: BomFeatureName = "Bill of Materials1"
                                                                  Dim swannotationtable As TableAnnotation
                                                                  Dim result As Boolean
                                                                  Dim featuremanager As featuremanager
                                                                  Dim feature As feature
                                                                  Dim vfeatures As Variant
                                                                  Set swapp = Application.SldWorks
                                                                  Set swmodel = swapp.ActiveDoc
                                                                  Dim i As Long
                                                                  Set featuremanager = swmodel.featuremanager
                                                                  vfeatures = featuremanager.GetFeatures(True)
                                                                  For i = 0 To UBound(vfeatures)
                                                                  Set feature = vfeatures(i)
                                                                  If feature.Name = BomFeatureName Then
                                                                  Dim bomfeature As bomfeature
                                                                  Set bomfeature = feature.GetSpecificFeature2
                                                                  Dim bomtableannotation As bomtableannotation
                                                                  Set bomtableannotation = bomfeature.GetTableAnnotations(0)
                                                                  Set swannotationtable = bomtableannotation

                                                                  Exit For
                                                                  End If
                                                                  Next i
                                                                  result = swannotationtable.InsertRow(4, swannotationtable.RowCount)
                                                                  Dim rowletter As String
                                                                  rowletter = ChrW(64 + swannotationtable.ColumnCount)
                                                                  swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 4) = _
                                                                  "SIEVE PACKETS"
                                                                  swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 5) = _
                                                                  "TBD"
                                                                  swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 6) = _
                                                                  swCustProp.Get4 "Sieve Packs", False, val(0), valout(0)

                                                                   

                                                                  On Error GoTo handler:
                                                                  Set swapp = Application.SldWorks
                                                                  Set swmodel = swapp.ActiveDoc
                                                                  Set featuremanager = swmodel.featuremanager
                                                                  vfeatures = featuremanager.GetFeatures(True)
                                                                  For i = 0 To UBound(vfeatures)
                                                                  Set feature = vfeatures(i)
                                                                  If feature.Name = BomFeatureName Then

                                                                  Set bomfeature = feature.GetSpecificFeature2

                                                                  Set bomtableannotation = bomfeature.GetTableAnnotations(0)
                                                                  Set swannotationtable = bomtableannotation
                                                                  Exit For
                                                                  End If
                                                                  Next i
                                                                  result = swannotationtable.InsertRow(4, swannotationtable.RowCount)

                                                                  rowletter = ChrW(64 + swannotationtable.ColumnCount)
                                                                  swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 4) = _
                                                                  "GRAMS OF ZEOLITE"
                                                                  swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 5) = _
                                                                  "TBD"
                                                                  swannotationtable.Text(swannotationtable.RowCount - 1, swannotationtable.ColumnCount - 6) = _
                                                                  "$PRP:Grams of Zeolite"
                                                                  handler:
                                                                  swapp.SendMsgToUser ("Cannot find BOM with the name: " + BomFeatureName)

                                                                  Debug.Print valout(0)
                                                                  Debug.Print valout(1)

                                                                  End Sub

                                                                    • Re: First Macro - Insert BOM API
                                                                      Deepak Gupta

                                                                      Here is the fixed version. It works currently with Bill of Material name as Bill of Materials1

                                                                       

                                                                      If this works for you, then it can be changed to get the BOM name on active sheet.

                                                                        • Re: First Macro - Insert BOM API
                                                                          David Dickens

                                                                          Deepak Gupta, you are the man!!!!!  Deepak Gupta Thank You

                                                                           

                                                                          The macro does all that I wanted it to.  Not perfectly, which I'll ask about next, but it does the job so you Sir get the correct answer mark.  Thank you again.

                                                                           

                                                                          Yes, I would in fact like to switch away from the using "Bill of Materials1".  This gets in the way if you ever delete the BOM and want to use the macro to reinsert it.  That would fix small item #1.

                                                                           

                                                                          Item #2 that I would like to ask you about is the insertion of the custom property values.  They don't update; they are one time insertion and that's it.  This value will change on occasion and will need to update in the drawing BOM.  How might I go about having that macro insert something that will live update from the Custom properties tab.  Because something else I noticed when I was testing it out this morning was that if I forgot to enter the values into the properties tab before I inserted the BOM via the macro is that the cells were as normal and would have to be overridden.