PDA

View Full Version : Get default windows printer in LISP


Harry
12-09-2005, 01:19 AM
I made the following code to get the default windows printer in LISP:

macro 'get_default_printer.mac' :

DEFINE get_default_windows_printer
LOCAL printer_name
LOCAL isopen
LOCAL line
LOCAL done
LOCAL isclosed

{get default windows printer}
inq_env 22
LET printer_name (INQ 303)
LET line "(list '" + printer_name + "')"

LET isopen (DOCU_OPEN_CONNECTION_TO_SD)
LET done (DOCU_ADD_LINE_TO_SD line)
LET isclosed (DOCU_CLOSE_CONNECTION_TO_SD)
END_DEFINE


The lisp code:

(defun xan-get-default-printername()
;function: get default printername
;----------------------------------------------------------------------

(progn
;local vars
(let (a_printerlist a_printername1 a_printername2)

(sd-execute-annotator-command :cmd "INPUT 'get_default_printer.mac'")

(DISPLAY (oli::sd-execute-annotator-function :fnc "get_default_windows_printer"))

;return code
a_printername1

);let
);progn
)


It is the first time I use this mechanisme to talk from anno to sd. It looks like there is some kind of loop sd is running in. Does anyone has a tip what I overlooked?

best regards,
Harry

...who thinks that it would be nice if there was a standard command for this function.

clausb
12-09-2005, 04:49 AM
Before we try to debug that code - do you want to know the default printer for Annotator, or the default printer for Windows in general? If it's the Windows default printer, check out my code example at http://www.clausbrod.de/Osdm/MacroDefaultPrinter .

Claus

John Scheffel
12-09-2005, 08:39 AM
If all you want to do is make the Windows default printer the current printer selected for plotting, this code might help. I got this from CoCreate Support. We use it in our am_customize startup file for version 2005 (13). I don't think it works in earlier versions.

The line which specifies :paper_format was commented because of a start up problem if the default printer did not have a format named "Letter". For example, some printer drivers use something like "Letter 8.5x11" instead. The name must exactly match an available paper size for the default printer driver, so is not useful in corporate or site leve customizations unless you are sure everyone has that size. It is useful for user level customization when the available paper sizes for the default printer are known.

;; Command from labs which will select the the Windows default printer
(docu-cmd "PLOTTER_TYPE ADD MSWINDOW_GDI_PRINTER 'win_default'")
(docu-cmd "PLOTTER_TYPE 'win_default'")

;; Changing to the default printer may change some settings, set the corp defaults.
;; :paper format was removed due to obscure problem with PCs that had default
;; printer with no "Letter" paper size. For example, some a have "Letter 8.5x11"
;(am_plot_ex :to_file :no :paper_format "Letter" :copies 1 :orientation :landscape)
(am_plot_ex :to_file :no :copies 1 :orientation :landscape)
(am_plot_ex :pattern_length :all (oli:sd-sys-to-user-units :length 8.0) :accept)

Harry
12-13-2005, 10:57 AM
Before we try to debug that code - do you want to know the default printer for Annotator, or the default printer for Windows in general? If it's the Windows default printer, check out my code example at http://www.clausbrod.de/Osdm/MacroDefaultPrinter .

Claus

Thanks for your reaction, I already studied your solution. It is was I am looking for but I do not like to use another language as addon. I already have to maintain programs in java, lisp, me macro, vb and xml.... :(

Best regards,

Harry

Harry
12-13-2005, 11:00 AM
Hi John,
thanks for your help. I can use the code very well. Clear and simple.

But I still like to know how the system works when I like to call a macro from lisp and recieve the answer back in lisp. I must be somethinf stupid what I overlook... Does anyone have a tip how to debug this situation? (This all runs on the border of lisp and me10 macro.)

Best regards,
Harry

clausb
12-13-2005, 12:03 PM
It is was I am looking for but I do not like to use another language as addon. I already have to maintain programs in java, lisp, me macro, vb and xml.... :(


If you prefer macros, http://www.clausbrod.de/Osdm/MacroDefaultPrinter now shows how to inquire the default printer in what essentially boils down to a Lisp one-liner with a teeny-weeny bit of OSDD macro code thrown in to spice it up.

Enjoy .-)

Claus

PS: I stil think the Lisp/VBscript approach is superior simply because it will work even in plain OSDM, i.e. it doesn't require the user to activate Annotation first.

clausb
12-13-2005, 12:09 PM
Hi John,
thanks for your help. I can use the code very well. Clear and simple.

But I still like to know how the system works when I like to call a macro from lisp and recieve the answer back in lisp. I must be somethinf stupid what I overlook... Does anyone have a tip how to debug this situation? (This all runs on the border of lisp and me10 macro.)

Best regards,
Harry

There's a dedicated document on this in the Integration Kit online help; use the full-text search option to look for "docu_add_line_to_sd".

I did not really try to debug your code, but I can see at least two potential issues with the OSDD macro code:

"line" is used as a variable name; maybe OSDD will confuse this with the line command?
To send a string back to OSDM, it needs to be converted into Lisp notation using DOCU_CSTRING_TO_LSTRING


Claus