明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3637|回复: 13

[源码] 通用打印函数,可指定参数,可打印pdf

[复制链接]
发表于 2018-1-18 15:35 | 显示全部楼层 |阅读模式
  1. ;打印函数,lujing可为nil,orpdf为T或nil,为T是打印pdf,为nil是打印到设备
  2. (defun gm-dayin(dayinji tufu p1 p2 xiankuan fenshu lujing orpdf yulan / acaddoc fangxiang jixu medianame mspace p3 plot pointtemp1 pointtemp2 st x x1 x2 y y1 y2)
  3.   ;设定系统变量,确保cad在前台进行打印,这样后一次打印会在前一次打印完成后才开始,避免错误
  4.   (setvar "backgroundplot" 0)
  5.   ;由p1和p2坐标判断是横向还是纵向
  6.   (if (> (cadr p1) (cadr p2)) (setq p3 p1
  7.               p1 (list (car p1) (cadr p2) 0)
  8.               p2 (list (car p2) (cadr p3) 0)))
  9.   (setq x1 (car p1) y1 (cadr p1) x2 (car p2) y2 (cadr p2))
  10.   (setq x (abs (- x1 x2)) y (abs (- y1 y2)) )
  11.   (if (> y x) (setq st "p") (setq st "l"))
  12.   ;当路径不为nil时,给路径加上后缀名
  13.   (if (/= lujing nil)(setq lujing (strcat lujing ".pdf")))
  14.   (setq acaddoc (vla-get-activedocument(vlax-get-acad-object))
  15.     mspace(vla-get-activelayout acaddoc)
  16.     plot (vla-get-plot acaddoc)
  17.   )
  18.   (setq p1 (trans p1 0  2)
  19.     p2 (trans p2 0 2)
  20.   )
  21.   ;处理p1和p2
  22.   (setq p1 (reverse (cdr (reverse p1))))
  23.   (setq p2 (reverse (cdr (reverse p2))))
  24.   (setq pointTemp1 (vlax-make-safearray vlax-vbDouble '(0 . 1)))  
  25.   (vlax-safearray-fill pointtemp1 p1)
  26.   (setq pointTemp2 (vlax-make-safearray vlax-vbDouble '(0 . 1)))  
  27.   (vlax-safearray-fill pointtemp2 p2)
  28.   
  29.   ;设定打印机
  30.   (vla-put-configname mspace dayinji)
  31.   ;设定打印样式表
  32.   (vla-put-stylesheet mspace "monochrome.ctb" )
  33.   (vla-refreshplotdeviceinfo mspace)
  34.   ;设定打印区域
  35.   (vla-setwindowtoplot mspace pointtemp1 pointtemp2)
  36.   ;设定打印形式为窗口打印,必须在设定打印区域之后
  37.   (vla-put-plottype mspace acWindow)
  38.   ;设定布满图纸打印
  39.   (vla-put-standardscale mspace acscaletofit)
  40.   ;设定是否居中打印
  41.   (vla-put-centerplot mspace :vlax-true)
  42.   
  43.   ;不居中打印时的设置
  44.   ;(setq p3 (vlax-make-safearray vlax-vbDouble '(0 . 1)))  
  45.   ;(vlax-safearray-put-element p3 0 0)
  46.   ;(vlax-safearray-put-element p3 1 0)
  47.   ;(vla-put-plotorigin mspace p3)
  48.   ;将图纸大小转换成标准介质名称返回
  49.   (setq medianame (gm-putlocalemedianame mspace tufu))
  50.   (vla-put-canonicalmedianame mspace medianame)
  51.   (vla-getpapersize mspace 'chang 'kuan)
  52.   (if (> chang kuan)(setq fangxiang "heng")(setq fangxiang "shu"))
  53.   ;设定横向或者纵向,l横向,p纵向
  54.   (cond
  55.     ((and (eq "heng" fangxiang) (= st "l")) (vla-put-plotrotation mspace ac0degrees))
  56.     ((and (eq "shu" fangxiang) (= st "l")) (vla-put-plotrotation mspace ac90degrees))
  57.     ((and (eq "heng" fangxiang) (= st "p")) (vla-put-plotrotation mspace ac90degrees))
  58.     ((and (eq "shu" fangxiang) (= st "p")) (vla-put-plotrotation mspace ac0degrees))
  59.     (T exit)
  60.   )
  61.   
  62.   ;设定是否打印对象线宽
  63.   (if (= (strcase xiankuan) "Y")
  64.     (vla-put-plotwithlineweights mspace :vlax-true)
  65.     (vla-put-plotwithlineweights mspace :vlax-false))
  66.   
  67.   ;打印预览
  68.   (if (= yulan "y")(progn
  69.          (vla-displayplotpreview plot acfullpreview)
  70.          
  71.          (setq jixu (getstring "/n 打印本张(Y)不打印本张(N):(Y)"))
  72.          (if (= jixu "") (setq jixu "y")))
  73.     (setq jixu "y")
  74.   )
  75.   
  76.   
  77.   (setq jixu (strcase jixu))
  78.   ;打印份数
  79.   (vla-put-numberofcopies plot fenshu)
  80.   (cond
  81.     ((and (= jixu "Y") (= orpdf T)) (vla-plottofile plot lujing))
  82.     ((and (= jixu "Y") (= orpdf nil)) (vla-plottodevice plot dayinji))
  83.     (T nil)
  84.   )
  85.   ;恢复系统变量
  86.   (setvar "backgroundplot" 0)
  87. )
  88. ;;;返回图纸尺寸本地名称所对应的标准名称
  89. (defun gm-putlocalemedianame(mspace bendiming / i localmedianame medianame medianames)
  90.   (setq medianames (vla-getcanonicalmedianames mspace)
  91.     i 0
  92.     medianames (vlax-safearray->list (vlax-variant-value medianames))
  93.   )
  94.   
  95.   (while (< i (length medianames))
  96.     (setq localmedianame (vla-getlocalemedianame mspace (nth i medianames)))
  97.     (if (eq localmedianame bendiming) (setq medianame (nth i medianames)
  98.                 i (1+ (length medianames)))
  99.       (setq i (1+ i))
  100.     )
  101.    
  102.   )
  103.   medianame
  104. )

评分

参与人数 2明经币 +3 收起 理由
xyp1964 + 2 赞一个!
wowan1314 + 1 很给力!

查看全部评分

 楼主| 发表于 2018-1-23 09:08 | 显示全部楼层
w245272914 发表于 2018-1-22 10:04
大神~  有些看不懂啊

(defun c:tt()
       
        (gm-dayin "dwg to pdf.pc3" "ISO A3 (420.00 x 297.00 毫米)" (getpoint "\n 左上角:")(getpoint "\n 右下角:") "y" 1 "d:\\1.pdf" T "y" )
)
可以用这个试一下
发表于 2018-1-23 18:02 | 显示全部楼层
war32 发表于 2018-1-23 09:08
(defun c:tt()
       
        (gm-dayin "dwg to pdf.pc3" "ISO A3 (420.00 x 297.00 毫米)" (getpoint "\n 左上角 ...

哥,你看~
指令: ttt

左上角:
右下角:; 錯誤: no function definition: GM-DAYIN
 楼主| 发表于 2018-1-23 08:50 | 显示全部楼层
ssyfeng 发表于 2018-1-20 17:26
打印成文件的时候少了个文件名

看了下,没问题啊
发表于 2018-1-20 09:45 | 显示全部楼层
好像用VLA的函数比直接用command慢
发表于 2018-1-20 10:10 | 显示全部楼层
支持源码,我也是直接COMMAND的。VLA有的还不会。
发表于 2018-1-20 17:26 | 显示全部楼层
打印成文件的时候少了个文件名
发表于 2018-1-22 10:04 | 显示全部楼层
大神~  有些看不懂啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-8 23:59 , Processed in 0.366096 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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