AutoIT routine and FORM printing

More advanced topics discussed.

Moderators: Susan Smith, admin, Gabriel

Post Reply
gtisdale
Posts: 218
Joined: Sun Jun 07, 2009 7:54 am
Location: Concord, Massachusetts
Contact:

AutoIT routine and FORM printing

Post by gtisdale »

I have needed a way to automatically create a PCL overlay and send it to a file for later printing. The BIG hang-up was how to tell BR which is going to store the file what print file name was given to the PCL output file when it was printed using the HP6L driver.

Gordon suggested that maybe AUTOIT would be a solution.

It was/is. Many things in Autoit that I thought would work did not, but there are so many options that I just tried other ways of getting to the end result. The examples in the tutorial were not a lot of help, unless I was just interested in displaying messages or writing text files using notepad.

I like AUtoIT a lot and it does the job. I am posting here the script that I finally used to accomplish the task. The BIG help was John Bowman's suggestion to use SLEEP for half-second intervals to allow the computer to finish tasks that I has set.

What I am doing in the BR / AutoIt routine is:
1.In my FORMFILL program I create or update a form that references a PDF file and a page within the file to use as a PDF "background" when the form is printed.
2. If the PDF file and page are specified I look into my related PCL forms library to see if the form with the same name exists.
3. If the form does not exists in the PCL library I call a function that
a. Runs the compiled Autoit routine to load acrobat, load the pdf file, print the selected page to the HP6L(file) driver and give it a .PRN name the same as the form that is being created
b. BR then opens the PRN file, strips the initialization parameters and replaces the top margin specification and eliminates the end of job characters
c. stores the changed PRN file in my forms library in 32000 bit chunks for reprinting
d. restructures and renumbers all of the stored macros so that they each have a different number

You can see all of this happening on the screen as the form flashes across the screnn doing the various pieces, but it all works without interruption and returns me to the original spot wher I can continu on with building the form.

For those who have not iused AUTOIT yet, the following scriopt with annotaions may be helpful as a tutorial in making Autoit wiork for you.

(The semi-colons are comment lines)

;Remove any pre-existing destination file to prevent REPLACE dialogue from occurring later
If FileExists( $CmdLine[1]&"\"&$CmdLine[4]&".prn") Then
FileDelete( $CmdLine[1]&"\"&$CmdLine[4]&".prn")
EndIf
;Load and run Acrobat Reader
run ("C:\Program Files\Adobe\Reader 9.0\Reader\acrord32.exe") ; $CmdLine[1] )
;Wait for Acrobat Reader to become active
WinWaitActive("Adobe Reader")
;Send key strokes to activate FILE/OPEN menu item
Send("!fo")
;Wait for the OPEN file dialogue window to become active
WinWaitActive("Open")
;Send command line PARAMETER 1 to the PATH combobox of the open dialogue window
ControlSend("Open", "", "[ClassNN: ComboBox1]", $CmdLine[1])
;Wait 1/2 second for the above action to complete
Sleep(500)
;Send command line PARAMETER 2 to the FILE NAME edit box of the OPEN dialogue window
ControlSetText("Open", "", "CLASS:Edit1", $CmdLine[2])
;For some reason the above command only sets focus to Edit1 so send the keystrokes
Send($Cmdline[2])
;The keystrokes have now been placed in the edit box so press ENTER to accept
Send("{ENTER}")
;Wait for Adobe Reader to be active again meaning that the PARAMETER 2 file haas been loaded
WinWaitActive("Adobe Reader")
;Send the menu instruction File/Print to Adobe Reader
Send("!fp")
;Wait for the PRINT dialogue window to become active
WinWaitActive("Print")
;The defaultfocus is on the PRINTER NAME so send the name of the required printer
;I have preset the HP6L(file) printer to be defaulted to printing to a file so I send this selection
Send("hp6l(file)")
;Wait 1/2 second for the selection to take place
Sleep(500)
;Send the command line PARAMETER 3 (page number of the PDF file to print) to the Edit Box
ControlSetText("Print", "", "[CLASSNN:Edit1]", $Cmdline[3])
;Send the ENTER key stroke to the PRINT Button on the dialogue box
ControlSend("Print", "", "[CLASSNN:Button2]","{ENTER}") ;
;Wait for the PRINT TO FILE Dialogue to appear
WinWaitActive("Print To File")
;Send the output file name PARAMTER 4 to the PRINT TO FILE window text box and append a .PRN
ControlSetText("Print To File","","[CLASSNN:Edit1]",$CmdLine[4]&".prn")
;Wait 1/2 second for the file name to be inserted into the dialogue box
Sleep(500)
;Send the ENTER key stroke to accept the inserted name and casue the print routine to occur
Send("{ENTER}")
;Wait 5 seconds for the print job to finish
Sleep(5000)
;Close Acrobat Reader
ProcessClose ( "acrord32.exe")
Susan Smith
Posts: 717
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Post by Susan Smith »

Thanks for posting this George. I have always wanted to have a presentation on AUTOIT at a BRG conference because I have a feeling that there is some amazing functionality that we could pull from it for our BR systems.

Maybe I'll put that on the wish list for 2011!

-- Susan
gordon
Posts: 358
Joined: Fri Apr 24, 2009 6:02 pm

Post by gordon »

There are several things we can do in BR to better support AutoIt. I have become aware of some of them as a result of some automation we are doing.

I have slated some significant AutoIt changes for 4.3. I'm only mentioning it now so people don't feel they need to work though the anomalies now, not knowing that significant changes are underway.
Post Reply