New to VB - Send Drawing to Printer

New to VB - Send Drawing to Printer

Anonymous
Not applicable
941 Views
3 Replies
Message 1 of 4

New to VB - Send Drawing to Printer

Anonymous
Not applicable

I am brand new to Visual Basic so I am sorry if this question seems really simple.

 

I need to setup and addin that when you save a file it checks if that file is a drawing and if it is then it prints the file.

 

I got the code working to fire when a file is saved and the file is a drawing file so I don't need help there but I can't seem to find the proper code to get it to send the file to the printer.

 

Any help would be much appreciated.

 

Also after I get this function working properly I would like to add the functionality to save the flat pattern as a .dxf on save for .ipt files. If any one has any sugestions on that it would be appreciated also.

 

Thanks

Ryan

0 Likes
942 Views
3 Replies
Replies (3)
Message 2 of 4

Ralf_Krieg
Advisor
Advisor

Hello

 

Taken from the Inventor programmers help:

 

Public Sub PrintDrawing()
    ' Set a reference to the print manager object of the active document.
    ' This will fail if a drawing document is not active.
    Dim oPrintMgr As DrawingPrintManager
    Set oPrintMgr = ThisApplication.ActiveDocument.PrintManager
    
    ' Get the name of the printer that will be used.
    If MsgBox("Using printer """ & oPrintMgr.Printer & """  Do you want to continue?", vbYesNo + vbQuestion) = vbNo Then
        ' Change to another printer.
        Dim sPrinterName As String
        sPrinterName = InputBox("Enter name of new printer:", "New Printer")
        If sPrinterName = "" Then
            Exit Sub
        Else
            oPrintMgr.Printer = sPrinterName
        End If
    End If
    
    ' Set to print in color.
    oPrintMgr.ColorMode = kPrintColorPalette
    
    ' Set to print two copies.
    oPrintMgr.NumberOfCopies = 2
    
    ' Set to print using portrait orientation.
    oPrintMgr.Orientation = kPortraitOrientation
    
    ' Set the paper size.
    oPrintMgr.PaperSize = kPaperSize11x17
        
    ' Set to print all sheets.
    oPrintMgr.PrintRange = kPrintAllSheets
    
    ' Set to print full scale.
    oPrintMgr.ScaleMode = kPrintFullScale
    
    ' Submit the print.
    oPrintMgr.SubmitPrint
    
    ' Change the number of copies to 1.
    oPrintMgr.NumberOfCopies = 1
    
    ' Change the paper size to a custom size.  The units are in centimeters.
    oPrintMgr.PaperSize = kPaperSizeCustom
    oPrintMgr.PaperHeight = 15
    oPrintMgr.PaperWidth = 10
    
    ' Get and set the current sheet range.
    Dim iFromSheet As Long
    Dim iToSheet As Long
    Call oPrintMgr.GetSheetRange(iFromSheet, iToSheet)

    MsgBox "Current sheet range is " & iFromSheet & " to " & iToSheet & Chr(13) & _
            "Setting to print sheets 1-2."
        
    ' Change the print range to print sheets 1 through 2.
    oPrintMgr.PrintRange = kPrintSheetRange
    Call oPrintMgr.SetSheetRange(1, 2)
    
    ' Submit the print.
    oPrintMgr.SubmitPrint
End Sub


or for all sheets in a drawing


Public Sub PlotAllSheetsInDrawing()
    'Print all sheets in drawing document
    'Get the active document and check whether it's drawing document
    If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
        
        Dim oDrgDoc As DrawingDocument
        Set 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
        Set oDrgPrintMgr = oDrgDoc.PrintManager
        ' Set the printer name
        ' comment this line to use default printer or assign another one
        oDrgPrintMgr.Printer = "HP LaserJet 4000 Series PCL 6"
        
        'Set the paper size , scale and orientation
        oDrgPrintMgr.ScaleMode = kPrintBestFitScale
        oDrgPrintMgr.PaperSize = kPaperSizeA4
        oDrgPrintMgr.PrintRange = kPrintAllSheets
        oDrgPrintMgr.Orientation = kLandscapeOrientation
        oDrgPrintMgr.SubmitPrint
    End If
End Sub

 

And the sheetmetal export as dxf:

 

Public Sub WriteSheetMetalDXF()

    ' Get the active document.  This assumes it is a part document.
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument

    ' Get the DataIO object.
    Dim oDataIO As DataIO
    Set oDataIO = oDoc.ComponentDefinition.DataIO

    ' Build the string that defines the format of the DXF file.
    Dim sOut As String
    sOut = "FLAT PATTERN DXF?AcadVersion=R12&OuterProfileLayer=Outer"

    ' Create the DXF file.
    oDataIO.WriteDataToFile sOut, "C:\temp\flat2.dxf"
End Sub


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 4

Anonymous
Not applicable

Thank you very much. This solved my problem. I am having trouble finding the inventor programmers help though. Is it something that I need to look for online or is it attached to inventor?

0 Likes
Message 4 of 4

Ralf_Krieg
Advisor
Advisor

Hello

 

If you expand the help menu (the little black triangle beside the Help-Button) in Inventor there's a entry "... resources". I don't know the english name, cause I'm using a german version. In this submenu you'll find the programmers help.

Another resource is the folder "SDK" in your Inventor installation folder. There you'll find samples and a PDF/DWF of the Inventor object model. This one is very helpful to get an overview.

You can also take a look at the webcast archive under http://www.adskconsulting.com/adn/cs/api_course_webcast_archive.php and of course Brian Ekin's Blog at http://modthemachine.typepad.com/.

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes