12 Replies Latest reply on Sep 21, 2017 6:09 AM by Matt Bieringer

    AddPrintRange and PrintRange issue in Macro

    Peter Kennedy

      I'm trying to control the number of pages I print using a macro, I've tried using both PrintRange and AddPrintRange

       

      2015 SOLIDWORKS API Help - PrintRange Property (IPrintSpecification)

      2015 SOLIDWORKS API Help - AddPrintRange Method (IPrintSpecification)

       

      However the macro still just seems to print which ever the current selected sheet is, regardless what range is defined.

      I'm trying to print to PDF however I have tried setting the printer to an actual one and the range is still incorrect.

       

      Has anyone been able to get these functions to work?

        • Re: AddPrintRange and PrintRange issue in Macro
          Peter Brinkhuis

          What does the macro currently look like? It's hard to debug from here now.

            • Re: AddPrintRange and PrintRange issue in Macro
              Peter Kennedy

              Option Explicit

               

               

              Dim swApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim swDraw As SldWorks.DrawingDoc

              Dim swRefModelExt As ModelDocExtension

              Dim swCustPropMgr As SldWorks.CustomPropertyManager

              Dim swView As SldWorks.View

              Dim swDrawComp As SldWorks.DrawingComponent

              Dim swComp As SldWorks.Component2

              Dim swRefModel As SldWorks.ModelDoc2

              Dim swLayerMgr As SldWorks.LayerMgr

              Dim swLayer As SldWorks.Layer

              Dim swPageSetup As SldWorks.PageSetup

              Dim printSpec As SldWorks.PrintSpecification

              Dim swModelDocExt As SldWorks.ModelDocExtension

               

              Dim val As String

              Dim FileNumber As String

              Dim strRefModelPath As String

              Dim TotalNumPages As Integer

              Dim PrintPages(1) As Integer

               

              Sub main()

                  Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

                  Set swDraw = swModel

                  Set swView = swDraw.GetFirstView

                  Set swView = swView.GetNextView

                  strRefModelPath = swView.GetReferencedModelName

                  Set swDrawComp = swView.RootDrawingComponent

                  swApp.DocumentVisible False, swDocPART

                 

                  Set swLayerMgr = swModel.GetLayerManager

                  Set swLayer = swLayerMgr.GetLayer("NEP")

                 

                  swLayer.Visible = False

                  Set swModelDocExt = swModel.Extension

                 

                  Set printSpec = swModelDocExt.GetPrintSpecification

                  TotalNumPages = printSpec.SheetCount

                  PrintPages(0) = 1

                  PrintPages(1) = TotalNumPages - 1

                  printSpec.ConvertToHighQuality = True

                  printSpec.AddPrintRange = 1 , PrintPages(1)

                  printSpec.FromScale = 1.5

                  printSpec.ToScale = 0.5

                  printSpec.ScaleMethod = swPrintSelection

                  printSpec.PrinterQueue = "Adobe PDF"

                  printSpec.PrintToFile = False

               

                swModelDocExt.PrintOut4 "", "", printSpec

                 

                  swLayer.Visible = True

                  printSpec.RestoreDefaults

                  printSpec.ResetPrintRange

                 

               

               

              End Sub

            • Re: AddPrintRange and PrintRange issue in Macro
              Peter Brinkhuis

              I filed a bug report, we'll see what happens.

              • Re: AddPrintRange and PrintRange issue in Macro
                Peter Brinkhuis

                The bug was confirmed, although it was already reported by someone else a little earlier. SPR 1018969 is the one.

                • Re: AddPrintRange and PrintRange issue in Macro
                  Matt Bieringer

                  I think I have found a way around this with .printout3 instead of .printout4. You can create a page array and use that with printout3.

                  Here is an example using 2 textboxes to set the range.

                   

                  Dim swApp As SldWorks.SldWorks
                  Dim swModel As SldWorks.ModelDoc2
                  Dim swDraw As SldWorks.DrawingDoc
                  Dim swModelDocExt As SldWorks.ModelDocExtension
                  Dim swPrintSpec As SldWorks.PrintSpecification
                  Dim swPageSetup As SldWorks.PageSetup
                  Dim swModelView As SldWorks.ModelView
                  Dim swSheet As SldWorks.Sheet
                  Dim sheets() As Integer
                  Dim FirstPage As Integer
                  Dim LastPage As Integer
                  
                  FirstPage = TextBox1.Text
                  LastPage = TextBox2.Text
                  ReDim sheets(i)
                  sheets(i) = FirstPage
                  i = i + 1
                  ReDim Preserve sheets(i)
                  sheets(i) = LastPage
                  swModelDocExt.PrintOut3 sheets, 1, True, "Adobe PDF", "", False
                  

                   

                  Hope it helps.