Jump to content

How to change printer and number of printed copies


jimfx
 Share

Recommended Posts

Hi All,

I am NOOB and I made an AutoIT script to automate printing a PDF file (2x) on a different printer. It works but it looks a bit clumsy. I'll show a part of the script (don't laugh plz)

Opt("WinTitleMatchMode", 2)

WinWaitActive("Adobe Reader")

; print command

Send ("!b")

Send ("r")

WinWaitActive("Print","")

; when pressing 5 times the down arrow key, the appropiate printer will be selected, (Xerox Phaser 3130 PCL 6 on Ne00:) then press 5x the TAB key to go to

;the number of copies to print

Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{TAB}{TAB}{TAB}{TAB}{TAB}")

sleep (500)

Send("2")

; press 7x TAB and hit ENTER to continue

Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}")

etc.

Can somebody please help me with a more robust script. When the order of printers changes, the whole procedure fails. I hope there is a better way to change printer and number of printed copies.

Many thanks in advance!

Jim

Link to comment
Share on other sites

You could use the AutoItInfo tool to find out what the instances are of the combobox for the printer list is, and the edit for the numnber of copies. Then, instead of using tab to get to the correct control use ControlFocus. Instead of using the down arror to get to the printer, which as you say is unreliable, either Send the printer name to select it, or use ControlCommand.

Here is something very similar I did for printing files in a CAD program to pdf which might help. (The way I did it might not be the best either but it worked fine which is where I loose interest.)

;script to print all the drawings in the CAD program to pdf 
While 1
    $outPath = "C:\CAD\" & $Customer & "\pdfs\";
    WinActivate("TurboCAD")
    $TCTitle = WinGetTitle("TurboCAD Professional")
    
    $drawing = _StringBetween($TCTitle, "[", ".tcw");the drawing displayed has it's file name in the title
    If Not IsArray($drawing) Then Exit;no drawings left to print?
    Send("!fp");select print
    If WinWaitActive("Print", "", 5) = 0 Then Exit
    ControlFocus("Print", "", "ComboBox1");select the printer list combo
    Send("CutePDF Writer");this is the printer I want
    Send("!1");fit on 1 page;only relevant for some printers?
    Send("{ENTER}");start printing
;ConsoleWrite("Will wait for Save As" & @CRLF)
    If WinWait("Save As", "", 5) = 0 Then Exit;something went wrong
    Sleep(200)
    ControlFocus("Save As", "", "Edit1")
    Sleep(200)
    
    Send($outPath & $drawing[0] & ".pdf");write the filename and path
    Send("{ENTER}");start it saving
    Sleep(400)
    $wtext = WinGetText("Save As")
    If StringInStr($wtext, "already exists") Then
        Sleep(1000)
        
        Send("{Y");ENTER}");yes overwrite
    EndIf
    Sleep(2000)
    WinActivate("TurboCAD");back to CAD
    Send("!fc");close that file because it's printed and we'll do the next
    Sleep(500)
    $count = 0
     ;check the last pdf was actually created
    While Not FileExists($outPath & $drawing[0] & ".pdf")
        Sleep(300)
        $count += 1
        If $count > 20 Then
            MsgBox(262144, "Error", "Failed to create file" & _
                    $outPath & $drawing[0] & ".pdf")
            Exit;oh dear!
        EndIf
        
    WEnd
WEnd

EDIT:

Oh, welcome to the AutoIt forums :)

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

To select the printer I use the following code (where $Window holds the Title of the Acrobat Reader "Print" Window:

$RC = ControlCommand($Window,"",1139,"SelectString",$Printer)
    If @error Then
        MsgBox(4096, @ScriptName,"Printer '" & $Printer & "' is not defined")
        $RC = WinWaitActive($Window,"")
        $RC = Send("{ESC}")
        _ClosePDF("")
        SetError(2)
        Return
    EndIf
    ; Rotate and center the printout
    $RC = ControlCommand($Window,"",563,"Check","")
    ; Set number of copies
    $RC = ControlSetText($Window,"",1154,$copies)
    ; Press "OK" Button
    $RC = ControlClick($Window,"",1)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I have a very simple solution to this..

I personally don't like mouse clicks and key sends, coz it can be real messy if there's any user input. and the beauty of any script is to make it run in the background, providing the user to do whatever he wants to do, and without disturbing him in any way.

Hence i suggest u use this. Works fine for me. n its quite easy to do thru autoit too, using the @comspec macro. or just running a batch file.

Edited by Manjish
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

I also had similar automation about printing a document

Try this code:

WinActivate("Adobe Reader",'')
Sleep(1000)
send("!fp")
WinWaitActive("Print",'')
Sleep(100)

;============Make a loop here for multiple printer to print===========================

ControlFocus("Print","","[CLASS:ComboBox; INSTANCE:1]"); set the focus to combo box
Sleep(10)
ControlCommand("Print","","[CLASS:ComboBox; INSTANCE:1]","SelectString",'Printer Name'); select the printer name 
Sleep(10)
ControlFocus("Print","","[CLASS:Edit; INSTANCE:2]"); set the focus to Copies combo box
Sleep(10)
ControlSetText("Print","","[CLASS:Edit; INSTANCE:2]",""); clear this default value of the Copies combo box
Sleep(10)
ControlCommand("Print","","[CLASS:Edit; INSTANCE:2]",EditPaste",'5'); set to 5 copies
Sleep(10)
ControlCommand("Print","","[CLASS:Button; TEXT:OK; INSTANCE:1]",); set the focus onOK button
Sleep(10)
ControlCommand("Print","","[CLASS:Button; TEXT:OK; INSTANCE:1]","Check", ""); click the OK button to print
;============End of loop here for multiple printer to print===========================

Exit

You can used AutoIt window info and used the ControlCommand function. it's very helpful.

let me know if this doesn't work so that I could review my programs... :)

Edited by nfaustin
[font="Palatino Linotype"][size="2"]*** The information contained in this post should be considered and certified WORKS ON MY MACHINE ***[/size][/font][font="Palatino Linotype"][size="2"] [/size][/font]
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...