乐筑天下

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

[编程交流] 创建无打印命令的PDF

[复制链接]

13

主题

36

帖子

23

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 00:18:59 | 显示全部楼层
你好
 
首先,我要感谢你给出的所有答案。
 
以下是我的总结。
我尝试了三种不同的方法。。。
1、自动发布
反应堆中的VLA SendCommand
3、重新定义保存命令
 
“自动发布”解决方案的代码。
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;;
  3. ;;;; Function to turn layers On or Off.
  4. ;;;;
  5. ;;;; Ex.
  6. ;;;;
  7. ;;;; In: (okg:LayerOn "SOSED_DESIGN" T)
  8. ;;;;
  9. ;;;; Out: Silent.
  10. ;;;;
  11. (defun okg:LayerOn (layer x)
  12. (if (not (vl-catch-all-error-p (setq layer (vl-catch-all-apply 'vla-item (list (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))) layer)))))
  13. (if x
  14.   (vlax-put layer 'layeron 1)
  15.   (vlax-put layer 'layeron 0)
  16. )
  17. )
  18. (princ)
  19. )
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21. ;;;;
  22. ;;;; Set current plot settings.
  23. ;;;;
  24. (command "-plot" "Y" "Model" "DWG To PDF.pc3" "ISO full bleed A3 (420.00 x 297.00 MM)" "Millimeter" "Landscape" "N" "E" "F" "C" "Y" "elmaster.ctb" "Y" "As displayed" "c:\\temp\\temp.pdf" "Y" "N")
  25. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  26. ;;;;
  27. ;;;; AutoPublish Settings.
  28. ;;;;
  29. ; AutoPublish turned on
  30. (setvar "AUTOMATICPUB" 1)
  31. ; Publish on = Save
  32. (vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "PublishOn" 0)
  33. ; Location = .\DWF and PDF(sub-folder relative to drawing folder)
  34. (vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "PublishTo" 2)
  35. ; Include = Model
  36. (vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "IncludeOption" 0)
  37. ; File format = PDF
  38. (vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "EplotFormat" 3)
  39. ; Type = Single-sheet file
  40. (vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "MultiSheetFile" 0)
  41. ; Layer information = Include
  42. (vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "IncludeLayerInfo" 1)
  43. ; Merge control = Lines overwrite
  44. (vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "MergeControl" 0)
  45. ; Password protection = Disabled
  46. (vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "DwfPwdProtected" 0)
  47. (vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "PromptForPwd" 0)
  48. ; Block information = Don´t include
  49. (vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "IncludeBlockInfo" 0)
  50. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  51. ;;;;
  52. ;;;; Reactors that will turn off a specific layer before pdf creation.
  53. ;;;;
  54. ; Load reactor if not already loaded.
  55. (if (not (member "AutoPublishStart" (mapcar 'vlr-data (cdar (vlr-reactors :vlr-command-reactor)))))
  56. (setq r:AutoPublishWillStart (vlr-command-reactor "AutoPublishStart" '((:vlr-CommandWillStart . rf:AutoPublishWillStart))))
  57. )
  58. ; Load reactor if not already loaded.
  59. (if (not (member "AutoPublishEnd" (mapcar 'vlr-data (cdar (vlr-reactors :vlr-command-reactor)))))
  60. (setq r:AutoPublishEnded (vlr-command-reactor "AutoPublishEnd" '((:vlr-commandEnded . rf:AutoPublishEnded))))
  61. )
  62. ; Callback function that will turn off a layer before AutoPublish.
  63. (defun rf:AutoPublishWillStart (reactor commandName)
  64. (if (= commandName "AUTOPUBLISH")
  65. ; Here you put anything you want to do before the pdf is created.
  66. ; An example could be a timestamp on the pdf, but in this case I turn a layer off.
  67. (okg:LayerOn "SOSED_DESIGN" nil)
  68. )
  69. )
  70. ; Callback function that will turn on a layer after AutoPublish.
  71. (defun rf:AutoPublishEnded (reactor commandName)
  72. (if (= commandName "AUTOPUBLISH")
  73. ; Put things back to normal.
  74. (okg:LayerOn "SOSED_DESIGN" T)
  75. )
  76. )

 
 
 
 
“反应堆中的VLA SendCommand”解决方案的代码。
  1. (if (not a)
  2. (setq a (vlr-command-reactor nil '((:vlr-commandEnded . endCommand))))
  3. )
  4. (defun endCommand (calling-reactor endcommandInfo / doc filedia fileName)
  5. (if (wcmatch (car endcommandInfo) "SAVE,QSAVE,SAVEAS")
  6. (progn
  7.   (setq filedia (getvar "filedia"))
  8.   (setvar "filedia" 0)
  9.   ;(okg:layeron "SOSED_DESIGN" nil)
  10.   (setq fileName "C:\\temp\\test.pdf")
  11.   (if (findfile fileName)
  12.    (setq fileName (strcat fileName "\r\Y"))
  13.   )
  14.   (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  15.   (vla-sendcommand doc (strcat "-plot\rY\rModel\rDWG To PDF.pc3\rISO full bleed A3 (420.00 x 297.00 MM)\rMillimeter\rLandscape\rN\rE\rF\rC\rY\relmaster.ctb\rY\rA\r" fileName "\rN\rY\r"))
  16.   (setvar "filedia" filedia)
  17.   ;(okg:layeron "SOSED_DESIGN" T)
  18. )
  19. )
  20. )

 
 
 
 
“重新定义保存命令”解决方案的代码。
  1. (defun c:QSave ()
  2. ; PDF
  3. (AddSomePdfFunction)
  4. ; QSave
  5. (command "_.qsave")
  6. )
  7. (defun c:Save ()
  8. ; PDF
  9. (AddSomePdfFunction)
  10. ; Save
  11. (command "_.save")
  12. )
  13. (defun c:SaveAs()
  14. ; PDF
  15. (AddSomePdfFunction)
  16. ; SaveAs
  17. (command "_.saveas")
  18. )

 
 
 
 
文字总结:
“1.自动发布”
这个解决方案很有效,我想做的一切都奏效了。
在pdf创建之前和之后执行所需的操作相对简单,例如在创建之前关闭一个层,然后再打开它。
我推荐这种解决方案。
 
“2.VLA SendCommand在反应堆中”
解决方案可行,但在创建pdf之前和之后很难执行所需的操作。
就我个人而言,我不喜欢在任何语言中使用sendcommand。
我不推荐这种解决方案。
 
 
“3.重新定义保存命令”
效果很好,你完全可以控制。
在我的工作区,save命令已经被重新定义,所以这次我不会使用这个方法。
我推荐这种解决方案。
回复

使用道具 举报

4

主题

194

帖子

192

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-6 00:26:43 | 显示全部楼层
很高兴听到您考虑将“SAVE”命令重新定义为一个可行的选项。无需担心重新定义ACAD命令来定制平台以满足特定用户的需求,这正是为什么它最初被赋予如此大的灵活性。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-9 19:34 , Processed in 0.587701 second(s), 54 queries .

© 2020-2025 乐筑天下

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