9 Replies Latest reply on Feb 25, 2015 1:53 PM by Adam Hoffman

    Change BOM configuration for assembly drawing

    Michael Caulton

      Is there any reason swBomFeat.Configuration = sConfig (Line 10) will work correctly on a BOM in a part drawing but not an assembly drawing?

       

          Sub ChangeDrawingBOMConfig(swDraw As SldWorks.DrawingDoc, sConfig As String)
              Dim swFeat As SldWorks.Feature
              Dim swBomFeat As SldWorks.BomFeature
              SetUserPreferencesDrawing(swDraw) ' Change user pref not to use template defaults so justification doesnt change
              swFeat = swDraw.FirstFeature
              Do While Not swFeat Is Nothing
                  If (swFeat.GetTypeName = "BomFeat") Then
                      Debug.Print(swFeat.Name)
                      swBomFeat = swFeat.GetSpecificFeature2
                      swBomFeat.Configuration = sConfig ' Set BOM Config
                  End If
                  swFeat = swFeat.GetNextFeature
              Loop
          End Sub
      

       

      Is there a better way to get the BOM on a particular drawing sheet?

        • Re: Change BOM configuration for assembly drawing
          Adam Hoffman

          Depends on what type of BOM it is. Read the remarks in the help here:

           

          2013 SOLIDWORKS API Help - Configuration Property (IBomFeature)

           

          I have always just deleted the BOM and reinserted a new one to get around this.

            • Re: Change BOM configuration for assembly drawing
              Michael Caulton

              Hi Adam, how do you deal with the column sizing and location when you create the new BOM? I do not want the size and location of the table to change from what was on the document originally.

                • Re: Change BOM configuration for assembly drawing
                  Adam Hoffman

                  Well that's the kicker isn't it? At our company, we follow strict standards on the which BOM template we use for what drawings. I know based on what type of drawing it is, what BOM table template to use when inserting the new BOM. If this is not your case, then you will have to jump through some hoops to find out the number of columns, those column widths, if it's a top level only or parts only BOM, the list of parameters is quite extensive. Wish I could say it would be a cake walk but it wouldn't. Wish I could be more help.

                    • Re: Change BOM configuration for assembly drawing
                      Michael Caulton

                      We are the same so I know which BOM template should be used. I can insert the BOM and get it into the location I want it but........

                       

                      The problem is sometimes the text in the cells overlaps the border as per example image below. The description columns is too narrow while other columns are wider than necessary.

                      Unmodified BOM.JPG

                       

                      Manually this can easily be fixed by highlighting the table then double clicking on one of the vertical lines in the header (same as excel). Desirable final result shown below.

                      Cell Width Auto.JPG

                        • Re: Change BOM configuration for assembly drawing
                          Adam Hoffman

                          What I would do is before deleting the BOM is get the number of columns and assign that to a variable. Then loop through the columns and get the width for each one adding it to a list. Then delete the BOM and insert your new one. After insertion, loop through the new BOM's columns and adjust the width according to the previous values obtained. It takes a little doing but should be simple enough. We usually lock the row height in our table templates, but you should be able to do the same with the row height. Let me know if you need any help with sample code.

                            • Re: Change BOM configuration for assembly drawing
                              Michael Caulton

                              I have been looping through the drawing features to find BOMs but cant find a way of identifying which BOM is on the active sheet.

                               

                              Is it possible to delete a BOM from the table "iTableAnnotation"?

                               

                              I am also having a problem where the exact same code will insert a BOM filled out correctly on one drawing but not on another. When it doesn't work correctly it inserts the BOM but doesn't link it to the specified configuration even though the configuration is name is set correctly.

                               

                                      ' Create new BOM

                                      swView = swDraw.GetCurrentSheet.GetViews()(0)

                                      AnchorType = swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight

                                      BomType = swBomType_e.swBomType_TopLevelOnly

                                      swBOMAnnotation = swView.InsertBomTable2(False, X, Y, AnchorType, BomType, sConfig, sBOMTemplatePath)

                                      swBOMFeature = swBOMAnnotation.BomFeature

                                • Re: Change BOM configuration for assembly drawing
                                  Adam Hoffman

                                  Here is what I use in one of my VB.Net add ins:

                                   

                                  swFeat = swModel.FirstFeature

                                   

                                  Do While Not swFeat Is Nothing
                                         If "BomFeat" = swFeat.GetTypeName2 Then
                                             swBOMFeature = swFeat.GetSpecificFeature2
                                             swBOMFeature.GetFeature.Select2(False, 0)
                                             swModExt.DeleteSelection2(0)
                                         End If
                                         swFeat = swFeat.GetNextFeature
                                  Loop

                                   

                                  swView = swModel.GetFirstView
                                  swView = swView.GetNextView
                                  AnchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight


                                  Try
                                       swBOMTableAnno = swView.InsertBomTable4(True, 0.4, 0.3, AnchorType, swBomType_e.swBomType_TopLevelOnly, _

                                                                                                                   CurrentConFig, sBOMTemplatePath, False, _

                                                                                                                   swNumberingType_e.swNumberingType_None, False)

                                   

                                       'Set the name of the BOM to Bill of Materials1

                                       swFeat = swModel.FirstFeature
                                       Do While Not swFeat Is Nothing
                                             If "BomFeat" = swFeat.GetTypeName2 Then
                                                 swFeat.Name = "Bill of Materials1"
                                             End If
                                             swFeat = swFeat.GetNextFeature
                                        Loop

                                  Catch BOMAnnoErr As Exception
                                            MessageBox.Show("Error Inserting New BOM Table For " + CurrentConFig, _

                                                                             "BOM Table Error", MessageBoxButtons.OK, _

                                                                              MessageBoxIcon.Error)
                                  End Try

                                    • Re: Change BOM configuration for assembly drawing
                                      Michael Caulton

                                      I use a very similar routine to get rid of the BOM but it does not let you get rid of a specific BOM on a specific sheet if you have multiple sheets. It  runs through all features and deletes all BOMs.

                                       

                                              ' Delete a BOM if one exists
                                              Dim swFeat As SldWorks.Feature = swDraw.FirstFeature
                                              Do While Not swFeat Is Nothing
                                                  If (swFeat.GetTypeName = "BomFeat") Then
                                                      swBOMFeature = swFeat.GetSpecificFeature2
                                                      swFeat.Select(False)
                                                      swFeat = swFeat.GetNextFeature
                                                      swModel.EditDelete()
                                                  Else 
                                                      swFeat = swFeat.GetNextFeature 
                                                  End If
                                              Loop