Jump to content

Recommended Posts

Posted

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)

Posted

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

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

 

Well no, I didn't...:oops:

 

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...:?

Posted (edited)

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

Edited by Lee Mac
  • Like 1
Posted

I'll give it a shot, thanks.

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

Posted

Issuing

 

(CloseReactor)

 

Will toggle the reactor on and off :)

Posted

Just add something simple...

 

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

Posted
Just add something simple...

 

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

 

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

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

 

Correct. :thumbsup:

Posted

I find its better to have a toggle/off function with a reactor, with your original function, there was no inherent way to stop the reactor functioning.

Posted
I find its better to have a toggle/off function with a reactor, with your original function, there was no inherent way to stop the reactor functioning.

 

ditto 90% of the time.

Posted

It's ALIVE!!! It works. Thanks

 

However, it is not activated by default - how would I make it activate automatically by default?

Posted

Put

 

(CloseReactor)

 

In your ACADDOC.lsp (make sure the LISP is loaded also).

Posted
It's ALIVE!!! It works. Thanks

 

However, it is not activated by default - how would I make it activate automatically by default?

 

DANGEROUS!!!

 

:cry::cry:

 

This is something I would recommend you have to turn on.

Posted
DANGEROUS!!!

 

:cry::cry:

 

This is something I would recommend you have to turn on.

 

Cary likes to live life on the edge :twisted:

Posted
Cary likes to live life on the edge :twisted:

 

I seriously do not recommend you have this set to auto on. If you open a file, just to take something from it, print, etc. you will have to remember to turn the reactor off; otherwise, you will be changing the edit date of the file. This may not be a big deal to you, but you really should be aware it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...