AnsweredAssumed Answered

printout2

Question asked by Hank Costner on Oct 31, 2017
Latest reply on Oct 31, 2017 by Hank Costner

Hello all,

 

I'm new to using SW API. The code I wrote is meant to take sheets from a drawing and save them as PDF's. I want to control what the filenames are from the program. That's what I'm trying to using the variable fileNames for.

I have a drawing open with many sheets when I run the API from the edit window.

My default printer is set to Microsoft Print to PDF.

The code compiles, and I'm not sure if the PDF's are being made and saved somewhere random, or if I'm missing something in my code.

Any ideas?

Here's my code:

 

 

 

Dim swApp As Object

Sub main()

 

 

Dim swModel As Object

 

 

 

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

    If (swModel Is Nothing) Then

        MsgBox "No active drawing found in SolidWorks." & Chr(13) & Chr(13) _

            & "Please load/activate a SolidWorks drawing ", vbExclamation

        End

    End If

   

    If (swModel.GetType <> swDocDRAWING) Then

        MsgBox "Current document is not a drawing." & Chr(13) & Chr(13) _

            & "Please load/activate a SolidWorks drawing ", vbExclamation

        End

    End If

   

   

Dim numberOfSheets As Integer

Dim SalesPageToPrint(0) As Integer 'Page Array

Dim FabPagesToPrint(1) As Integer 'Page Array

Dim n As Integer 'file name placeholder

Dim fileNames 'names for files

Dim pageIncrement As Integer 'used to step through Page Array

Dim i As Integer 'iterator

 

 

numberOfSheets = swModel.GetSheetCount

SalesPageToPrint(0) = 1

FabPagesToPrint(0) = 2

FabPagesToPrint(1) = 3

i = 0

n = 0

fileNames = Array("125112-Production.pdf", "125112 - Sales", _

"125117 - Production", "125117 - Sales")

 

 

Do While i < 3

 

 

swModel.Extension.PrintOut2 SalesPageToPrint, 1, True, "", fileNames(n)

n = n + 1

swModel.Extension.PrintOut2 FabPagesToPrint, 1, True, "", fileNames(n)

 

 

SalesPageToPrint(0) = SalesPageToPrint(0) + 3

FabPagesToPrint(0) = FabPagesToPrint(0) + 3

FabPagesToPrint(1) = FabPagesToPrint(1) + 3

n = n + 1

i = i + 3

 

 

Loop

 

 

 

 

End Sub

Outcomes