明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1374|回复: 5

[函数] 请问如何取得指定出图设备之纸张规格?

[复制链接]
发表于 2014-2-14 09:29:26 | 显示全部楼层 |阅读模式
请问要用什么函数,

才能查指定印表机可打印的纸张规格清单


谢谢~^^
发表于 2014-2-14 10:15:08 | 显示全部楼层
  1. ;;返回打印设置的纸张清单
  2. (vlax-safearray->list
  3.   (vlax-variant-value
  4.     (vla-GetCanonicalMediaNames
  5.       (vla-Item        (vla-get-PlotConfigurations
  6.                   (vla-get-ActiveDocument (vlax-get-acad-object))
  7.                 )
  8.                 0 ;; 也可输入页面设置名称
  9.       )
  10.     )
  11.   )
  12. )
发表于 2014-2-17 09:45:27 | 显示全部楼层
Gu_xl 发表于 2014-2-14 10:15

; 错误: Automation 错误。未提供说明。

环境:XP,CAD2012,32位,不知为什么
发表于 2014-2-17 12:33:01 | 显示全部楼层
USER2128 发表于 2014-2-17 09:45
; 错误: Automation 错误。未提供说明。

环境:XP,CAD2012,32位,不知为什么

那是因为当前图形没有保存页面设置!请先在打印页面进行页面设置并保存才行!
发表于 2014-3-4 05:10:50 | 显示全部楼层
那有没有办法添加纸张规格呢?不通过对话框界面
发表于 2014-3-4 05:20:12 | 显示全部楼层
打印机系列-代码

; (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)
)

;;所有的打印机设置.(设置,不是名称!)
(defun GetPlotDevices (ad)
(vla-RefreshPlotDeviceInfo
    (vla-get-activelayout ad))
(vlax-safearray->list
    (vlax-variant-value
      (vla-getplotdevicenames
        (vla-item (vla-get-layouts ad) "Model"))))
)

;;当前布局的当前打印机 :pc3
(defun GetActivePlotDevice (ad)
(vla-get-ConfigName
    (vla-get-ActiveLayout ad))
)

;;当前设置下的"打印样式" : ctb
(defun GetPlotStyleTableNames (ad)
(vla-RefreshPlotDeviceInfo
    (vla-get-activelayout ad))
(vlax-safearray->list
    (vlax-variant-value
      (vla-getplotstyletablenames
        (vla-item (vla-get-layouts ad) "Model"))))
)

;;所有的,(可能不会这么用)
(defun ListAllMediaNames(ad / al cn pd apmn)
(setq al (vla-get-activelayout ad))
(setq cn (vla-get-configname al))
(foreach pd (GetPlotDevices)
    (if (/= pd "None")
      (progn
        (vla-put-configname al pd)
        (setq apmn (cons pd apmn))
        (setq apmn (cons (GetCanonicalMediaNames ad) apmn))
      )
    )
)
(if (/= cn "None") (vla-put-configname al cn))
(reverse apmn)
)

; (ListAllLocalMediaNames (vla-get-activedocument (vlax-get-acad-object)))
(defun ListAllLocalMediaNames(ad / al cn pd apmn)
(setq al (vla-get-activelayout ad))
(setq cn (vla-get-configname al))
(foreach pd (GetPlotDevices ad)
    (if (/= pd "None")
      (progn
        (vla-put-configname al pd)
        (setq apmn (cons pd apmn))
        (setq apmn (cons (GetLocaleMediaNames ad) apmn))
      )
    )
)
(if (/= cn "None") (vla-put-configname al cn))
(reverse apmn)
)

;;某一配置的"图纸尺寸"定义
; (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
)

;;上面的本地名
; (GetLocalMediaNamesOfConfigname ad "Acrobat PDFWriter")
(defun GetLocalMediaNamesOfConfigname(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 (GetLocaleMediaNames ad))
(if (/= oldcn "None") (vla-put-configname al oldcn))
cmn
)

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

;;当前布局,下面有用.
(defun ActLay ()
       (vla-get-ActiveLayout
     (vla-get-activedocument
       (vlax-get-acad-object)
     )
       )
)

; Return the Plotter configuration name
(defun GetActivePlotDevice ()
(vla-get-ConfigName
    (ActLay)
)
)

; Return the Plot style table name
(defun GetActiveStyleSheet ()
(vla-get-StyleSheet
    (ActLay)
)
)

; Force the Plotter configuration to something
(defun PutActivePlotDevice (PlotDeviceName)
(vla-put-ConfigName
    (ActLay)
    PlotDeviceName
)
)

; Force the Plot style table to something
(defun PutActiveStyleSheet (StyleSheetName)
(vla-put-StyleSheet
    (ActLay)
    StyleSheetName
)
)

; Return a list of all Plotter configurations
(defun PlotDeviceNamesList ()
(vla-RefreshPlotDeviceInfo (ActLay))
(vlax-safearray->list
    (vlax-variant-value
      (vla-GetPlotDeviceNames
    (ActLay)
      )
    )
)
)

; Return a list of all Plot style tables
(defun PlotStyleTableNamesList ()
(vla-RefreshPlotDeviceInfo (ActLay))
(vlax-safearray->list
    (vlax-variant-value
      (vla-GetPlotStyleTableNames
    (ActLay)
      )
    )
)
)

; If the saved Plotter configuration doesn't exist set it to None
(defun PutActivePlotDeviceToNoneIfNotExist ()
(if (not (member (GetActivePlotDevice) (PlotDeviceNamesList)))
    (PutActivePlotDevice "None")
)
)

; If the saved Plot style table doesn't exist set it to None
(defun PutActiveStyleSheetToNoneIfNotExist ()
(if (not (member (GetActiveStyleSheet) (PlotStyleTableNamesList)))
    (PutActiveStyleSheet "")
)
)

; Change the Plotter configuration "Emtunga.pc3" to your need
(defun PutActivePlotDeviceToCompanyStandardIfNotExist ()
(if (not (member (GetActivePlotDevice) (PlotDeviceNamesList)))
    (PutActivePlotDevice "Emtunga.pc3")
)
)

; Change the Plot style table "Emtunga-A3-BW.ctb" to your need
(defun PutActiveStyleSheetToCompanyStandardIfNotExist ()
(if (not (member (GetActiveStyleSheet) (PlotStyleTableNamesList)))
    (PutActiveStyleSheet "Emtunga-A3-BW.ctb")
)
)

; Change the Plotter configuration to the default one set in the options
; if the active plot device does not exist
(defun PutActivePlotDeviceToDefaultIfNotExistOrNone ()
(if (or (not (member (GetActivePlotDevice) (PlotDeviceNamesList)))
      (= (GetActivePlotDevice) "None")
      )
    (if    (= (vla-get-UseLastPlotSettings
         (vla-get-output
           (vla-get-preferences (vlax-get-acad-object))
         )
       )
       :vlax-true
    )
      (PutActivePlotDevice
    (getenv "General\MRUConfig")
      )
      (PutActivePlotDevice
    (vla-get-DefaultOutputDevice
      (vla-get-output
        (vla-get-preferences (vlax-get-acad-object))
      )
    )
      )
    )
)
)


; Change the Plot style table to the default one set in the options
; if the active Plot style table does not exist
(defun PutActiveStyleSheetToDefaultIfNotExistOrNone ()
(if (or (not
        (member (GetActiveStyleSheet) (PlotStyleTableNamesList))
      )
      (= (GetActiveStyleSheet) "")
      )
    (PutActiveStyleSheet
      (vla-get-DefaultPlotStyleTable
    (vla-get-output
      (vla-get-preferences (vlax-get-acad-object))
    )
      )
    )
)
)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-19 04:28 , Processed in 0.162725 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表