明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 387|回复: 9

[提问] 新手问题:如何在不选择图框的情况下获得顶点从而直接打印至PDF?

[复制链接]
发表于 2024-7-26 13:44:48 | 显示全部楼层 |阅读模式
纯新手,提问可能也非常小白。
问题:我需要在AutoCAD 打开图纸的情况下,通过执行命令,直接将当前图纸打印至PDF。
需要选择合适的图幅,需要充满PDF页面。

在论坛里找了一圈大佬们的源码,没找到合适的(可能自己也不太会用这些代码)。
但发现有一个大佬的代码特别时候我的理解,只是这个代码需要人工干预选择图的坐上角和右下角,我希望是通过程序自动识别的。
请问大佬们该如何实现。感谢!!!

  1. (defun c:tt()   
  2.   (setq p1 (getpoint "\n 左上角:"))
  3.   (setq p2 (getpoint "\n 右下角:"))
  4.   (princ "\n")
  5.   (princ p1)  
  6.   (princ "\n")
  7.   (princ p2)
  8.   (princ "\n")  
  9.   (gm-dayin "dwg to pdf.pc3" "ISO A3 (420.00 x 297.00 毫米)" p1 p2 "y" 1 "d:\\1.pdf" T "y" )
  10. )

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


发表于 2024-7-26 15:49:29 | 显示全部楼层
读取含有"图框","TK"内容块,然后获取它的包围盒,
修改PC3纸张,再启动打印引擎,结束.
 楼主| 发表于 2024-7-26 16:05:35 | 显示全部楼层
谢谢!
大佬能代码示意一下吗?
要求会不会太过分了?
发表于 2024-7-26 16:13:50 | 显示全部楼层
参考秋枫的批量打印程序.有源码.
 楼主| 发表于 2024-7-26 16:21:02 | 显示全部楼层
黄翔 发表于 2024-7-26 16:13
参考秋枫的批量打印程序.有源码.

秋神的代码量比较大,刚接触AutoLisp,大多都没看懂
 楼主| 发表于 2024-7-27 15:30:36 | 显示全部楼层
周末有大神上论坛吗?
发表于 2024-7-28 17:45:41 | 显示全部楼层
不错的贴子
 楼主| 发表于 2024-7-28 17:54:09 | 显示全部楼层
一日一游一提
发表于 2024-7-28 19:13:45 | 显示全部楼层
我直接用秋枫的打印即可
 楼主| 发表于 2024-7-29 14:01:34 | 显示全部楼层
秋枫大神的代码看不懂。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-8 08:32 , Processed in 0.200915 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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