首先,我要感谢你给出的所有答案。
以下是我的总结。
我尝试了三种不同的方法。。。
1、自动发布
反应堆中的VLA SendCommand
3、重新定义保存命令
“自动发布”解决方案的代码。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
;;;; Function to turn layers On or Off.
;;;;
;;;; Ex.
;;;;
;;;; In: (okg:LayerOn "SOSED_DESIGN" T)
;;;;
;;;; Out: Silent.
;;;;
(defun okg:LayerOn (layer x)
(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)))))
(if x
(vlax-put layer 'layeron 1)
(vlax-put layer 'layeron 0)
)
)
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
;;;; Set current plot settings.
;;;;
(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")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
;;;; AutoPublish Settings.
;;;;
; AutoPublish turned on
(setvar "AUTOMATICPUB" 1)
; Publish on = Save
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "PublishOn" 0)
; Location = .\DWF and PDF(sub-folder relative to drawing folder)
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "PublishTo" 2)
; Include = Model
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "IncludeOption" 0)
; File format = PDF
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "EplotFormat" 3)
; Type = Single-sheet file
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "MultiSheetFile" 0)
; Layer information = Include
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "IncludeLayerInfo" 1)
; Merge control = Lines overwrite
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "MergeControl" 0)
; Password protection = Disabled
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "DwfPwdProtected" 0)
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "PromptForPwd" 0)
; Block information = Don´t include
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-A001:409\\Profiles\\Master Concept 11 (SWE)\\Dialogs\\AcAutoPublishOpts" "IncludeBlockInfo" 0)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
;;;; Reactors that will turn off a specific layer before pdf creation.
;;;;
; Load reactor if not already loaded.
(if (not (member "AutoPublishStart" (mapcar 'vlr-data (cdar (vlr-reactors :vlr-command-reactor)))))
(setq r:AutoPublishWillStart (vlr-command-reactor "AutoPublishStart" '((:vlr-CommandWillStart . rf:AutoPublishWillStart))))
)
; Load reactor if not already loaded.
(if (not (member "AutoPublishEnd" (mapcar 'vlr-data (cdar (vlr-reactors :vlr-command-reactor)))))
(setq r:AutoPublishEnded (vlr-command-reactor "AutoPublishEnd" '((:vlr-commandEnded . rf:AutoPublishEnded))))
)
; Callback function that will turn off a layer before AutoPublish.
(defun rf:AutoPublishWillStart (reactor commandName)
(if (= commandName "AUTOPUBLISH")
; Here you put anything you want to do before the pdf is created.
; An example could be a timestamp on the pdf, but in this case I turn a layer off.
(okg:LayerOn "SOSED_DESIGN" nil)
)
)
; Callback function that will turn on a layer after AutoPublish.
(defun rf:AutoPublishEnded (reactor commandName)
(if (= commandName "AUTOPUBLISH")
; Put things back to normal.
(okg:LayerOn "SOSED_DESIGN" T)
)
)
“反应堆中的VLA SendCommand”解决方案的代码。
(if (not a)
(setq a (vlr-command-reactor nil '((:vlr-commandEnded . endCommand))))
)
(defun endCommand (calling-reactor endcommandInfo / doc filedia fileName)
(if (wcmatch (car endcommandInfo) "SAVE,QSAVE,SAVEAS")
(progn
(setq filedia (getvar "filedia"))
(setvar "filedia" 0)
;(okg:layeron "SOSED_DESIGN" nil)
(setq fileName "C:\\temp\\test.pdf")
(if (findfile fileName)
(setq fileName (strcat fileName "\r\Y"))
)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(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"))
(setvar "filedia" filedia)
;(okg:layeron "SOSED_DESIGN" T)
)
)
)
“重新定义保存命令”解决方案的代码。
(defun c:QSave ()
(AddSomePdfFunction)
; QSave
(command "_.qsave")
)
(defun c:Save ()
(AddSomePdfFunction)
; Save
(command "_.save")
)
(defun c:SaveAs()
(AddSomePdfFunction)
; SaveAs
(command "_.saveas")
)
文字总结:
“1.自动发布”
这个解决方案很有效,我想做的一切都奏效了。
在pdf创建之前和之后执行所需的操作相对简单,例如在创建之前关闭一个层,然后再打开它。
我推荐这种解决方案。
“2.VLA SendCommand在反应堆中”
解决方案可行,但在创建pdf之前和之后很难执行所需的操作。
就我个人而言,我不喜欢在任何语言中使用sendcommand。
我不推荐这种解决方案。
“3.重新定义保存命令”
效果很好,你完全可以控制。
在我的工作区,save命令已经被重新定义,所以这次我不会使用这个方法。
我推荐这种解决方案。 很高兴听到您考虑将“SAVE”命令重新定义为一个可行的选项。无需担心重新定义ACAD命令来定制平台以满足特定用户的需求,这正是为什么它最初被赋予如此大的灵活性。
页:
1
[2]