Printing to Network Printer - no dialoge box

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Printing to Network Printer - no dialoge box

Post by newpie » Mon Aug 19, 2019 4:43 pm

Hello, I making an app with the goal to print multiple templates in livecode. I made one with macro program before where it could print to designated network label printer (thru app) without installing it and dialog boxes.

Some that code was as so:
SelectedPrinter = idkwvmwprn003\HL65
Run, print.exe /D:\\%SelectedPrinter% "%LocalUser%\Output.txt",,Hide

Can I simulate this in livecode as I can't rely on users installing the designated printers prior to app use? I would like to get away putting in an text file and move to where the print the card or whatever you recommend.

Thanks for any help.

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Re: Printing to Network Printer - no dialoge box

Post by newpie » Mon Aug 26, 2019 11:41 pm

Hello, any idea on this one?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Printing to Network Printer - no dialoge box

Post by FourthWorld » Tue Aug 27, 2019 3:16 am

See the open printing command in the Dictionary, which includes an option for showing the print job dialog.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Re: Printing to Network Printer - no dialoge box

Post by newpie » Fri Aug 30, 2019 3:35 pm

Thank you FourthWorld. I wanted to push to the printer without opening the dialogue box actually, like I could in hotkey basically.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Printing to Network Printer - no dialoge box

Post by FourthWorld » Fri Aug 30, 2019 4:40 pm

Hmmm.., The print command should normally send to the currently-selected printer without a dialog unless the dialog option is included in the open printing statement.

Is it possible the system did not register that a printer has already been selected, or that it may have changed?

Might be worth a bug report to see how the team views this. Unless the OS now prohibits silent printing, we should expect control over whether the dialog is shown or not.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Re: Printing to Network Printer - no dialoge box

Post by newpie » Sat Aug 31, 2019 12:21 am

Ok, I tested the print command for my network printer with the following, but it always select my local printer. Any trick to this? Perhaps I am using wrong command to set printer? Something to note, I do not want the end user to install the printer. Similar to how hotkey could print to any printer on network.

Code: Select all

on mouseUp
   set the printerName to "idkwvmwprn003\HL65"
   print card 1
end mouseUp
Thanks

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Printing to Network Printer - no dialoge box

Post by FourthWorld » Sat Aug 31, 2019 1:35 am

How is Hotkey configured?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Re: Printing to Network Printer - no dialoge box

Post by newpie » Sat Aug 31, 2019 1:54 am

The code is in first post, not any additional configuration code. Is there a way to specify the server address to the network printer in LiveCode?

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Re: Printing to Network Printer - no dialoge box

Post by newpie » Mon Sep 02, 2019 12:17 am

Hello, if anyone knows how to route to a network printer I took another look and found the full address of network printer is as so:

Code: Select all

idkwvmwprn003.WROK.NET\HL65
I was really hoping to get this working today if possible, any help would be appreciated. thanks.

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Printing to Network Printer - no dialoge box

Post by SparkOut » Mon Sep 02, 2019 3:06 pm

I don't know, and can't test, but maybe add double backslashes before the printer name, so you are calling it by unc path?

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Re: Printing to Network Printer - no dialoge box

Post by newpie » Tue Sep 03, 2019 4:20 pm

Thank you SparkOut for your post. I tried the below with no success. It seems to always go to my default printer I noticed.

Code: Select all

on mouseUp
   set the printerName to "idkwvmwprn003\\HL65"
   print card 1
end mouseUp

Code: Select all

on mouseUp
   set the printerName to "idkwvmwprn003.WROK.NET\\HL65"
   print card 1
end mouseUp

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Printing to Network Printer - no dialoge box

Post by SparkOut » Tue Sep 03, 2019 10:20 pm

I meant \\ before the hostname for the printer, thus:

set the printerName to "\\idkwvmwprn003\HL65"

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Printing to Network Printer - no dialoge box

Post by SparkOut » Tue Sep 03, 2019 10:24 pm

I can't test properly but there is some magic that can be done with LiveCode using vbscript, so you may be able to test and tweak and adjust the scripts below to achieve something like what you need.
Say you have a button with the following script

Code: Select all

on mouseUp
   --first let's find what printer is currently set as default so that we can
   --override the default and then put it back again afterwards
   put the cGetDefaultPrinter of me into tVBScript
   do tVBScript as "vbscript"
   put the result into tResult
   --answer "The current default printer is" && tResult
   set the cStoredDefaultPrinter of me to tResult
   --now we have saved the current default printer, let's override it with the networked one
   --we get the VBScript which contains placeholder
   put the cSetNetworkPrinter of me into tVBScript
   --this is the hardcoded UNC path to the chosen printer
   put "\\idkwvmwprn003\HL65" into tPrinterName
   --replace the placeholder with the correct printer name
   replace "<~%printernameGoesHere%~>" with tPrinterName in tVBScript
   do tVBScript as "vbscript"
   put the result into tResult
   if tResult is not empty then
      answer "Something went wrong:" && tResult
      --you should handle errors more gracefully than this
      exit to top
   end if
   --try your printing
   print card 1
   --now we can set the original printer back as default
   put the cSetNetworkPrinter of me into tVBScript
   --we got the script with placeholder back
   put the cStoredDefaultPrinter of me into tPrinterName
   --replace the placeholder with the correct printer name stored from before
   replace "<~%printernameGoesHere%~>" with tPrinterName in tVBScript
   do tVBScript as "vbscript"
   put the result into tResult
   if tResult is not empty then
      answer "Something went wrong:" && tResult
      --you should handle errors more gracefully than this
   end if
end mouseUp
The buttons should have custom properties containing the following vbscripts as their values:

cGetDefaultPrinter property should contain

Code: Select all

Set oShell = CreateObject("WScript.Shell")
strValue = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
strPrinter = oShell.RegRead(strValue)
strPrinter = Split(strPrinter, ",")(0)
result = strPrinter
cSetNetworkPrinter property should contain

Code: Select all

Option Explicit
On Error Resume Next
Dim objNetwork, strUNCPrinter,strError,result
strUNCPrinter = "<~%printernameGoesHere%~>"
Set objNetwork = CreateObject("WScript.Network") 
Set objAdd = objNetwork.AddWindowsPrinterConnection(strUNCPrinter)
If Not objAdd Then
    strError = "Error connecting printer"
Else
    objNetwork.SetDefaultPrinter strUNCPrinter
    strError = ""
End If
objNetwork = Nothing
objAdd = Nothing
result = strError

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Re: Printing to Network Printer - no dialoge box

Post by newpie » Tue Sep 03, 2019 10:47 pm

Thank you SparkOut. My results of using \\ in front did not work, and Livecode still seem to only want to send to the default installed printer.

I saw your second post here, I will test with this now. Thanks again.

newpie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 155
Joined: Sat Jun 29, 2013 11:24 pm

Re: Printing to Network Printer - no dialoge box

Post by newpie » Tue Sep 03, 2019 11:11 pm

Hello SparkOut, I setup the button as described and it does put my default printer in the cStoredDefaultPrinter custom property. Unfortunately it gives me error "Something went wrong: Error connecting printer" fyi. Wanted to let you know.

I also wanted to make sure i was doing it correctly. When you state something like this
strUNCPrinter = "<~%printernameGoesHere%~>"

you want something to this effect:
strUNCPrinter = "<~%HL65%~>"


Thx

Post Reply