Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Printing Different size sheets

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
619 Views, 7 Replies

Printing Different size sheets

Anonymous
Not applicable
Hi Guys First time post in this group..

Im currently trying to create a macro to print and dxf automatically, which i have succefully done... well almost!

we have the instance where we have say a sheet 1 and a _LSR for flat pattern laser cutting drawings. Typically the Sheet 1 will be an A3 size drawing, and the laser will be anything up to A0. The problem i have is getting the sheets to print out in their own size, the macro i have grabs the first sheet size and sets it from there.

the dxf works great as it doesnt rely on paper sizes, but the PDF is an issue

Anyone got a clue if what im trying to do is possible?

Thanks in advance

Steve Oliver
0 Likes

Printing Different size sheets

Hi Guys First time post in this group..

Im currently trying to create a macro to print and dxf automatically, which i have succefully done... well almost!

we have the instance where we have say a sheet 1 and a _LSR for flat pattern laser cutting drawings. Typically the Sheet 1 will be an A3 size drawing, and the laser will be anything up to A0. The problem i have is getting the sheets to print out in their own size, the macro i have grabs the first sheet size and sets it from there.

the dxf works great as it doesnt rely on paper sizes, but the PDF is an issue

Anyone got a clue if what im trying to do is possible?

Thanks in advance

Steve Oliver
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
I'm not very clear about the problem. Could you post the code you have to
illustrate?

Sanjay-
0 Likes

I'm not very clear about the problem. Could you post the code you have to
illustrate?

Sanjay-
Message 3 of 8
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Hi Sanjay apologies for not being clear!

the PDF code i have is:-

Sub PDF_uncontrolled()

Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
Dim oLayer As Layer

Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet

' Get the layer object that we want to use.
Set oLayer = oDrawDoc.StylesManager.Layers.Item("Uncontrolled")
oLayer.Visible = True


oDrawDoc.PrintManager.Printer = "PDFCreator"
oDrawDoc.PrintManager.NumberOfCopies = 1
oDrawDoc.PrintManager.PrintRange = kPrintAllSheets
oDrawDoc.PrintManager.Orientation = kLandscapeOrientation
oDrawDoc.PrintManager.Rotate90Degrees = False
oDrawDoc.PrintManager.PaperSize = kPaperSizeA3
oDrawDoc.PrintManager.SubmitPrint
oLayer.Visible = False

End Sub

There is also a borrowed and slightly modded code i got from here also that i was trying to do the same thing with, but ended up using it as a single sheet print for the odd size sheet.

Option Explicit

Private Function FindSheetSize(varSheet As Sheet) As PaperSizeEnum
Select Case varSheet.Size
Case kA4DrawingSheetSize
FindSheetSize = kPaperSizeA4
Case kA3DrawingSheetSize
FindSheetSize = kPaperSizeA3
Case kA2DrawingSheetSize
FindSheetSize = kPaperSizeA2
Case kA1DrawingSheetSize
FindSheetSize = kPaperSizeA1
Case kA0DrawingSheetSize
FindSheetSize = kPaperSizeA0
End Select
End Function


Public Sub PDFCurrentSheet()

Dim varDrawingDoc As DrawingDocument
Set varDrawingDoc = ThisApplication.ActiveDocument

Dim varPrintManager As DrawingPrintManager
Set varPrintManager = varDrawingDoc.PrintManager

Dim varSheet As Inventor.Sheet
Set varSheet = varDrawingDoc.ActiveSheet

' Declare and show the uncontrolled layer
Dim oLayer As Layer
Set oLayer = varDrawingDoc.StylesManager.Layers.Item("Uncontrolled")
oLayer.Visible = True

With varPrintManager
.Printer = "PDFCreator"
.PaperSize = FindSheetSize(varSheet)
.PrintRange = kPrintCurrentSheet
.ScaleMode = kPrintFullScale
.Orientation = kLandscapeOrientation


End With

If FindSheetSize(varSheet) = kPaperSizeA1 Then
varDrawingDoc.PrintManager.Rotate90Degrees = True
ElseIf FindSheetSize(varSheet) = kPaperSizeA0 Then
varDrawingDoc.PrintManager.Rotate90Degrees = True
Else:
varDrawingDoc.PrintManager.Rotate90Degrees = False
End If

varDrawingDoc.PrintManager.SubmitPrint

oLayer.Visible = False

End Sub

So my end goal is to have a macro that prints all sheets in their respective sheet size. the problem i have is that most macros i have seen get the sheet size from the active sheet and the run the print routine..

what i need is a macro that can print all sheets in the correct size, in the current single PDF file rather than several PDF files appended with the sheet number.

im very new to this so apologies for the dodgy code.

im also thinking that this is an issue related more to the pdf printer than anything else!

Does that make more sense?

Thanks

Steve Oliver
0 Likes

Hi Sanjay apologies for not being clear!

the PDF code i have is:-

Sub PDF_uncontrolled()

Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
Dim oLayer As Layer

Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet

' Get the layer object that we want to use.
Set oLayer = oDrawDoc.StylesManager.Layers.Item("Uncontrolled")
oLayer.Visible = True


oDrawDoc.PrintManager.Printer = "PDFCreator"
oDrawDoc.PrintManager.NumberOfCopies = 1
oDrawDoc.PrintManager.PrintRange = kPrintAllSheets
oDrawDoc.PrintManager.Orientation = kLandscapeOrientation
oDrawDoc.PrintManager.Rotate90Degrees = False
oDrawDoc.PrintManager.PaperSize = kPaperSizeA3
oDrawDoc.PrintManager.SubmitPrint
oLayer.Visible = False

End Sub

There is also a borrowed and slightly modded code i got from here also that i was trying to do the same thing with, but ended up using it as a single sheet print for the odd size sheet.

Option Explicit

Private Function FindSheetSize(varSheet As Sheet) As PaperSizeEnum
Select Case varSheet.Size
Case kA4DrawingSheetSize
FindSheetSize = kPaperSizeA4
Case kA3DrawingSheetSize
FindSheetSize = kPaperSizeA3
Case kA2DrawingSheetSize
FindSheetSize = kPaperSizeA2
Case kA1DrawingSheetSize
FindSheetSize = kPaperSizeA1
Case kA0DrawingSheetSize
FindSheetSize = kPaperSizeA0
End Select
End Function


Public Sub PDFCurrentSheet()

Dim varDrawingDoc As DrawingDocument
Set varDrawingDoc = ThisApplication.ActiveDocument

Dim varPrintManager As DrawingPrintManager
Set varPrintManager = varDrawingDoc.PrintManager

Dim varSheet As Inventor.Sheet
Set varSheet = varDrawingDoc.ActiveSheet

' Declare and show the uncontrolled layer
Dim oLayer As Layer
Set oLayer = varDrawingDoc.StylesManager.Layers.Item("Uncontrolled")
oLayer.Visible = True

With varPrintManager
.Printer = "PDFCreator"
.PaperSize = FindSheetSize(varSheet)
.PrintRange = kPrintCurrentSheet
.ScaleMode = kPrintFullScale
.Orientation = kLandscapeOrientation


End With

If FindSheetSize(varSheet) = kPaperSizeA1 Then
varDrawingDoc.PrintManager.Rotate90Degrees = True
ElseIf FindSheetSize(varSheet) = kPaperSizeA0 Then
varDrawingDoc.PrintManager.Rotate90Degrees = True
Else:
varDrawingDoc.PrintManager.Rotate90Degrees = False
End If

varDrawingDoc.PrintManager.SubmitPrint

oLayer.Visible = False

End Sub

So my end goal is to have a macro that prints all sheets in their respective sheet size. the problem i have is that most macros i have seen get the sheet size from the active sheet and the run the print routine..

what i need is a macro that can print all sheets in the correct size, in the current single PDF file rather than several PDF files appended with the sheet number.

im very new to this so apologies for the dodgy code.

im also thinking that this is an issue related more to the pdf printer than anything else!

Does that make more sense?

Thanks

Steve Oliver
Message 4 of 8
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
I understand now. You have sheets of different sizes in your drawing and you
want to print them to the appropriate paper size to the same PDF. As far as
I know, this will not be possible. The only thing I could think of is to
experiment with the ScaleMode property to best fit the drawing to the
specified paper size, but this may not be acceptable if you always want full
scale drawings.

Sanjay-
0 Likes

I understand now. You have sheets of different sizes in your drawing and you
want to print them to the appropriate paper size to the same PDF. As far as
I know, this will not be possible. The only thing I could think of is to
experiment with the ScaleMode property to best fit the drawing to the
specified paper size, but this may not be acceptable if you always want full
scale drawings.

Sanjay-
Message 5 of 8
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Thanks Sanjay

the more i thought about it the more i came to the conclusion that i was limited by the driver / print all sheets method.

i have a clunky workflow i can follow so i should be ok... not quite the one click that i was hoping tho!

be interested to hear if anyone else has a solution tho...

Thanks

Steve Oliver
0 Likes

Thanks Sanjay

the more i thought about it the more i came to the conclusion that i was limited by the driver / print all sheets method.

i have a clunky workflow i can follow so i should be ok... not quite the one click that i was hoping tho!

be interested to hear if anyone else has a solution tho...

Thanks

Steve Oliver
Message 6 of 8
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
oh Sanjay, anything is possible with computers! (well, almost anything)

Here is my printing macro, and no it doesn't print each page to the same pdf, but it will create a series of pdfs that you can then combine.



-------------------------------------------------------------------

Public Sub PrintDrawingToPDF()

' set printer
Dim sPrinter As String
sPrinter = "Adobe PDF"

' get application
Dim oIVApp As Inventor.Application
Set oIVApp = GetInventor
If oIVApp Is Nothing Then Exit Sub

' get document
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = GetActiveDrawing
If oDrawDoc Is Nothing Then Exit Sub

' get print manager
Dim oPM As DrawingPrintManager
Set oPM = oDrawDoc.PrintManager

If Not DrawingCheckPrinter(oPM, sPrinter) Then
MsgBox "Printer " & sPrinter & " was not found", , "Error"
Exit Sub
End If

' loop thru drawing, printing similar sheets together
Dim oSheet As Sheet
Dim oPaperSize As PaperSizeEnum
Dim oOrientation As PrintOrientationEnum

Dim bflag As Boolean
bflag = False

Dim iStart As Integer
Dim iEnd As Integer
Dim i As Integer
i = 1
While oDrawDoc.Sheets.Count >= i
' set size and orientation
Set oSheet = oDrawDoc.Sheets(i)
Let oPaperSize = DrawingGetPaperSizeFromSheet(oSheet)
Let oOrientation = DrawingGetPrintOrientationFromSheet(oSheet)
iStart = i

' find last consecutive sheet with same size and orientation
bflag = False
While oDrawDoc.Sheets.Count >= i And Not bflag
Set oSheet = oDrawDoc.Sheets(i)
If oPaperSize = DrawingGetPaperSizeFromSheet(oSheet) And _
oOrientation = DrawingGetPrintOrientationFromSheet(oSheet) Then

iEnd = i
i = i + 1 ' increment counter

Else
bflag = True
End If
Wend

' print the sheets
With oPM

.Printer = sPrinter
.AllColorsAsBlack = False
.ColorMode = kPrintColorPalette
.NumberOfCopies = 1
.Orientation = oOrientation
.PaperSize = oPaperSize
.TilingEnabled = False
.PrintRange = kPrintSheetRange
.SetSheetRange iStart, iEnd
.SubmitPrint

End With


Wend

End Sub



Public Function GetActiveDrawing() As DrawingDocument

If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
Set GetActiveDrawing = ThisApplication.ActiveDocument
Else
MsgBox "Must have a drawing active", vbOKOnly, "Error"
End If

End Function




Public Function DrawingGetPaperSizeFromSheet(oSheet As Sheet) As PaperSizeEnum

Dim oPaperSize As PaperSizeEnum
Select Case oSheet.Size
Case kADrawingSheetSize
oPaperSize = kPaperSizeLetter

Case kBDrawingSheetSize
oPaperSize = kPaperSize11x17

Case kCDrawingSheetSize
oPaperSize = kPaperSizeCSheet

Case kDDrawingSheetSize
oPaperSize = kPaperSizeDSheet

Case kEDrawingSheetSize
oPaperSize = kPaperSizeESheet

Case kFDrawingSheetSize
MsgBox "Unknown paper size, print manually", , "Error"
Exit Function

Case kA0DrawingSheetSize
oPaperSize = kPaperSizeA0

Case kA1DrawingSheetSize
oPaperSize = kPaperSizeA1

Case kA2DrawingSheetSize
oPaperSize = kPaperSizeA2

Case kA3DrawingSheetSize
oPaperSize = kPaperSizeA3

Case kA4DrawingSheetSize
oPaperSize = kPaperSizeA4

Case Else
oPaperSize = kPaperSizeDefault
End Select

Let DrawingGetPaperSizeFromSheet = oPaperSize

End Function


Public Function DrawingGetPrintOrientationFromSheet(oSheet As Sheet)

Dim oOrientation As PrintOrientationEnum
Select Case oSheet.Orientation
Case kLandscapePageOrientation
oOrientation = kLandscapeOrientation
Case kPortraitPageOrientation
oOrientation = kPortraitOrientation
Case Else
oOrientation = kDefaultOrientation
End Select

Let DrawingGetPrintOrientationFromSheet = oOrientation

End Function


Public Function DrawingCheckPrinter(oPM As PrintManager, sPrinter As String) As Boolean

On Error Resume Next

oPM.Printer = sPrinter
If Err Then
Err.Clear
DrawingCheckPrinter = False
Else
DrawingCheckPrinter = True
End If

On Error GoTo 0

End Function


Public Function GetInventor(Optional bCreateApp As Boolean = True) As Inventor.Application

On Error Resume Next
Set GetInventor = GetObject(, "Inventor.Application")
If Err Then
Err.Clear

If bCreateApp Then
' ask user to start Inventor
Dim iAns As Integer
iAns = MsgBox("Inventor is not currently running. Would you like to start the program?", vbYesNo)

If iAns = vbYes Then
Set GetInventor = CreateObject("Inventor.Application")
If Not GetInventor Is Nothing Then
GetInventor.visible = True
End If
End If
Else
Set GetInventor = Nothing
End If

End If
On Error GoTo 0

End Function
0 Likes

oh Sanjay, anything is possible with computers! (well, almost anything)

Here is my printing macro, and no it doesn't print each page to the same pdf, but it will create a series of pdfs that you can then combine.



-------------------------------------------------------------------

Public Sub PrintDrawingToPDF()

' set printer
Dim sPrinter As String
sPrinter = "Adobe PDF"

' get application
Dim oIVApp As Inventor.Application
Set oIVApp = GetInventor
If oIVApp Is Nothing Then Exit Sub

' get document
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = GetActiveDrawing
If oDrawDoc Is Nothing Then Exit Sub

' get print manager
Dim oPM As DrawingPrintManager
Set oPM = oDrawDoc.PrintManager

If Not DrawingCheckPrinter(oPM, sPrinter) Then
MsgBox "Printer " & sPrinter & " was not found", , "Error"
Exit Sub
End If

' loop thru drawing, printing similar sheets together
Dim oSheet As Sheet
Dim oPaperSize As PaperSizeEnum
Dim oOrientation As PrintOrientationEnum

Dim bflag As Boolean
bflag = False

Dim iStart As Integer
Dim iEnd As Integer
Dim i As Integer
i = 1
While oDrawDoc.Sheets.Count >= i
' set size and orientation
Set oSheet = oDrawDoc.Sheets(i)
Let oPaperSize = DrawingGetPaperSizeFromSheet(oSheet)
Let oOrientation = DrawingGetPrintOrientationFromSheet(oSheet)
iStart = i

' find last consecutive sheet with same size and orientation
bflag = False
While oDrawDoc.Sheets.Count >= i And Not bflag
Set oSheet = oDrawDoc.Sheets(i)
If oPaperSize = DrawingGetPaperSizeFromSheet(oSheet) And _
oOrientation = DrawingGetPrintOrientationFromSheet(oSheet) Then

iEnd = i
i = i + 1 ' increment counter

Else
bflag = True
End If
Wend

' print the sheets
With oPM

.Printer = sPrinter
.AllColorsAsBlack = False
.ColorMode = kPrintColorPalette
.NumberOfCopies = 1
.Orientation = oOrientation
.PaperSize = oPaperSize
.TilingEnabled = False
.PrintRange = kPrintSheetRange
.SetSheetRange iStart, iEnd
.SubmitPrint

End With


Wend

End Sub



Public Function GetActiveDrawing() As DrawingDocument

If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
Set GetActiveDrawing = ThisApplication.ActiveDocument
Else
MsgBox "Must have a drawing active", vbOKOnly, "Error"
End If

End Function




Public Function DrawingGetPaperSizeFromSheet(oSheet As Sheet) As PaperSizeEnum

Dim oPaperSize As PaperSizeEnum
Select Case oSheet.Size
Case kADrawingSheetSize
oPaperSize = kPaperSizeLetter

Case kBDrawingSheetSize
oPaperSize = kPaperSize11x17

Case kCDrawingSheetSize
oPaperSize = kPaperSizeCSheet

Case kDDrawingSheetSize
oPaperSize = kPaperSizeDSheet

Case kEDrawingSheetSize
oPaperSize = kPaperSizeESheet

Case kFDrawingSheetSize
MsgBox "Unknown paper size, print manually", , "Error"
Exit Function

Case kA0DrawingSheetSize
oPaperSize = kPaperSizeA0

Case kA1DrawingSheetSize
oPaperSize = kPaperSizeA1

Case kA2DrawingSheetSize
oPaperSize = kPaperSizeA2

Case kA3DrawingSheetSize
oPaperSize = kPaperSizeA3

Case kA4DrawingSheetSize
oPaperSize = kPaperSizeA4

Case Else
oPaperSize = kPaperSizeDefault
End Select

Let DrawingGetPaperSizeFromSheet = oPaperSize

End Function


Public Function DrawingGetPrintOrientationFromSheet(oSheet As Sheet)

Dim oOrientation As PrintOrientationEnum
Select Case oSheet.Orientation
Case kLandscapePageOrientation
oOrientation = kLandscapeOrientation
Case kPortraitPageOrientation
oOrientation = kPortraitOrientation
Case Else
oOrientation = kDefaultOrientation
End Select

Let DrawingGetPrintOrientationFromSheet = oOrientation

End Function


Public Function DrawingCheckPrinter(oPM As PrintManager, sPrinter As String) As Boolean

On Error Resume Next

oPM.Printer = sPrinter
If Err Then
Err.Clear
DrawingCheckPrinter = False
Else
DrawingCheckPrinter = True
End If

On Error GoTo 0

End Function


Public Function GetInventor(Optional bCreateApp As Boolean = True) As Inventor.Application

On Error Resume Next
Set GetInventor = GetObject(, "Inventor.Application")
If Err Then
Err.Clear

If bCreateApp Then
' ask user to start Inventor
Dim iAns As Integer
iAns = MsgBox("Inventor is not currently running. Would you like to start the program?", vbYesNo)

If iAns = vbYes Then
Set GetInventor = CreateObject("Inventor.Application")
If Not GetInventor Is Nothing Then
GetInventor.visible = True
End If
End If
Else
Set GetInventor = Nothing
End If

End If
On Error GoTo 0

End Function
Message 7 of 8
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Of course, Josh. It's the combining at the end part that I didn't think of.

Sanjay-
0 Likes

Of course, Josh. It's the combining at the end part that I didn't think of.

Sanjay-
Message 8 of 8
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
>It's the combining at the end part that I didn't think of.

yes it would be super nice if it was possible to do this via API (and it may be with an Add-in). The part I can't figure out is how to feed the names of the .pdf output to the printer (of course if you're printing to a "normal" printer this isn't a problem). There is an Adobe PDF API that can be called by Inventor, unfortunately there is a print dialog that pops up that I can't figure out how to access. Maybe if I was compiling an Add-in, there would be an event to catch, but I'm only using VBA...
0 Likes

>It's the combining at the end part that I didn't think of.

yes it would be super nice if it was possible to do this via API (and it may be with an Add-in). The part I can't figure out is how to feed the names of the .pdf output to the printer (of course if you're printing to a "normal" printer this isn't a problem). There is an Adobe PDF API that can be called by Inventor, unfortunately there is a print dialog that pops up that I can't figure out how to access. Maybe if I was compiling an Add-in, there would be an event to catch, but I'm only using VBA...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report