Printing with VB .Net

Printing with VB .Net

GeorgK
Advisor Advisor
2,403 Views
7 Replies
Message 1 of 8

Printing with VB .Net

GeorgK
Advisor
Advisor

Hello together,

 

is there a complete sample for printing on different printers, paper size, scale mode, sheets, orientation, color, line weights, preview and paper source?

 

Thank you very much

 


Georg

0 Likes
Accepted solutions (1)
2,404 Views
7 Replies
Replies (7)
Message 2 of 8

skyngu
Collaborator
Collaborator

no, there is not a complete sample.

Autodesk Inventor Professional 2019
0 Likes
Message 3 of 8

GeorgK
Advisor
Advisor

Do you have some examples?

0 Likes
Message 4 of 8

Anonymous
Not applicable
Accepted solution

This code is used for printing to 3 different printers, please note that the identification of paper size and oreintation is done by checking the boarder size which I am using. change it accordingly.

 Private Sub oButtonAutoPrint_OnExecute(Context As Inventor.NameValueMap) Handles oButtonAutoPrint.OnExecute
            Try
                Dim oDoc As Inventor.DrawingDocument
                oDoc = m_inventorApplication.ActiveDocument

                Dim oSheet As Inventor.Sheet
                oSheet = oDoc.ActiveSheet

                Dim oPM As Inventor.PrintManager
                oPM = oDoc.PrintManager

                Dim strPrinter As String = Nothing

                If oSheet.Border.Name = "IP-A4R" Then
                    oPM.Printer = "HP LaserJet 1022"
                    oPM.ColorMode = PrintColorModeEnum.kPrintGrayScale
                    oPM.PaperSize = PaperSizeEnum.kPaperSizeA4
                    oPM.Orientation = PrintOrientationEnum.kLandscapeOrientation
                    oPM.NumberOfCopies = 1
                    oPM.scalemode = Inventor.PrintScaleModeEnum.kPrintBestFitScale
                    oPM.printrange = Inventor.PrintRangeEnum.kPrintCurrentSheet
                    oPM.RemoveLineWeights = True
                ElseIf oSheet.Border.Name = "IP-A4" Then
                    oPM.Printer = "HP LaserJet 1022"
                    oPM.ColorMode = PrintColorModeEnum.kPrintGrayScale
                    oPM.PaperSize = PaperSizeEnum.kPaperSizeA4
                    oPM.Orientation = PrintOrientationEnum.kPortraitOrientation
                    oPM.NumberOfCopies = 1
                    oPM.scalemode = Inventor.PrintScaleModeEnum.kPrintBestFitScale
                    oPM.printrange = Inventor.PrintRangeEnum.kPrintCurrentSheet
                    oPM.RemoveLineWeights = True
                ElseIf oSheet.Border.Name = "IP-A3" Then
                    oPM.Printer = "HP Officejet Pro K850 Series"
                    oPM.ColorMode = PrintColorModeEnum.kPrintColorPalette
                    oPM.PaperSize = PaperSizeEnum.kPaperSizeA3
                    oPM.Orientation = PrintOrientationEnum.kLandscapeOrientation
                    oPM.NumberOfCopies = 1
                    oPM.scalemode = Inventor.PrintScaleModeEnum.kPrintBestFitScale
                    oPM.printrange = Inventor.PrintRangeEnum.kPrintCurrentSheet
                    oPM.RemoveLineWeights = True
                ElseIf oSheet.Border.Name = "IP-A2" Then
                    oPM.Printer = "HP Designjet 500 42+HPGL2 Card"
                    oPM.ColorMode = PrintColorModeEnum.kPrintColorPalette
                    oPM.PaperSize = PaperSizeEnum.kPaperSizeA2
                    oPM.Rotate90Degrees = True
                    oPM.Orientation = PrintOrientationEnum.kPortraitOrientation
                    oPM.NumberOfCopies = 1
                    oPM.scalemode = Inventor.PrintScaleModeEnum.kPrintBestFitScale
                    oPM.printrange = Inventor.PrintRangeEnum.kPrintCurrentSheet
                    oPM.RemoveLineWeights = True
                ElseIf oSheet.Border.Name = "IP-A1" Then
                    oPM.Printer = "HP Designjet 500 42+HPGL2 Card"
                    oPM.ColorMode = PrintColorModeEnum.kPrintColorPalette
                    oPM.PaperSize = PaperSizeEnum.kPaperSizeA1
                    oPM.Rotate90Degrees = True
                    oPM.Orientation = PrintOrientationEnum.kPortraitOrientation
                    oPM.NumberOfCopies = 1
                    oPM.scalemode = Inventor.PrintScaleModeEnum.kPrintBestFitScale
                    oPM.printrange = Inventor.PrintRangeEnum.kPrintCurrentSheet
                    oPM.RemoveLineWeights = True
                ElseIf oSheet.Border.Name = "IP-A0" Then
                    oPM.Printer = "HP Designjet 500 42+HPGL2 Card"
                    oPM.ColorMode = PrintColorModeEnum.kPrintColorPalette
                    oPM.PaperSize = PaperSizeEnum.kPaperSizeA0
                    oPM.Rotate90Degrees = True
                    oPM.Orientation = PrintOrientationEnum.kPortraitOrientation
                    oPM.NumberOfCopies = 1
                    oPM.scalemode = Inventor.PrintScaleModeEnum.kPrintBestFitScale
                    oPM.printrange = Inventor.PrintRangeEnum.kPrintCurrentSheet
                    oPM.RemoveLineWeights = True
                End If

                oPM.SubmitPrint()

                If oSheet.Border.Name = "IP-A2" Then
                    MsgBox("Please Load A2 Paper (Portrait) on " & strPrinter, MsgBoxStyle.Information, " Automated Printing")
                ElseIf oSheet.Border.Name = "IP-A1" Then
                    MsgBox("Please Load A1 Paper (Portrait) on " & strPrinter, MsgBoxStyle.Information, " Automated Printing")
                ElseIf oSheet.Border.Name = "IP-A0" Then
                    MsgBox("Please Load A0 Paper (Roll) on " & strPrinter, MsgBoxStyle.Information, " Automated Printing")
                End If

            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub

 

0 Likes
Message 5 of 8

GeorgK
Advisor
Advisor

Thank you very much for your example.

0 Likes
Message 6 of 8

j_kleijnjansY73VU
Participant
Participant

Hello

I try to put your code in VB but unfortunately I get an error message.

I can not find out what is wrong. Perhaps you can help me

Regards Jos

 

j_kleijnjansY73VU_0-1726819197993.png

 

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor

Hi @j_kleijnjansY73VU.  The error is saying that it does not recognize the "m_inventorApplication" variable you are trying to use.  That local variable is supposed to be 'declared' at the Class level, at same level as the Sub routine which you are trying to use that variable within, or at a higher level, so that you can access it from within all the Sub/Function routines defined within that Class.  It is supposed to represent the Inventor.Application object.  If you already have a local variable which represents an instance of the Inventor.Application object, but it is spelled differently, then use that variable there instead.

 

Also, when you know you are working with a DrawingDocument, instead of some other type of Inventor Document, then you could be working with the DrawingPrintManager type, instead of the regular PrintManager type.  The DrawingPrintManager is a type that is derived from the PrintManager type, and is obviously specific for drawings, and has a lot more properties and methods available to it, that are unique to drawings.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 8

j_kleijnjansY73VU
Participant
Participant

I'm going to try to solve this. I don't know much about programming myself.
Yes it worked👍 thanks

0 Likes