chulse 发表于 2022-7-6 11:21:43

Reactor for dwg close - how to

I am working on a reactor to set several things on dwg close. A little background is HERE.
 
The trouble I am having now is that it seems to do what it's supposed to, except it doesn't save the changes.
I have this as part of the S::STARTUP (I have a "mystartup" appended to it and saved in the acaddoc.lsp file - shared on our network)
 
Any help greatly appreciated.
 

(defun Create_Close_Reactor() (vl-load-com) (if(not close:reactor)   (setq close:reactor   (vlr-editor-reactor nil       '((:vlr-beginClose . CloseReaction))))   ); end if (princ) ); end of Create_Close_Reactor(defun CloseReaction(args reac / tmp actDoc) (setq actDoc(vla-get-ActiveDocument       (vlax-get-acad-object)))(vla-put-ActiveSpace actDoc 1)(vla-ZoomExtents(vlax-get-acad-object))(vla-put-ActiveLayer actDoc   (vla-Item(vla-get-Layers actDoc)"0"))   ;;(repeat 3(vla-PurgeAll actDoc)) ;;set ucs to world;; (vla-put-ActiveUCS doc   (vla-add (vla-get-usercoordinatesystems doc)   (vlax-3D-point '(0. 0. 0.))       (vlax-3D-point '(1. 0. 0.))         (vlax-3D-point '(0. 1. 0.)) "TempWord_UCS"))          (vla-Save actDoc) (princ) ); end of CloseReaction(Create_Close_Reactor)

alanjt 发表于 2022-7-6 11:27:48

You do realize that you can never open a drawing without saving.

chulse 发表于 2022-7-6 11:29:33

 
Well no, I didn't...
 
But if I open a dwg, work on it, save it and close it, this reactor appears too make the changes before the close as it is supposed to (change to model space, zoom extents, set the ucs to world, etc - I can watch it do it)
but when I open the dwg again, it has not saved those changes??
I'm just not sure what I am missing here...

Lee Mac 发表于 2022-7-6 11:33:53

Hi Cary,
 
I might approach it like this:
 

(defun CloseReactor nil (vl-load-com) ;; Lee Mac~14.04.10 ((lambda ( data / react )      (if (setq react            (vl-some            (function                (lambda ( reactor )                  (if (eq data (vlr-data reactor)) reactor)                )            )            (cdar                (vlr-reactors :vlr-editor-reactor)            )            )          )      (if (vlr-added-p react)          (vlr-remove react)          (vlr-add react)      )      (setq react          (vlr-editor-reactor data            (list            (cons :vlr-beginclose 'CloseCallBack)            )          )      )      )      (princ      (if (vlr-added-p react)          "\n** Reactor Activated **"          "\n** Reactor Deactivated **"      )      )      react    )   "Close-Reactor" ) (princ))(defun CloseCallBack (reactor arguments) (vla-put-ActiveSpace   (setq doc (vla-get-ActiveDocument               (setq acad (vlax-get-acad-object))             )   )   acModelSpace ) (vla-ZoomExtents acad) (vla-put-ActiveLayer doc   (vla-item   (vla-get-layers doc) "0"   ) ) (vla-put-ActiveUCS doc   (vla-add   (vla-get-usercoordinatesystems doc)       (vlax-3D-point '(0. 0. 0.))         (vlax-3D-point '(1. 0. 0.))         (vlax-3D-point '(0. 1. 0.)) "TempWord_UCS"   ) ) (if (not (eq "" (vla-get-FullName doc)))   (vla-saveas doc (vla-get-FullName doc)) ) (princ))
Here, the reactor function is a toggle, and can be toggled on and off whilst the drawing is open. The reactor will only save the drawing if the drawing has been saved previously.
 
Its untested, but hopefully should work for you.
 
Lee

chulse 发表于 2022-7-6 11:37:33

I'll give it a shot, thanks.
How do you toggle it (what command, I don't see how you did that...)?

Lee Mac 发表于 2022-7-6 11:40:10

Issuing
 

(CloseReactor)
 
Will toggle the reactor on and off

chulse 发表于 2022-7-6 11:40:59

I see. I don't understand it... but I see it

alanjt 发表于 2022-7-6 11:46:30

Just add something simple...
 

(defun c:Test (/) (CloseReactor))

chulse 发表于 2022-7-6 11:49:54

 
...so that would assign a normal command line command to the reactor toggle then? (so it didn't need to be written in parenthesis?)

alanjt 发表于 2022-7-6 11:50:52

 
Correct.
页: [1] 2
查看完整版本: Reactor for dwg close - how to