Print to specific printer

I need to be able to send print jobs to different printers without the operator having to choose which one - avoid sending to wrong printer…

I saw this on another thread:


but when I try it I get this:

[code]Traceback (most recent call last):

File “event:mouseClicked”, line 2, in

AttributeError: ‘’ object has no attribute ‘setPrinterName’

Ignition v7.6.4 (b2013112117)
Java: Sun Microsystems Inc. 1.6.0_31

Is there something Im missing or Is there a way to force a print job to a specific printer or set the default printer for that job?


I haven’t played with the code for it, but it looks like importing the java.awt.print class might be of use to you.

java.awt.print.PrinterJob class:

maybe the .setPrintService() method would be helpful…

Is there a reason job.setPrinterName(“the_printer_name”) doesnt work?

You must have something else going on, and may need to call tech support to see what’s happening.

I just tried the following script in 7.6.4

job = system.print.createPrintJob(event.source.parent) print dir(job) print "Printer name is: ",job.getPrinterName() job.setPrinterName("foo") print "After setting, printer name is: ",job.getPrinterName()

My output was:

['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__eq__', '__getattribute__', '__hash__', '__init__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__unicode__', 'bottomMargin', 'class', 'equals', 'fitToPage', 'getBottomMargin', 'getClass', 'getLeftMargin', 'getOrientation', 'getPageHeight', 'getPageWidth', 'getPrinterName', 'getRightMargin', 'getTopMargin', 'getZoomFactor', 'hashCode', 'isFitToPage', 'isShowPrintDialog', 'leftMargin', 'margins', 'notify', 'notifyAll', 'orientation', 'pageHeight', 'pageWidth', 'print', 'printerName', 'rightMargin', 'setBottomMargin', 'setFitToPage', 'setLeftMargin', 'setMargins', 'setOrientation', 'setPageHeight', 'setPageWidth', 'setPrinterName', 'setRightMargin', 'setShowPageFormat', 'setShowPrintDialog', 'setTopMargin', 'setZoomFactor', 'showPageFormat', 'showPrintDialog', 'toString', 'topMargin', 'wait', 'zoomFactor'] Printer name is: None After setting, printer name is: foo

The script above was my complete script – no special imports.

hmmm… interesting. I tried it again:

job = event.source.parent.getComponent('ConvLocData_Table') job.setPrinterName("SSBINV05") job.print()

but I get the error object has no attribute. Im running 7.6.4 wonder what could be wrong. seems like a fairly simple instruction.

Take a look at the first line of each of our scripts. You aren’t calling the function on a printjob object.

1 Like

ahh. got it - thank you. I overlooked that. since it worked without the setPrinterName I wasnt paying attention to that first line in your reply.

when I use createPrintJob job = system.print.createPrintJob(event.source.parent.getComponent('ConvLocData_Table').data)

it errors with “1st arg cant be coerced to java.awt.Component”

but when I put it in as you have it, it works - just doesnt print the chart it prints the entire screen shot.

also as far as the setPrinterName Ive tried both the printer name and the full path ie: “\networkloc\myprinter” Ive tried a number of things and everything ive tried gives an error “no compatible printer found”

sorry for all the questions - thanks for your help.

For the first problem, remove the ‘.data’ from your parameter. You’re grabbing the dataset, when what you want is the component.

My setup here isn’t easy to test the printer path, but I’d suggest you try the full pathname again ("\networkloc\myprinter" ), except this time escape the backslash characters. You can either change the string to “\\networkloc\myprinter” or add an r in front ( r"\networkloc\myprinter" ). These both tell Python that you really want a backslash, not special characters. Let me know if that helps.

thats it!. r’\networkloc\myprinter’ did the trick. -thank you

removing the .data and going with:

job = system.print.createPrintJob(event.source.parent.getComponent('ConvLocData_Table'))

did work in printing just the chart the only. the nice thing about using

job = (event.source.parent.getComponent('ConvLocData_Table').data) job.print()

is that it will print the whole charts entire data and not just whats visible in the window but maybe nothing I can do about that if I want to be able to select which printer.

Thanks again for your help.