VBA Printer options not affecting print

VBA Printer options not affecting print

pball
Mentor Mentor
5,656 Views
27 Replies
Message 1 of 28

VBA Printer options not affecting print

pball
Mentor
Mentor

I've noticed weird behavoir with this code to print drawings since I've started to use it, but I've never really tried getting to the bottom of it since it not usually a problem. The problem is I'll set certain options and then they aren't applied to the print job.

 

I don't know if I'm doing something wrong, but this code I found doesn't want to change the paper size and color options.

 

When set it to use 11x17 paper it will print 8.5x11 which is the default size for the printer. So if I change the printer options to default to 11x17 it will print with 11x17. Changing the color between color, greyscale, and blackandwhite don't affect the prints either.

 

Also is there a way to detect the default printer since I noticed when I "printed" a pdf manually and then tried this script it used the pdf printer and not the default printer, which I would always want to use.

 

 

Public Sub Single_Print_11x17()

    Dim oPrintMgr As PrintManager
    Set oPrintMgr = ThisApplication.ActiveDocument.PrintManager

    If MsgBox("Using default printer """ & oPrintMgr.printer & """ with 11x17 paper.  Do you want to continue?", vbYesNo + vbQuestion) = vbNo Then Exit Sub

    Print_doc printer:=oPrintMgr.printer, paper:=kPaperSize11x17, black_white:=True

End Sub

 If you notice that i'm not using two of the arguements in the function that are passed, that's because they don't appear to affect anything so I just left some of it hard coded. When/if I can get the different options working I'll start using the arguements more since I have plans.

 

Function Print_doc(ByVal printer As String, ByVal paper As String, ByVal black_white As Boolean)
    If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then Exit Function

    Dim oDrgDoc As DrawingDocument
    Set oDrgDoc = ThisApplication.ActiveDocument

    Dim oDrgPrintMgr As DrawingPrintManager
    Set oDrgPrintMgr = oDrgDoc.PrintManager

    'choose printer works
    oDrgPrintMgr.printer = printer
    'choose sheets works
    oDrgPrintMgr.PrintRange = kPrintAllSheets
    'choose size doesn't work
    oDrgPrintMgr.PaperSize = kPaperSize11x17
    'choose scale works
    oDrgPrintMgr.ScaleMode = kPrintBestFitScale
    'color/black & white don't work
    oDrgPrintMgr.ColorMode = kPrintGrayScale
    oDrgPrintMgr.AllColorsAsBlack = black_white
    oDrgPrintMgr.SubmitPrint
End Function

 

I'd love to get all these options working since I want to be able to select size and color options when using my print scripts.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style

Userscript to edit forum links to jump to first unread post
Jump To First Post Userscript
0 Likes
5,657 Views
27 Replies
Replies (27)
Message 21 of 28

sergio_duran
Advocate
Advocate

Hi Adam,

 

I created an iLogic to print and it allows me to select any paper size. In fact, the ilogic rule and API Macro are exactly the same (just little tweaks to adjust to iLogic syntax). Ilogic rule works very well.

0 Likes
Message 22 of 28

adam.nagy
Autodesk Support
Autodesk Support

Would you mind pasting both sample code here for reference?



Adam Nagy
Autodesk Platform Services
0 Likes
Message 23 of 28

sergio_duran
Advocate
Advocate

Hi Adam,

I've attached both iLogic and VBA codes. BTW, I've tried with both numbers and names in my VBA code when changing the paper size (e.g. kPaperSizeDSheet or 14347)

Thanks for your help!

0 Likes
Message 24 of 28

adam.nagy
Autodesk Support
Autodesk Support

Thank you!

 

In case of the iLogic code you are first selecting the printer and then set the size (which sounds more logical) whereas in VBA you first set the size and then you change the printer.

 

Could you please test the exact same workflow in VBA that you follow in the iLogic code? - I wonder if that makes a difference.  



Adam Nagy
Autodesk Platform Services
Message 25 of 28

sergio_duran
Advocate
Advocate

Hi Adam,

It worked! I changed the order in VBA and worked (first the printer and then set the size). Sorry for the late reply, I couldn't test it at the beginning of the week.

 

Thank you so much for your help! That simple solution fixed my VBA code.

0 Likes
Message 26 of 28

Anonymous
Not applicable

Hi,

I have to print the PDF file which is stored on my PC. File name and path name are known.

I just need help to send that PDF file to printer by setting following printer parameters,

1. Printer Name

2. Orientation

3. Paper Size

4. Print on Both side (either flip on long edge or flip on short edge)

This I have to do it in the AutoCAD VBA only.

Your help is highly appreciated

 

 

 

0 Likes
Message 27 of 28

Anonymous
Not applicable

Hi,

I have to print the PDF file which is stored on my PC. File name and path name are known. I just need help to send that PDF file to printer by setting following printer parameters,

1. Printer Name 2. Orientation 3. Paper Size 4. Print on Both side (either flip on long edge or flip on short edge)

This I have to do it in the AutoCAD VBA only. Your help is highly appreciated  

0 Likes
Message 28 of 28

adam.nagy
Autodesk Support
Autodesk Support

Since you said "AutoCAD VBA" I assume you are using AutoCAD and not Inventor - this section of the forum is for Inventor.

 

However, this should help for AutoCADhttps://forums.autodesk.com/t5/vba/vba-printing-to-pdf/td-p/8349492



Adam Nagy
Autodesk Platform Services
0 Likes