Print Drawing Depending on Sheetsize

Print Drawing Depending on Sheetsize

Jesper_S
Collaborator Collaborator
651 Views
5 Replies
Message 1 of 6

Print Drawing Depending on Sheetsize

Jesper_S
Collaborator
Collaborator

Hi.

 

I'm trying to create a iLogic code that prints my drawings and depending on what the sheetsize is, it sends it to diffrent printers (A4 & A3 same printer, A2 & A1 diffrent printer) and adjusts the printmanagers sheetsize.

 

Found a post regarding this but can't get it to work. 

https://forums.autodesk.com/t5/inventor-customization/ilogic-print-to-active-sheet-size/td-p/5816292

I get the error "Can't convert the String A3 to Integer"

 

Here is my attempt.

Sub Main()
Dim oDrgDoc As DrawingDocument
oDrgDoc = ThisApplication.ActiveDocument

' Set reference to drawing print manager' DrawingPrintManager has more options than PrintManager' as it's specific to drawing document
Dim oDrgPrintMgr As DrawingPrintManager
oDrgPrintMgr = oDrgDoc.PrintManager

Dim PrinterPlotter = "\\OVO-PRINT01\OVB-HQ-Floor1-Construction-Plotter-01"
Dim PrinterCommon = "\\OVO-PRINT01\OVB-HQ-Floor1-Common-Color-01"
'MessageBox.Show(GetPaperSize(ActiveSheet.Size), "Title")


SheetSize = ActiveSheet.Size
MessageBox.Show(SheetSize, "Title")
If SheetSize = "A4" Then
	oDrgPrintMgr.Printer = PrinterCommon
ElseIf SheetSize = "A3" Then
	oDrgPrintMgr.Printer = PrinterCommon
ElseIf SheetSize = "A2" Then
	oDrgPrintMgr.Printer = PrinterPlotter
ElseIf SheetSize = "A1" Then
	oDrgPrintMgr.Printer = PrinterPlotter
End If
' Set the printer name' comment this line to use default printer or assign another one
'oDrgPrintMgr.Printer = PrinterCommon


'Set the paper size , scale and orientation
oDrgPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale
'oDrgPrintMgr.PaperSize = PaperSizeEnum.kPaperSizeA3
oDrgPrintMgr.PaperSize = GetPaperSize(ActiveSheet.Size)
oDrgPrintMgr.PrintRange = kPrintAllSheets
oDrgPrintMgr.Orientation = kLandscapeOrientation
oDrgPrintMgr.AllColorsAsBlack = True
oDrgPrintMgr.SubmitPrint
End Sub

Function GetPaperSize(shtSize As DrawingSheetSizeEnum) As PaperSizeEnum
    'Add a line for each sheet and papersize combination
    If shtSize = DrawingSheetSizeEnum.kA0DrawingSheetSize Then Return PaperSizeEnum.kPaperSizeA0
End Function

 

Thanks in advance


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Accepted solutions (1)
652 Views
5 Replies
Replies (5)
Message 2 of 6

JhoelForshav
Mentor
Mentor

Hi @Jesper_S 

 

Sheet.Size is of type DrawingSheetSizeEnum (Integer), not String.

 

Instead of

If SheetSize = "A4"

It should be

If SheetSize = DrawingSheetSizeEnum.kA4DrawingSheetSize

And so on for all the different sizes 🙂

0 Likes
Message 3 of 6

Jesper_S
Collaborator
Collaborator

Hi.

 

Thanks for your answer.

 

But I think that it's the Function that's the issue and the Calling Out for the sheetsize.

oDrgPrintMgr.PaperSize = GetPaperSize(ActiveSheet.Size)

If I comment this out and use

oDrgPrintMgr.PaperSize = PaperSizeEnum.kPaperSizeA3

it works.

 

The first section of "If" is to select the correct printer. 

If it's A4 & A3, select the common printer.

If it's A2 & A1, select the plotter.


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 4 of 6

JhoelForshav
Mentor
Mentor
Accepted solution

I see now that you used

ActiveSheet.Size

which in fact is a string...

ActiveSheet is of type ICadDrawingSheet and Not Sheet.

 

Your function GetPaperSize however takes an argument of type DrawingSheetSizeEnum but you call it with argument ActiveSheet.Size which is a string.

 

Try changing

oDrgPrintMgr.PaperSize = GetPaperSize(ActiveSheet.Size)

To

oDrgPrintMgr.PaperSize = GetPaperSize(ActiveSheet.Sheet.Size)

 

Message 5 of 6

JhoelForshav
Mentor
Mentor

And the function like this i suppose? 🙂

 

Function GetPaperSize(shtSize As DrawingSheetSizeEnum) As PaperSizeEnum
	'Add a line for each sheet and papersize combination
	If shtSize = DrawingSheetSizeEnum.kA0DrawingSheetSize Then Return PaperSizeEnum.kPaperSizeA0
	If shtSize = DrawingSheetSizeEnum.kA1DrawingSheetSize Then Return PaperSizeEnum.kPaperSizeA1
	If shtSize = DrawingSheetSizeEnum.kA2DrawingSheetSize Then Return PaperSizeEnum.kPaperSizeA2
	If shtSize = DrawingSheetSizeEnum.kA3DrawingSheetSize Then Return PaperSizeEnum.kPaperSizeA3
	If shtSize = DrawingSheetSizeEnum.kA4DrawingSheetSize Then Return PaperSizeEnum.kPaperSizeA4
End Function
Message 6 of 6

Jesper_S
Collaborator
Collaborator

Sweet, Thanks.

 

Worked like  charm.

Only problem I got now is that the Plotter Printer has crashed so I can't test the code on that one....

Our IT is trying to fix it, software issue...

 

But i think that the code will do the job. 

 

Thanks once again.

 

 

EDIT: Yes the function should look like that.. have changed it, saw your reply after I posted.


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.