- 积分
- 9501
- 明经币
- 个
- 注册时间
- 2006-7-25
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2011-8-21 19:06:07
|
显示全部楼层
本帖最后由 xiaoyingzi 于 2011-8-21 19:11 编辑
花了不少时间,终于自己解决了,最后配上秋枫的批量打印,自己用得很方便了- ;;;xiaoyingzi 2011.08.21
- ;;; 修改当前图档的打印配置
- (defun ChangePlotConfig (configName styleSheet PlotRotation PaperSize Plotscale CenterPlot / app doc layout newOrigin)
- (vl-load-com)
- (setq app (vlax-get-acad-object)
- doc (vla-get-activedocument app)
- layout (vla-get-activelayout doc)
- )
- (vla-RefreshPlotDeviceInfo layout)
- (vla-put-configname layout configName) ;打印机
- (vla-put-stylesheet layout styleSheet) ;打印样式
- (if (= "纵向" PlotRotation)
- (vla-put-PlotRotation layout ac0Degrees) ;图形方向 纵向
- (vla-put-PlotRotation layout ac90Degrees) ;图形方向 横向
- )
- (setq index ;开始修改纸张
- (vl-position (strcase PaperSize)
- (mapcar (function strcase)
- (GetPaperList1 configName)
- )
- )
- )
- (vla-put-CanonicalMediaName layout (nth index (GetPaperList2 configName)))
- (princ)
- (if (= "按图纸空间缩放" Plotscale) ;比例 按图纸空间缩放
- (vla-put-standardscale layout acScaleToFit)
- (progn
- (vla-put-standardscale layout acVpCustomScale)
- (vla-SetCustomScale layout 1 Plotscale) ;比例 自定义比例1:Plotscale
- )
- )
- (if (= "居中打印" CenterPlot)
- (vla-put-CenterPlot layout :vlax-true) ;居中打印
- (progn
- (vla-put-CenterPlot layout :vlax-false) ;不居中打印
- (setq newOrigin (vlax-make-safearray vlax-vbDouble '(0 . 1)))
- (vlax-safearray-fill newOrigin (list 0 0)) ;设定打印偏移x为0,y为0
- (vla-put-PlotOrigin Layout newOrigin)
- )
- )
- ;(vla-SetWindowToPlot layout newOrigin newOrigin)
- ;(vla-put-PlotType layout acWindow) ;打印范围 窗口
- (vla-put-paperunits layout acMillimeters) ;单位 米
- (vla-put-PlotWithLineweights layout :vlax-true) ;true: 使用打印型式中的线宽来打印 false: 使用图形文件中的线宽来打印
- )
- ;;; 获得某打印机纸张类型列表, 返回形如 "过大尺寸:ISO A2 (纵向)" "过大尺寸:ISO A2 (横向)".... 的列表
- ;;; 例: (setq PaperSizes (GetPaperList1 "HP DesignJet 430 (E/A0) by HP" ))
- (defun GetPaperList1 (configName / app canpapersizearr canpapersizelist canpapersizevar app doc index layout papersize)
- (vl-load-com)
- (setq app (vlax-get-acad-object)
- doc (vla-get-activedocument app)
- layout (vla-get-activelayout doc)
- )
- (vla-put-configname layout configName) ;将打印机设为当前打印机
- (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)
- )
- ;;; 获得某打印机纸张类型列表, 返回形如 "User620" "User1644".... 的列表
- ;;; 例: (setq PaperSizes (GetPaperList2 "HP DesignJet 430 (E/A0) by HP" ))
- (defun GetPaperList2 (configName / app canpapersizearr canpapersizelist canpapersizevar app doc layout)
- (vl-load-com)
- (setq app (vlax-get-acad-object)
- doc (vla-get-activedocument app)
- layout (vla-get-activelayout doc)
- )
- (vla-put-configname layout configName);将打印机设为当前打印机
- (vla-RefreshPlotDeviceInfo layout)
- (setq CanPaperSizeVar (vla-GetCanonicalMediaNames (vla-item (vla-get-layouts doc) "Model"))
- CanPaperSizeArr (vlax-variant-value CanPaperSizeVar)
- CanPaperSizeLIst (vlax-safearray->list CanPaperSizeArr)
- )
- )
- ;;; 在当前布局,把当前打印设置添加到一个新的页面设置,并置为当前
- ;;; (addPageSetup <PageSetupName>)
- ;;; 例: (AddPageSetup ("PageSetupName")
- (defun AddPageSetup (name / space pc lay PlotConfig)
- (setq app (vlax-get-acad-object)
- doc (vla-get-activedocument app)
- layout (vla-get-activelayout doc)
- )
- ; 删除已有的打印页面设置
- (vlax-for pc (vla-get-plotconfigurations doc)
- (if (= (strcase (vla-get-name pc)) (strcase name))
- (vla-delete pc)
- )
- )
- ; 添加到新的页面设置
- (if (= (getvar "ctab") "Model")
- (setq space :vlax-true
- lay (vla-get-Layout (vla-get-ModelSpace
- (vla-get-activedocument (vlax-get-acad-object)))))
- (setq space :vlax-false
- lay (vla-get-ActiveLayout (vla-get-activedocument
- (vlax-get-acad-object))))
- )
- (setq pc (vla-add
- (vla-get-plotconfigurations doc)
- name
- space))
- (vla-CopyFrom pc lay)
- (vla-put-name pc name)
- ; 把新添加的页面设置置为当前
- (setq PlotConfig (vl-catch-all-apply
- 'vla-item
- (list
- (vla-get-PlotConfigurations
- doc
- )
- name
- )
- )
- )
- (if (not (vl-catch-all-error-p PlotConfig))
- (vla-copyfrom layout PlotConfig)
- )
- (princ)
- )
- (defun c:a1 ()
- (ChangePlotConfig "\\\\hp430\\hp designJet 430 (e/a0) by hp" "蜡纸.ctb" "纵向" "过大尺寸:ISO A1 (纵向)" 100 "不居中打印")
- (AddPageSetup "蜡纸A1")
- (princ "\n当前打印机HP DesignJet 430,蜡纸,纵向进纸,纸张A1,1:100打印比例,居中打印! ")
- (princ "\n当前打印页面设置名为蜡纸A1! ")
- (princ)
- )
- (defun c:a2 ()
- (ChangePlotConfig "\\\\hp430\\hp designJet 430 (e/a0) by hp" "蜡纸.ctb" "横向" "过大尺寸:ISO A2 (横向)" 100 "不居中打印")
- (AddPageSetup "蜡纸A2")
- (princ "\n当前打印机HP DesignJet 430,蜡纸,纵向进纸,纸张A2,1:100打印比例,居中打印! ")
- (princ "\n当前打印页面设置名为蜡纸A2! ")
- (princ)
- )
- (defun c:a3 ()
- (ChangePlotConfig "\\\\打印机\\Generic 16BW-5" "白纸.ctb" "纵向" "A3" "按图纸空间缩放" "居中打印")
- (AddPageSetup "白纸A3")
- (princ "\n当前打印机Generic 16BW-5,白纸,纵向进纸,纸张A3,按图纸空间缩放,居中打印! ")
- (princ "\n当前打印页面设置名为纸张A3! ")
- (princ)
- )
- (defun c:a4 ()
- (ChangePlotConfig "\\\\打印机\\Generic 16BW-5" "白纸.ctb" "横向" "A4" "按图纸空间缩放" "居中打印")
- (AddPageSetup "白纸A4")
- (princ "\n当前打印机Generic 16BW-5,白纸,横向进纸,纸张A4,按图纸空间缩放,居中打印! ")
- (princ "\n当前打印页面设置名为纸张A4! ")
- (princ)
- )
就是其中
;(vla-SetWindowToPlot layout newOrigin newOrigin)
;(vla-put-PlotType layout acWindow)
还是有问题,想设置打印范围为窗口模式,SetWindowToPlot 中的那两个点没什么用,因为后面还要用到秋枫的批量打印,
所以随便设了下,但还是不行,不知道什么问题
|
评分
-
查看全部评分
|