langjs 发表于 2011-4-19 15:52:16

如何获得某台打印机的纸张列表呢?(已解决)

本帖最后由 langjs 于 2011-4-21 08:29 编辑

lisp中,已知计算机安装的一个打印机名,如何获得这台打印机的纸张列表呢?谢谢。


最后采用的程序如下:

;;; 获得某打印机纸张类型列表
;;;例:(setq PaperSize (GetPaperList "HP LaserJet 5000 Series PCL" ))
(defun GetPaperList (priname / acadobj canpapersizearr canpapersizelist canpapersizevar doc index layout papersize)
(vl-load-com)
(setq layout (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
(vla-put-configname layout priname);将打印机设为当前打印机,下面程序是论坛某老大的获取当前打印纸张类型。
(setq acadobj (vlax-get-acad-object)
doc (vla-get-activedocument acadobj)
layout (vla-get-activelayout doc)
)
(vla-RefreshPlotDeviceInfo layout)
(setq CanPaperSizeVar (vla-GetCanonicalMediaNames layout)
CanPaperSizeArr (vlax-variant-value CanPaperSizeVar)
CanPaperSizeLIst (vlax-safearray->list CanPaperSizeArr)
PaperSize '()
index 0
)
(repeat (length CanPaperSizeList)
    (setq Papersize (cons (vla-GetLocaleMediaName layout (nth index CanPaperSizeList)) Papersize)
   index (1+ index)
    )
)
(reverse PaperSize)
)

ferious 发表于 2024-1-23 20:12:44

你好,网络打印机怎么输入不了

(setq PaperSize (GetPaperList " \\192.168.0.142\左边"))

ferious 发表于 2023-11-14 22:43:05

langjs 发表于 2011-4-21 08:30
感谢老大的帮助。谢谢

大师,最终的源码在哪里?能给下吗

Andyhon 发表于 2011-4-19 16:38:02

visit site:
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Handling-different-prompts-plot-command/m-p/1201867/highlight/true

langjs 发表于 2011-4-19 18:06:00

楼上的网址我怎么打不开啊

langjs 发表于 2011-4-19 18:06:45

回复 Andyhon 的帖子

楼上的网址我怎么打不开啊

Andyhon 发表于 2011-4-19 18:22:19

;;04/09/04 Bill Zondlo -received from AutoDesk NG
;;programming examples to get plotter info
;;
(defun get_plotter_names ()
(vla-RefreshPlotDeviceInfo (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
(vlax-safearray->list
(vlax-variant-value
(vla-getplotdevicenames
(vla-get-activelayout
(vla-get-activedocument
(vlax-get-acad-object)))))) ;gets list of installed plotters
) ;;04/09/04 Bill Zondlo -received from AutoDesk NG
;;programming examples to get plotter info
;;
(defun get_paper_sizes ()
(vla-RefreshPlotDeviceInfo (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
(vlax-safearray->list
(vlax-variant-value
(vla-getCanonicalMediaNames
(vla-get-activelayout
(vla-get-activedocument
(vlax-get-acad-object)))))) ;gets all media names
)

langjs 发表于 2011-4-19 18:49:13

回复 Andyhon 的帖子

谢谢老大提供帮助,可惜不是我想要的程序。

我是自己做了一个打印DCL,里边两个打印机,对应的列表不一样,我如何做到选择其中一个打印机,就把它对应的纸张列表取出来?

网上有个程序,但是只能读取当前打印机的纸张列表,不是当前打印机的列表读不出来,和我需要的差了一点点。
;;; 获得当前打印机纸张类型列表
(defun GetPaperList ()
(vl-load-com)
(setq acadobj (vlax-get-acad-object)
doc (vla-get-activedocument acadobj)
layout (vla-get-activelayout doc)
)
(vla-RefreshPlotDeviceInfo layout)
(setq CanPaperSizeVar (vla-GetCanonicalMediaNames layout)
CanPaperSizeArr (vlax-variant-value CanPaperSizeVar)
CanPaperSizeLIst (vlax-safearray->list CanPaperSizeArr)
PaperSize '()
index 0
)
(repeat (length CanPaperSizeList)
    (setq Papersize (cons (vla-GetLocaleMediaName layout (nth index CanPaperSizeList))
   Papersize
      )
   index (1+ index)
    )
)
(reverse PaperSize)
)

Andyhon 发表于 2011-4-19 21:06:35

Ref:

(setq ad (vla-get-activedocument (vlax-get-acad-object)))

(defun GetCanonicalMediaNames (ad)
(vla-RefreshPlotDeviceInfo
    (vla-get-activelayout ad)
)
(vlax-safearray->list
    (vlax-variant-value
      (vla-GetCanonicalMediaNames
        (vla-item (vla-get-layouts ad) "Model")
      )
    )
)
)

(defun GetLocaleMediaNames (ad / mn mnl)
(setq la (vla-item (vla-get-layouts ad) "Model"))
(foreach mn (GetCanonicalMediaNames ad)
    (setq mnl (cons (vla-GetLocaleMediaName la mn) mnl))
)
(reverse mnl)
)

;;; (GetCanonicalMediaNamesOfConfigname ad "Acrobat PDFWriter")
(defun GetCanonicalMediaNamesOfConfigname (ad cn / oldcn al cmn)
(setq al (vla-get-ActiveLayout ad))
(setq oldcn (vla-get-configname al))
(vla-put-configname al cn)
(vla-RefreshPlotDeviceInfo al)
(setq cmn (GetCanonicalMediaNames ad))
(if (/= oldcn "None")
    (vla-put-configname al oldcn)
)
cmn
)

;;; =================
info:
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Paper-Size-of-Selected-Printer/m-p/884662

langjs 发表于 2011-4-19 21:22:30

本帖最后由 langjs 于 2011-4-19 22:50 编辑

老大你太强悍了,崇拜,正是我需要的!!!万分感谢啊!!!
试用一下,怎么好多列表中的元素名变成User+数字格式了?

langjs 发表于 2011-4-20 10:12:57

回复 Andyhon 的帖子

老大,我执行后返回某个打印机的结果是:(User256 User281 User280 User279 User278 User277 User276 User275 User274
User273 User272 User271 User270 User68 User67 User66 User65 User64 User63
User62 User61 User60 User59 User58 User57 User56 User55 User54 User53 User52
User51 User50 User47 User46 User45 User44 User43 User42 German Legal Fanfold
German Std Fanfold US Std Fanfold 6 3/4 Envelope Envelope Monarch Envelope
Envelope B6 Envelope B5 Envelope B4 Envelope C65 Envelope C6 Envelope C4
Envelope C3 Envelope C5 Envelope DL E size sheet D size sheet C size sheet
Envelope #14 Envelope #12 Envelope #11 Envelope #10 Envelope #9 Note 11x17
10x14 Quarto Folio B5 (JIS) B4 (JIS) A5 A4 Small A4 A3 Executive Statement
Legal Ledger Tabloid Letter Small Letter)

好多User+数字格式,我想要的结果是这样的:
( ARCH E ARCH D ARCH C ARCH B ARCH A ANSI E ANSI D ANSI C ANSI B ANSI A A1
A0 A3 Extra Transverse A3 Transverse A2 B5 (ISO) Extra A5 Extra A3 Extra B5
(JIS) Transverse A5 Transverse A4 Plus Letter Plus SuperB/SuperB/A3
SuperA/SuperA/A4 Letter Extra Transverse A4 Transverse Letter Transverse A4
Extra Tabloid Extra Legal Extra Letter Extra Envelope Invite 11x15 10x11 9x11
Japanese Postcard B4 (ISO) German Legal Fanfold German Std Fanfold US Std
Fanfold 6 3/4 Envelope Envelope Monarch Envelope Italy Envelope B6 Envelope B5
Envelope B4 Envelope C65 Envelope C6 Envelope C4 Envelope C3 Envelope C5
Envelope DL E size sheet D size sheet C size sheet Envelope #14 Envelope #12
Envelope #11 Envelope #10 Envelope #9 Note 11x17 10x14 Quarto Folio B5 (JIS) B4
(JIS) A5 A4 Small A4 A3 Executive Statement Legal Ledger Tabloid Letter Small
Letter)

请问能不能转变过来呢?谢谢

Andyhon 发表于 2011-4-20 10:54:42

未遇过您说的情况,帮不上忙呢
页: [1] 2
查看完整版本: 如何获得某台打印机的纸张列表呢?(已解决)