5 Replies Latest reply on Apr 8, 2017 1:56 PM by Deepak Gupta

    API to link weldment cut list placed on each sheet to all the views of this sheet

    Sebastien Kitten

      Hi,

      I currently use a macro that scans all the views for each sheet placed in a drawing and assigns the BOM table placed on each sheet to all the views present on this sheet. This works pretty well, excepted when it comes to weldment cut list. I would like to adapt this macro so it works exactly the same way when the sheet has a weldment cut list instead of a BOM. I don't want to replace the weldment cut list with a BOM including the detailed cut list. I don't succeed in getting the feature name of the table when it is a weldment cut list. Here is my code, I'm looking for some help to correct the "If TableType = 4 Then" test.

       

      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swDraw As SldWorks.DrawingDoc

      Dim swTableAnnotation As SldWorks.TableAnnotation

      Dim swBOMAnnotation As SldWorks.BomTableAnnotation

      Dim swBOMFeature As SldWorks.BomFeature

      Dim swWCLAnnotation As Variant

      Dim swWCLFeature As SldWorks.WeldmentCutListFeature

      Dim View As SldWorks.View

      Dim vSheetName  As Variant

      Dim i As Integer

      Dim TableType As Long

      Dim BOMTableName As String

      Dim WCLTableName As String

       

       

      Sub main()

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

      Set swDraw = swModel

      Set Sheet = swDraw.GetCurrentSheet

       

       

      vSheetName = swDraw.GetSheetNames

       

       

          For i = 0 To UBound(vSheetName)

              swDraw.ActivateSheet vSheetName(i)

       

       

              'FindBOM

              'Get the first View from the DrawingDoc

              Set View = swDraw.GetFirstView

              'Traverse all the TableAnnotations for the View looking for BOM table type_

              Set swTableAnnotation = View.GetFirstTableAnnotation

              Do While Not swTableAnnotation Is Nothing

                  TableType = swTableAnnotation.Type

                  If TableType = 2 Then ' BOM

                      Set swBOMAnnotation = swTableAnnotation

                      Set swBOMFeature = swBOMAnnotation.BomFeature

                      BOMTableName = swBOMFeature.Name

                      Debug.Print "BOM on this active sheet: " & BOMTableName

                  End If

                  If TableType = 4 Then ' WeldmentCutList

      '                Set swWCLFeature =

      '                BOMTableName = swWCLFeature.Name

      '                Debug.Print "Weldment Cut List on this active sheet: " & BOMTableName

                  End If

                  Set swView = swDraw.GetFirstView

                  Set swView = swView.GetNextView

                      While Not swView Is Nothing

                          swView.SetKeepLinkedToBOM True, BOMTableName

                          Set swView = swView.GetNextView

                      Wend

              Exit Do

              Set swTableAnnotation = swTableAnnotation.GetNext

              Loop

          Next i

       

      End Sub

       

      Thanks.

       

      Sebastien