新手问题:如何在不选择图框的情况下获得顶点从而直接打印至PDF?
纯新手,提问可能也非常小白。问题:我需要在AutoCAD 打开图纸的情况下,通过执行命令,直接将当前图纸打印至PDF。
需要选择合适的图幅,需要充满PDF页面。
在论坛里找了一圈大佬们的源码,没找到合适的(可能自己也不太会用这些代码)。
但发现有一个大佬的代码特别时候我的理解,只是这个代码需要人工干预选择图的坐上角和右下角,我希望是通过程序自动识别的。
请问大佬们该如何实现。感谢!!!
(defun c:tt()
(setq p1 (getpoint "\n 左上角:"))
(setq p2 (getpoint "\n 右下角:"))
(princ "\n")
(princ p1)
(princ "\n")
(princ p2)
(princ "\n")
(gm-dayin "dwg to pdf.pc3" "ISO A3 (420.00 x 297.00 毫米)" p1 p2 "y" 1 "d:\\1.pdf" T "y" )
)
;打印函数,lujing可为nil,orpdf为T或nil,为T是打印pdf,为nil是打印到设备
(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)
;设定系统变量,确保cad在前台进行打印,这样后一次打印会在前一次打印完成后才开始,避免错误
(setvar "backgroundplot" 0)
;由p1和p2坐标判断是横向还是纵向
(if (> (cadr p1) (cadr p2)) (setq p3 p1
p1 (list (car p1) (cadr p2) 0)
p2 (list (car p2) (cadr p3) 0)))
(setq x1 (car p1) y1 (cadr p1) x2 (car p2) y2 (cadr p2))
(setq x (abs (- x1 x2)) y (abs (- y1 y2)) )
(if (> y x) (setq st "p") (setq st "l"))
;当路径不为nil时,给路径加上后缀名
(if (/= lujing nil)(setq lujing (strcat lujing ".pdf")))
(setq acaddoc (vla-get-activedocument(vlax-get-acad-object))
mspace(vla-get-activelayout acaddoc)
plot (vla-get-plot acaddoc)
)
(setq p1 (trans p1 02)
p2 (trans p2 0 2)
)
;处理p1和p2
(setq p1 (reverse (cdr (reverse p1))))
(setq p2 (reverse (cdr (reverse p2))))
(setq pointTemp1 (vlax-make-safearray vlax-vbDouble '(0 . 1)))
(vlax-safearray-fill pointtemp1 p1)
(setq pointTemp2 (vlax-make-safearray vlax-vbDouble '(0 . 1)))
(vlax-safearray-fill pointtemp2 p2)
;设定打印机
(vla-put-configname mspace dayinji)
;设定打印样式表
(vla-put-stylesheet mspace "monochrome.ctb" )
(vla-refreshplotdeviceinfo mspace)
;设定打印区域
(vla-setwindowtoplot mspace pointtemp1 pointtemp2)
;设定打印形式为窗口打印,必须在设定打印区域之后
(vla-put-plottype mspace acWindow)
;设定布满图纸打印
(vla-put-standardscale mspace acscaletofit)
;设定是否居中打印
(vla-put-centerplot mspace :vlax-true)
;不居中打印时的设置
;(setq p3 (vlax-make-safearray vlax-vbDouble '(0 . 1)))
;(vlax-safearray-put-element p3 0 0)
;(vlax-safearray-put-element p3 1 0)
;(vla-put-plotorigin mspace p3)
;将图纸大小转换成标准介质名称返回
(setq medianame (gm-putlocalemedianame mspace tufu))
(vla-put-canonicalmedianame mspace medianame)
(vla-getpapersize mspace 'chang 'kuan)
(if (> chang kuan)(setq fangxiang "heng")(setq fangxiang "shu"))
;设定横向或者纵向,l横向,p纵向
(cond
((and (eq "heng" fangxiang) (= st "l")) (vla-put-plotrotation mspace ac0degrees))
((and (eq "shu" fangxiang) (= st "l")) (vla-put-plotrotation mspace ac90degrees))
((and (eq "heng" fangxiang) (= st "p")) (vla-put-plotrotation mspace ac90degrees))
((and (eq "shu" fangxiang) (= st "p")) (vla-put-plotrotation mspace ac0degrees))
(T exit)
)
;设定是否打印对象线宽
(if (= (strcase xiankuan) "Y")
(vla-put-plotwithlineweights mspace :vlax-true)
(vla-put-plotwithlineweights mspace :vlax-false))
(setq jixu "y")
(setq jixu (strcase jixu))
;打印份数
(vla-put-numberofcopies plot fenshu)
(cond
((and (= jixu "Y") (= orpdf T)) (vla-plottofile plot lujing))
((and (= jixu "Y") (= orpdf nil)) (vla-plottodevice plot dayinji))
(T nil)
)
;恢复系统变量
(setvar "backgroundplot" 0)
)
;;;返回图纸尺寸本地名称所对应的标准名称
(defun gm-putlocalemedianame(mspace bendiming / i localmedianame medianame medianames)
(setq medianames (vla-getcanonicalmedianames mspace)
i 0
medianames (vlax-safearray->list (vlax-variant-value medianames))
)
(while (< i (length medianames))
(setq localmedianame (vla-getlocalemedianame mspace (nth i medianames)))
(if (eq localmedianame bendiming) (setq medianame (nth i medianames)
i (1+ (length medianames)))
(setq i (1+ i))
)
)
medianame
)
读取含有"图框","TK"内容块,然后获取它的包围盒,
修改PC3纸张,再启动打印引擎,结束. 谢谢!
大佬能代码示意一下吗?:handshake
要求会不会太过分了?:$ 参考秋枫的批量打印程序.有源码. 黄翔 发表于 2024-7-26 16:13
参考秋枫的批量打印程序.有源码.
秋神的代码量比较大,刚接触AutoLisp,大多都没看懂:'( 周末有大神上论坛吗? 不错的贴子 一日一游一提 我直接用秋枫的打印即可 秋枫大神的代码看不懂。。。
页:
[1]