乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 29|回复: 1

[综合讨论] 脚本打印

[复制链接]

1

主题

1

帖子

0

银币

初来乍到

Rank: 1

铜币
5
发表于 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应保存到//工程图纸/。
 
有谁能建议一条正确的道路来实现这一过程的自动化?
 
干杯
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-7 01:13:25 | 显示全部楼层
这是一个开始,这是最新的版本将做你想要的它绘制一个范围,这样你可以做布局1或2-3等。你需要单独下载Ghostscript,因为它将pdf的组合成1。
 
  1. ;Plots layouts by range
  2. ; By Alan H Feb 2014
  3. (defun AH:pltlays ( / val1 val2 plotnames dwgname lendwg pdfname lay numlay numend dwgpre)
  4. (SETVAR "PDMODE" 0)
  5. (setvar "plottransparencyoverride" 2)
  6. (setvar "fillmode" 1)
  7. (setvar "textfill" 1)
  8. (setq plotnames '())
  9. ; check that pdf directory exists
  10. (setq dwgpre (strcat (getvar "dwgprefix") "\pdf"))
  11. (if (= (vl-file-directory-p dwgpre) nil)
  12. (vl-mkdir dwgpre)
  13. )
  14. (SETQ LAYOUTS (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))
  15. (SETQ COUNT (- (VLA-GET-COUNT LAYOUTS) 1))
  16. (if (not AH:getval2) (load "getvals3"))
  17. (ah:getval2 "Enter start tab number" 6 4 "1" "Enter end tab number" 6 4 (RTOS COUNT 2 0))
  18. (setq numlay (ATOI val1))
  19. (setq numend (ATOI val2))
  20. (setq len (+ (- numend numlay) 1))
  21. (setq dwgname (GETVAR "dwgname"))
  22. (setq lendwg (strlen dwgname))
  23. (setq dwgname (substr dwgname 1 (- lendwg 4)))
  24. (repeat len
  25. (vlax-for lay LAYOUTS
  26. (if (= numlay (vla-get-taborder lay))
  27. (setvar "ctab" (vla-get-name lay))
  28. ) ; if
  29. (setq pdfname (strcat dwgpre "\" dwgname "-" (getvar "ctab") ".pdf" ))
  30. ) ; for
  31. (setvar "textfill" 1)
  32. (setvar "fillmode" 1)
  33. (setvar "PLOTTRANSPARENCYOVERRIDE" 2)
  34.    (COMMAND "-PLOT"  "Y"  "" "dwg to Pdf"
  35.        "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE"  "N"   "W"  "-6,-6" "807,560" "1=2"  "C"
  36.        "y" "Designlasercolour.ctb" "Y" "n" "n" "n" pdfName "N" "y"
  37.    )
  38. (setq numlay (+ numlay 1))
  39. (setq plotnames (cons pdfname plotnames))
  40. ) ; end repeat
  41. (setq trgfile (strcat (getvar "dwgprefix") "pdf\" dwgname "-D" val1 "-D" val2 ".pdf"))
  42. (setq plotnames (reverse plotnames))
  43. (IF (= (length plotnames) 1)
  44. (princ)
  45. (progn
  46. (if (not combinepdf)(load "mergepdfs"))
  47. (combinepdf gsExe plotnames trgFile )
  48. )
  49. )
  50. ) ; defun
  51. (AH:pltlays)
  52. (princ)

 
  1. ;MergePdfs
  2. ;Merges multiple pdf (or eps) files into one
  3. ;Requires the installatoion of Ghostscript
  4. ; make a batch file ?
  5. ;gs -sDEVICE=pdfwrite \
  6. ;    -dNOPAUSE -dBATCH -dSAFER \
  7. ;    -sOutputFile=combined.pdf \
  8. ;    first.pdf \
  9. ;    second.pdf \
  10. ;    third.pdf [...]
  11. ;Ghostscript ([url]http://www.ghostscript.com/[/url]) can be used to combine PDFs.
  12. ; Something like this should work: by Roy_043
  13. (defun KGA_String_Join (strLst delim)
  14. (if strLst
  15. (apply
  16. 'strcat
  17. (cons
  18. (car strLst)
  19. (mapcar '(lambda (a) (strcat delim a)) (cdr strLst))
  20. )
  21. )
  22. ""
  23. )
  24. )
  25. ; (CombinePdf
  26. (setq gsexe "C:\\Program Files\\gs\\gs9.19\\bin\\gswin64c.exe")
  27. ; (setq srcFilelst  '("D:\\Tmp\\A.pdf" "D:\\Tmp\\B.pdf"))
  28. ; (setq trgfile "C:\\Acadtemp\\Total.pdf")
  29. ; )
  30. ; Note: Existing trgFile will be overwritten.
  31. (defun CombinePdf (gsExe srcFileLst trgFile)
  32. (startapp
  33. (strcat
  34. gsExe " "
  35. "-sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dQUIET  "
  36. "-sOutputFile="" trgFile "" "
  37. """ (KGA_String_Join srcFileLst "" "") """
  38. )
  39. )
  40. )

 
还有这个
  1. ; Input  Dialog box with variable title
  2. ; multiple lines of dcl input supported
  3. ; add extra lines if required by copying code defun
  4. ; By Alan H 2015
  5. (vl-load-com)
  6. ; 1 line dcl
  7. ; sample code (ah:getval1 "Line 1" 5 4)
  8. (defun AH:getval1 (title width limit def1 / fo fname)
  9. ; you can hard code a directory if you like for dcl file
  10. (setq fo (open (setq fname "c:\\acadtemp\\getval.dcl") "w"))
  11. (write-line "ddgetval : dialog {" fo)
  12. (write-line " : row {" fo)
  13. (write-line ": edit_box {" fo)
  14. (write-line (strcat "    key = "  (chr 34) "key1" (chr 34) ";") fo)
  15. (write-line  (strcat " label = "  (chr 34) title (chr 34) ";"  )   fo)
  16. ; these can be replaced with shorter value etc
  17. (write-line (strcat "     edit_width = " (rtos width 2 0) ";" ) fo)
  18. (write-line (strcat "     edit_limit = " (rtos limit 2 0) ";" ) fo)
  19. (write-line "   is_enabled = true;" fo)
  20. (write-line "    }" fo)
  21. (write-line "  }" fo)
  22. (write-line "ok_only;}" fo)
  23. (close fo)
  24. (setq dcl_id (load_dialog  fname))
  25. ; pt is a list 2 numbs -1 -1 centre ('(20 20))
  26. ;(not (new_dialog "test" dch "" *screenpoint*))
  27. (if (not (new_dialog "ddgetval" dcl_id))
  28. (exit))
  29. (set_tile "key1" (setq val1 def1))
  30. (action_tile "key1" "(setq val1 $value)")
  31. (mode_tile "key1" 3)
  32. (start_dialog)
  33. (done_dialog)
  34. (unload_dialog dcl_id)
  35. ; returns the value of val1 as a string
  36. (vl-file-delete fname)
  37. ) ; defungetval1
  38. ; 2 line dcl
  39. ; sample code (ah:getval2 "Line 1" 5 4 "Line2" 8 7)
  40. (defun AH:getval2 (title1 width1 limit1 def1 title2 width2 limit2 def2 / fo fname)
  41. (setq fo (open (setq fname "c:\\acadtemp\\getval.dcl") "w"))
  42. (write-line "ddgetval2 : dialog {" fo)
  43. (write-line " : column {" fo)
  44. (write-line ": edit_box {" fo)
  45. (write-line (strcat "    key = " (chr 34) "key1" (chr 34) ";") fo)
  46. (write-line  (strcat " label = "  (chr 34) title1 (chr 34) ";" ) fo)
  47. (write-line (strcat "     edit_width = " (rtos width1 2 0) ";" ) fo)
  48. (write-line (strcat "     edit_limit = " (rtos limit1 2 0) ";" ) fo)
  49. (write-line "   is_enabled = true ;" fo)
  50. (write-line "    }" fo)
  51. (write-line "spacer_1 ;" fo)
  52. (write-line ": edit_box {" fo)
  53. (write-line (strcat "    key = " (chr 34) "key2" (chr 34) ";") fo)
  54. (write-line (strcat " label = "  (chr 34) title2 (chr 34) ";"  ) fo)
  55. (write-line (strcat "     edit_width = " (rtos width2 2 0) ";" ) fo)
  56. (write-line (strcat "     edit_limit = " (rtos limit2 2 0) ";" ) fo)
  57. (write-line "   is_enabled = true ;" fo)
  58. (write-line "    }" fo)
  59. (write-line "    }" fo)
  60. (write-line "spacer_1 ;" fo)
  61. (write-line "ok_only;}" fo)
  62. (close fo)
  63. ; code part
  64. (setq dcl_id (load_dialog  fname))
  65. (if (not (new_dialog "ddgetval2" dcl_id))
  66. (exit))
  67. (mode_tile "key1" 3)
  68. (set_tile "key1" (setq val1 def1))
  69. (action_tile "key1" "(setq val1 $value)")
  70. (mode_tile "key2" 3)
  71. (set_tile "key2" (setq val2 def2))
  72. (action_tile "key2" "(setq val2 $value)")
  73. (start_dialog)
  74. (done_dialog)
  75. (unload_dialog dcl_id)
  76. ; returns the value of val1 and val2 as strings
  77. (vl-file-delete fname)
  78. ) ; defungetval2
  79. ; 3 line dcl
  80. ; sample code (ah:getval3 "Line 1" 5 4 "0.9" "Line 2" 8 7 "wow" "Line 3" 6 4 "123")
  81. (defun AH:getval3 (title1 width1 limit1 def1 title2 width2 limit2 def2 title3 width3 limit3 def3 / fo fname)
  82. (setq fo (open (setq fname "c:\\acadtemp\\getval.dcl") "w"))
  83. (write-line "ddgetval3 : dialog {" fo)
  84. (write-line " : column {" fo)
  85. (write-line ": edit_box {" fo)
  86. (write-line (strcat "    key = " (chr 34) "key1" (chr 34) ";") fo)
  87. (write-line  (strcat " label = "  (chr 34) title1 (chr 34) ";" ) fo)
  88. (write-line (strcat "     edit_width = " (rtos width1 2 0) ";" ) fo)
  89. (write-line (strcat "     edit_limit = " (rtos limit1 2 0) ";" ) fo)
  90. (write-line "   is_enabled = true ;" fo)
  91. (write-line "    }" fo)
  92. (write-line "spacer_1 ;" fo)
  93. (write-line ": edit_box {" fo)
  94. (write-line (strcat "    key = " (chr 34) "key2" (chr 34) ";") fo)
  95. (write-line (strcat " label = "  (chr 34) title2 (chr 34) ";"  ) fo)
  96. (write-line (strcat "     edit_width = " (rtos width2 2 0) ";" ) fo)
  97. (write-line (strcat "     edit_limit = " (rtos limit2 2 0) ";" ) fo)
  98. (write-line "   is_enabled = true ;" fo)
  99. (write-line "    }" fo)
  100. (write-line "spacer_1 ;" fo)
  101. (write-line ": edit_box {" fo)
  102. (write-line (strcat "    key = " (chr 34) "key3" (chr 34) ";") fo)
  103. (write-line (strcat " label = "  (chr 34) title3 (chr 34) ";"  ) fo)
  104. (write-line (strcat "     edit_width = " (rtos width3 2 0) ";" ) fo)
  105. (write-line (strcat "     edit_limit = " (rtos limit3 2 0) ";" ) fo)
  106. (write-line "   is_enabled = true ;" fo)
  107. (write-line "    }" fo)
  108. (write-line "    }" fo)
  109. (write-line "spacer_1 ;" fo)
  110. (write-line "ok_only;}" fo)
  111. (close fo)
  112. ; code part
  113. (setq dcl_id (load_dialog  fname))
  114. (if (not (new_dialog "ddgetval3" dcl_id))
  115. (exit))
  116. (mode_tile "key1" 3)
  117. (set_tile "key1" (setq val1 def1))
  118. (action_tile "key1" "(setq val1 $value)")
  119. (mode_tile "key2" 3)
  120. (set_tile "key2" (setq val2 def2))
  121. (action_tile "key2" "(setq val2 $value)")
  122. (mode_tile "key3" 3)
  123. (set_tile "key3" (setq val3 def3))
  124. (action_tile "key3" "(setq val3 $value)")
  125. (start_dialog)
  126. (done_dialog)
  127. (unload_dialog dcl_id)
  128. ; returns the value of val1 val2 and val3 as strings
  129. (vl-file-delete fname)
  130. ) ; defungetval3
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 05:15 , Processed in 0.671834 second(s), 56 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表