qwiqshot

Detect and pause while printing

15 posts in this topic

Could someone provide me with an example of how to successfully pause a script after activating a print process, that would detect that the next print process cannot be initiated yet, until the current job has processed please.

I am new so be gentle, lol (See video for what I am referring to. I click print and then must wait until windows says its ready to initiate the next print job, forgive the quality, it was recorded from my cell phone).

This should illustrate what my issue is

Share this post


Link to post
Share on other sites



Hi.

 

Maybe shellexecutewait(), using "print" as verb, will do the trick for you?

 

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Thank you for replying rudi

As I stated I am very new to AutoIT and scripting.

Thank you for pushing me in a possible direction to figure this out. I will start reading about  shellexecutewait() to see if I can get this to work !

Share this post


Link to post
Share on other sites

Hmm

It appears that shellexecutewait runs a program (Runs an external program using the ShellExecute API and pauses script execution until it finishes)

what I am doing is creating a script that clicks a pre existing Macro buttons then waits for the print process to end and then prints the next button. The excel sheet is extremely extensive. 57 tabs of pre defined math calculations & job functions, that gets inserted, depending on which job type tab I am in at the time of composing a contract, so the  ShellExecuteWait doesn't seem the right direction. I may be wrong.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I believe what is holding it up is the printer itself. While standing next to the printer and my finger on the PrtScn button, I hit capture as it shows Not Responding  (Red Text showing up with Excel) and can hear the printer firing up. The moment the printing starts, the red text goes away and I can then print the next document.

 

How do I go about pausing a script in this situation?

red.png

Edited by qwiqshot

Share this post


Link to post
Share on other sites

Hi.

Propably you will need to "cleanup" the excel sheet itself. Avoid too many "chain calculations" across cells.

Or disable the feature "re-calculate all cells on printing" (something like that, no clue, what's the proper English message)

 

Excel will speed up quite a lot, when you use "Range-Formula-Definitions".

  • Mark the range, that will have same formulars for that range
  • Enter the formula to the first cell
  • press CTRL+SHIFT+ENTER to save the formula: This way it will be in the sheet just once. Notice the "curled backets", they point out, that this is a "range formula"

 

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

I have a spreadsheet printing to a network printer that is having similar delay issues. My spreadsheet is very small so I doubt its the spreadsheet. Its been a while since I have tried detecting the point the process is released so I can setup a script to continue once the process is released, but I'm confident it IS possible. I too am not highly experienced with AutoIT, so sadly I am not able to point out the scripting to get this up and running.

Share this post


Link to post
Share on other sites

Have a look at this thread.  It should get you started on what you want to do.  

 

Adam

 

Share this post


Link to post
Share on other sites

I also found this article that might help. It seems way more to what qwiqshot is trying to do

 

 

 

Share this post


Link to post
Share on other sites

Thank you all for replying. I have bunched this up, I think it has me on the right track.

My next step would be to learn how to pause the script until the file in the directory no longer exists then resume once gone

I ran this on my local machine with a txt file in the Printers directory named hi.txt and it does acknowledge it's presence. If I change the required file name, it does correctly says the file does not exist. so I'm excited i'm making progress.

Any suggestions moving forward?

 

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Spoolcheck()

Func Spoolcheck()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = "\WINDOWS\system32\spool\PRINTERS\*.txt"

    Local $iFileExists = FileExists($sFilePath)

    ; Display a message of whether the file exists or not.
    If $iFileExists Then
        MsgBox($MB_SYSTEMMODAL, "", "The file exists." & @CRLF & "FileExist returned: " & $iFileExists)
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The file doesn't exist." & @CRLF & "FileExist returned: " & $iFileExists)
    EndIf
 EndFunc   ;==>Spoolcheck

 

Share this post


Link to post
Share on other sites

p.s. Are wildcards used in file systems allowed?

i.e. 

"\WINDOWS\system32\spool\PRINTERS\*.*"

Share this post


Link to post
Share on other sites

Hm.

 

That's really hard to figure out ;-) as it's not explicitely mentioned in the help file, eh?

 

$f=FileOpen("C:\temp\Wildcard-check.txt",2+8)
FileWriteLine($f,"Just a file, leave me alone!")
FileClose($f)


if FileExists("C:\temp\*.txt") Then
    MsgBox(0,"Wildcard Check","Is allowed")
Else
    MsgBox(0,"Wildcard Check","Is not allowed")
EndIf

 

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Touche Rudi :lol:

 

I monitored the \Windows\system32\spool\PRINTERS\ directory most of the day today for ever print job, while also running Process Explorer. The files that are generated by printing increase in numeric naming and do not remain static, so monitoring a specific file would be impossible, it would infact require a wildcard like *.SHD (<-- SHD is the file extension it generates). Sadly the files is only there a few milliseconds, so detecting its presence then disappearance may be impossible.

However, I have noticed that during the time awaiting the brief visit of said file, that splwow64.exe is holding up top in the processes until the document prints. Can this be used to pause a script somehow?

cpuload.png.bb48428ee29e88e56080d1bd7b83

Edited by qwiqshot

Share this post


Link to post
Share on other sites

I have given up on trying to capture the exact time the SHD file appears so that I can click the next button and have now turned to the UDF's for Excel.

This prints fine 2 copies to the default printer and the exact range I want, but I need that to print two copies to the Contract Printer

Local $oExcel = _Excel_Open()
_Excel_Print($oExcel, "A1:K55, 2, $sPrinter = Default")

These are the two VBA macro's currently attached to buttons within the spreadsheet,  I am able to print to the default printer (Plain) but cannot steer to the Contract paper.

Sub PrintCopy1()
'
' PrintCopy1 Macro
'

'
Dim STDprinter As String
    STDprinter = Application.ActivePrinter
    Application.ActivePrinter = "Xerox WorkCentre 7556 PS Plain Paper on Ne00:"
    ' change printer
    ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
        :=True, IgnorePrintAreas:=False
End Sub


--------------------------------------------------------------------------------



Sub PrintCopy2()
'
' PrintCopy2 Macro
'

'
Dim STDprinter As String
    STDprinter = Application.ActivePrinter
    Application.ActivePrinter = "Xerox WorkCentre 7556 PS Contract Paper on Ne01:"
    ' change printer
    ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
        :=True, IgnorePrintAreas:=False
End Sub

 

Printer details from Installed Printers are:

Plain Printer:

  • Xerox WorkCentre 7556 PS Plain Paper
  • 199.158.2.139

Contract Printer: 

  • Xerox WorkCentre 7556 PS Contract Paper
  • 199.158.2.139_1

Could someone please steer me right please?

p.s. Both printers are the exact same Physical printer, just installed to use specific trays.

p.s.s. I have also located this page that has UDF's pre defined, but I cannot figure out how to swap between the two versions we have installed to each PC, by changing the default printer, if that is a must.

Share this post


Link to post
Share on other sites
_Excel_Print($oExcel, "A1:K55, 2, $sPrinter = Default")

_Excel_Print allows to specify the target printer. But you need to specify the printer without the name of the parameter. Means:

_Excel_Print($oExcel, "A1:K55", 2, "Name of the printer")

Be careful with quotes. They need to be around EACH parameter. In your code AutoIt only sees two parameters.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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