3 Replies Latest reply on Dec 7, 2016 9:36 AM by Mathieu Jette

    API/Macro, Multi pages drawing, tables problem.

    Mathieu Jette

      Hi,

           We are using a macro for batch print and inputs of properties in the drawings as they are being printed.

      When a drawing has multiple pages (1 for each configuration of the assembly/part), the macro scans the bom to identify the page to print (as far as how I understand it).

      It works well untill there is another table (revision, or plain table) in the sheet... if so, then the macro crashes.

      I need help to fix this issue.

       

      Here is the Macro Section concerned. with the line where it crashes identified.

       

      Set swFeatMgr = Sw_model.FeatureManager

      Bon_Sheet = False

      Sw_Sheets = Sw_Draft.GetSheetNames

      N_Sheet = 1

      If Sw_Draft.GetSheetCount = 1 Then GoTo Pass_Sheet

      For J = 0 To UBound(Sw_Sheets)

          bRet = Sw_Draft.ActivateSheet(Sw_Sheets(J))

          Set Sw_Sheet = Nothing

          Set Sw_Sheet = Sw_Draft.Sheet(Sw_Sheets(J))

          Set Sw_View = Sw_model.GetFirstView

          Do While Not Sw_View Is Nothing

              Set SwAll_table = Sw_View.GetFirstTableAnnotation

              Do While Not SwAll_table Is Nothing

                  Set Sw_Bom = Nothing

                  Set Sw_Bom = SwAll_table

                  Set Sw_Bom_Feature = Nothing

                  Set Sw_Bom_Feature = Sw_Bom.BomFeature                                    'Crash happens here

                  Names = Sw_Bom_Feature.GetConfigurations(True, Visible)

                  If Names(0) = Config_Name Then

                      Bon_Sheet = True

                      Exit Do

                  End If

                  Set SwAll_table = SwAll_table.GetNext

              Loop

              If Bon_Sheet = True Then

                  Exit Do

              End If

             

              bolUseParentStyle = Sw_View.GetUseParentDisplayMode()

              lngDisplayMode = Sw_View.GetDisplayMode2

              bolDispEdgesInShadedMode = Sw_View.GetDisplayEdgesInShadedMode

              bolResult = Sw_View.SetDisplayMode3(bolUseParentStyle, lngDisplayMode, False, bolDispEdgesInShadedMode)

             

              Set Sw_View = Sw_View.GetNextView

          Loop

          If Bon_Sheet = True Then

              Exit For

          End If

          N_Sheet = N_Sheet + 1

      Next J

       

       

      Any help will be appreciated.

      Thanks.

        • Re: API/Macro, Multi pages drawing, tables problem.
          Peter Brinkhuis

          I don't really understand what the macro does exactly. I see it goes through the sheets, through the views and the tables.

           

          I think you have to check the type of the table annotation using 2015 SOLIDWORKS API Help - Type Property (ITableAnnotation)  . If it's a bill of materials, you can run the line that 'crashes' with other table types. If it's another type of table, you just skip it.

          • Re: API/Macro, Multi pages drawing, tables problem.
            Josh Brady

            As Peter mentioned, you do need to check the table type before assuming it's a BOM:

             

            Set swFeatMgr = Sw_model.FeatureManager

            Bon_Sheet = False

            Sw_Sheets = Sw_Draft.GetSheetNames

            N_Sheet = 1

            If Sw_Draft.GetSheetCount = 1 Then GoTo Pass_Sheet

            For J = 0 To UBound(Sw_Sheets)

                bRet = Sw_Draft.ActivateSheet(Sw_Sheets(J))

                Set Sw_Sheet = Nothing

                Set Sw_Sheet = Sw_Draft.Sheet(Sw_Sheets(J))

                Set Sw_View = Sw_model.GetFirstView

                Do While Not Sw_View Is Nothing

                    Set SwAll_table = Sw_View.GetFirstTableAnnotation

                    Do While Not SwAll_table Is Nothing

                           if SwAll_table.Type = swTableAnnotation_BillOfMaterials then

                        Set Sw_Bom = Nothing

                        Set Sw_Bom = SwAll_table

                        Set Sw_Bom_Feature = Nothing

                        Set Sw_Bom_Feature = Sw_Bom.BomFeature                                    'Crash happens here

                        Names = Sw_Bom_Feature.GetConfigurations(True, Visible)

                        If Names(0) = Config_Name Then

                            Bon_Sheet = True

                            Exit Do

                        End If

                        End If

                        Set SwAll_table = SwAll_table.GetNext

                    Loop

                    If Bon_Sheet = True Then

                        Exit Do

                    End If

                  

                    bolUseParentStyle = Sw_View.GetUseParentDisplayMode()

                    lngDisplayMode = Sw_View.GetDisplayMode2

                    bolDispEdgesInShadedMode = Sw_View.GetDisplayEdgesInShadedMode

                    bolResult = Sw_View.SetDisplayMode3(bolUseParentStyle, lngDisplayMode, False, bolDispEdgesInShadedMode)

                  

                    Set Sw_View = Sw_View.GetNextView

                Loop

                If Bon_Sheet = True Then

                    Exit For

                End If

                N_Sheet = N_Sheet + 1

            Next J