dar2162 发表于 2022-7-6 23:20:58

脚本打印

我正在寻找一种自动绘图的方法。
 
我绘制的每幅图都有相同的4种布局,名称如下:CP1、CU1、3L1、3L2。我总是需要按照以下约定绘制三个文档。
 
[图纸名称]-CP.pdf这只包含CP1页。
[图纸名称]-CU。pdf这只包含CU1页。
[图纸名称]-3L。pdf包含第3L1和3L2页。
 
这些图形的打印应始终保存在我的文件路径中较高的一级。一、 e.AutoCad文件的路径为//工程图纸/AutoCAD/和PDF应保存到//工程图纸/。
 
有谁能建议一条正确的道路来实现这一过程的自动化?
 
干杯

BIGAL 发表于 2022-7-7 01:13:25

这是一个开始,这是最新的版本将做你想要的它绘制一个范围,这样你可以做布局1或2-3等。你需要单独下载Ghostscript,因为它将pdf的组合成1。
 

;Plots layouts by range
; By Alan H Feb 2014
(defun AH:pltlays ( / val1 val2 plotnames dwgname lendwg pdfname lay numlay numend dwgpre)
(SETVAR "PDMODE" 0)
(setvar "plottransparencyoverride" 2)
(setvar "fillmode" 1)
(setvar "textfill" 1)
(setq plotnames '())
; check that pdf directory exists
(setq dwgpre (strcat (getvar "dwgprefix") "\pdf"))
(if (= (vl-file-directory-p dwgpre) nil)
(vl-mkdir dwgpre)
)
(SETQ LAYOUTS (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))
(SETQ COUNT (- (VLA-GET-COUNT LAYOUTS) 1))
(if (not AH:getval2) (load "getvals3"))
(ah:getval2 "Enter start tab number" 6 4 "1" "Enter end tab number" 6 4 (RTOS COUNT 2 0))
(setq numlay (ATOI val1))
(setq numend (ATOI val2))
(setq len (+ (- numend numlay) 1))
(setq dwgname (GETVAR "dwgname"))
(setq lendwg (strlen dwgname))
(setq dwgname (substr dwgname 1 (- lendwg 4)))
(repeat len
(vlax-for lay LAYOUTS
(if (= numlay (vla-get-taborder lay))
(setvar "ctab" (vla-get-name lay))
) ; if
(setq pdfname (strcat dwgpre "\\" dwgname "-" (getvar "ctab") ".pdf" ))
) ; for
(setvar "textfill" 1)
(setvar "fillmode" 1)
(setvar "PLOTTRANSPARENCYOVERRIDE" 2)
   (COMMAND "-PLOT""Y""" "dwg to Pdf"
       "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE""N"   "W""-6,-6" "807,560" "1=2""C"
       "y" "Designlasercolour.ctb" "Y" "n" "n" "n" pdfName "N" "y"
   )

(setq numlay (+ numlay 1))
(setq plotnames (cons pdfname plotnames))
) ; end repeat
(setq trgfile (strcat (getvar "dwgprefix") "pdf\\" dwgname "-D" val1 "-D" val2 ".pdf"))
(setq plotnames (reverse plotnames))
(IF (= (length plotnames) 1)
(princ)
(progn
(if (not combinepdf)(load "mergepdfs"))
(combinepdf gsExe plotnames trgFile )
)
)
) ; defun
(AH:pltlays)

(princ)

 

;MergePdfs
;Merges multiple pdf (or eps) files into one
;Requires the installatoion of Ghostscript
; make a batch file ?
;gs -sDEVICE=pdfwrite \
;    -dNOPAUSE -dBATCH -dSAFER \
;    -sOutputFile=combined.pdf \
;    first.pdf \
;    second.pdf \
;    third.pdf [...]
;Ghostscript (http://www.ghostscript.com/) can be used to combine PDFs.
; Something like this should work: by Roy_043
(defun KGA_String_Join (strLst delim)
(if strLst
(apply
'strcat
(cons
(car strLst)
(mapcar '(lambda (a) (strcat delim a)) (cdr strLst))
)
)
""
)
)
; (CombinePdf
(setq gsexe "C:\\Program Files\\gs\\gs9.19\\bin\\gswin64c.exe")
; (setq srcFilelst'("D:\\Tmp\\A.pdf" "D:\\Tmp\\B.pdf"))
; (setq trgfile "C:\\Acadtemp\\Total.pdf")
; )
; Note: Existing trgFile will be overwritten.
(defun CombinePdf (gsExe srcFileLst trgFile)
(startapp
(strcat
gsExe " "
"-sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dQUIET"
"-sOutputFile=\"" trgFile "\" "
"\"" (KGA_String_Join srcFileLst "\" \"") "\""
)
)
)

 
还有这个

; InputDialog box with variable title
; multiple lines of dcl input supported
; add extra lines if required by copying code defun
; By Alan H 2015
(vl-load-com)
; 1 line dcl
; sample code (ah:getval1 "Line 1" 5 4)
(defun AH:getval1 (title width limit def1 / fo fname)
; you can hard code a directory if you like for dcl file
(setq fo (open (setq fname "c:\\acadtemp\\getval.dcl") "w"))
(write-line "ddgetval : dialog {" fo)
(write-line " : row {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = "(chr 34) "key1" (chr 34) ";") fo)
(write-line(strcat " label = "(chr 34) title (chr 34) ";")   fo)
; these can be replaced with shorter value etc
(write-line (strcat "   edit_width = " (rtos width 2 0) ";" ) fo)
(write-line (strcat "   edit_limit = " (rtos limit 2 0) ";" ) fo)
(write-line "   is_enabled = true;" fo)
(write-line "    }" fo)
(write-line "}" fo)
(write-line "ok_only;}" fo)
(close fo)
(setq dcl_id (load_dialogfname))
; pt is a list 2 numbs -1 -1 centre ('(20 20))
;(not (new_dialog "test" dch "" *screenpoint*))
(if (not (new_dialog "ddgetval" dcl_id))
(exit))
(set_tile "key1" (setq val1 def1))
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key1" 3)
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 as a string
(vl-file-delete fname)
) ; defungetval1
; 2 line dcl
; sample code (ah:getval2 "Line 1" 5 4 "Line2" 8 7)
(defun AH:getval2 (title1 width1 limit1 def1 title2 width2 limit2 def2 / fo fname)
(setq fo (open (setq fname "c:\\acadtemp\\getval.dcl") "w"))
(write-line "ddgetval2 : dialog {" fo)
(write-line " : column {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = " (chr 34) "key1" (chr 34) ";") fo)
(write-line(strcat " label = "(chr 34) title1 (chr 34) ";" ) fo)
(write-line (strcat "   edit_width = " (rtos width1 2 0) ";" ) fo)
(write-line (strcat "   edit_limit = " (rtos limit1 2 0) ";" ) fo)
(write-line "   is_enabled = true ;" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = " (chr 34) "key2" (chr 34) ";") fo)
(write-line (strcat " label = "(chr 34) title2 (chr 34) ";") fo)
(write-line (strcat "   edit_width = " (rtos width2 2 0) ";" ) fo)
(write-line (strcat "   edit_limit = " (rtos limit2 2 0) ";" ) fo)
(write-line "   is_enabled = true ;" fo)
(write-line "    }" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(write-line "ok_only;}" fo)
(close fo)
; code part
(setq dcl_id (load_dialogfname))
(if (not (new_dialog "ddgetval2" dcl_id))
(exit))
(mode_tile "key1" 3)
(set_tile "key1" (setq val1 def1))
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key2" 3)
(set_tile "key2" (setq val2 def2))
(action_tile "key2" "(setq val2 $value)")
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 and val2 as strings
(vl-file-delete fname)
) ; defungetval2
; 3 line dcl
; sample code (ah:getval3 "Line 1" 5 4 "0.9" "Line 2" 8 7 "wow" "Line 3" 6 4 "123")
(defun AH:getval3 (title1 width1 limit1 def1 title2 width2 limit2 def2 title3 width3 limit3 def3 / fo fname)
(setq fo (open (setq fname "c:\\acadtemp\\getval.dcl") "w"))
(write-line "ddgetval3 : dialog {" fo)
(write-line " : column {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = " (chr 34) "key1" (chr 34) ";") fo)
(write-line(strcat " label = "(chr 34) title1 (chr 34) ";" ) fo)
(write-line (strcat "   edit_width = " (rtos width1 2 0) ";" ) fo)
(write-line (strcat "   edit_limit = " (rtos limit1 2 0) ";" ) fo)
(write-line "   is_enabled = true ;" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = " (chr 34) "key2" (chr 34) ";") fo)
(write-line (strcat " label = "(chr 34) title2 (chr 34) ";") fo)
(write-line (strcat "   edit_width = " (rtos width2 2 0) ";" ) fo)
(write-line (strcat "   edit_limit = " (rtos limit2 2 0) ";" ) fo)
(write-line "   is_enabled = true ;" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = " (chr 34) "key3" (chr 34) ";") fo)
(write-line (strcat " label = "(chr 34) title3 (chr 34) ";") fo)
(write-line (strcat "   edit_width = " (rtos width3 2 0) ";" ) fo)
(write-line (strcat "   edit_limit = " (rtos limit3 2 0) ";" ) fo)
(write-line "   is_enabled = true ;" fo)
(write-line "    }" fo)
(write-line "    }" fo)
(write-line "spacer_1 ;" fo)
(write-line "ok_only;}" fo)
(close fo)
; code part
(setq dcl_id (load_dialogfname))
(if (not (new_dialog "ddgetval3" dcl_id))
(exit))
(mode_tile "key1" 3)
(set_tile "key1" (setq val1 def1))
(action_tile "key1" "(setq val1 $value)")
(mode_tile "key2" 3)
(set_tile "key2" (setq val2 def2))
(action_tile "key2" "(setq val2 $value)")
(mode_tile "key3" 3)
(set_tile "key3" (setq val3 def3))
(action_tile "key3" "(setq val3 $value)")
(start_dialog)
(done_dialog)
(unload_dialog dcl_id)
; returns the value of val1 val2 and val3 as strings
(vl-file-delete fname)
) ; defungetval3
页: [1]
查看完整版本: 脚本打印