Jump to content

Recommended Posts

Posted

Here's a quickly written example using Visual LISP, tested briefly (on an already cleaned set of drawings)... One need only have this code load with AcadDoc.lsp... Regapps are purged at drawing open, and again upon Save*, along with a call to PurgeAll, setting system variables, and a zoom extents.

 

(vl-load-com)
;;;---------------------------------------------------------------------;
(defun Cleanup:StartReactor ()
 (or *CleanupReactor*
     (setq *CleanupReactor*
            (vlr-editor-reactor
              "My cleanup reactor"
              '(
                (:vlr-commandwillstart . Cleanup:OnCommandWillStart)
               )
            )
     )
 )
 (prompt "\nCleanup reactor loaded. ")

 ;; purge regapps only
 (Cleanup:PurgeRegAppsOnly
   (vla-get-activedocument (vlax-get-acad-object))
 )
 (prompt "\n[Cleanup] : Purged regapps only ")

 (princ)
)
;;;---------------------------------------------------------------------;
(defun Cleanup:OnCommandWillStart
      (rea cmd / *error* mspace acApp acDoc)

 (defun *error* (msg)

   ;; restore pviewport active, if applicable
   (if mspace
     (vla-put-mspace acDoc :vlax-true)
   )
   (cond ((not msg))                                                   ; Normal exit
         ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
         ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
   )
   (princ)
 )

 (if (wcmatch (strcase (car cmd)) "*CLOSE*,*SAVE*")
   (progn

     ;; purge regapps only
     (Cleanup:PurgeRegAppsOnly
       (setq acDoc (vla-get-activedocument
                     (setq acApp (vlax-get-acad-object))
                   )
       )
     )

     ;; if pviewport active, go to paper space
     (if (setq mspace (< (getvar 'tilemode) 1 (getvar 'cvport)))
       (vla-put-mspace acDoc :vlax-false)
     )

     ;; purge all
     (repeat 3 (vla-purgeall acDoc))

     ;; set system variables
     (foreach x '((gridmode 0)
                  (snapmode 0)
                  ;;<-- more here
                 )
       (vl-catch-all-apply 'setvar x)
     )

     ;; zoom extents
     (vla-zoomextents acApp)

     (prompt "\n[Cleanup] : Purged regapps/all, set sysvars, and zoom "
     )
   )
 )
 (*error* nil)
)
;;;---------------------------------------------------------------------;
(defun Cleanup:PurgeRegAppsOnly (doc)
 (vlax-for x (vla-get-registeredapplications doc)
   (vl-catch-all-apply 'vla-delete (list x))
 )
)
;;;---------------------------------------------------------------------;
(Cleanup:StartReactor)
(princ)

 

... Not sure how you work, but if performing the ZoomExtents in PViewport active presents an issue, consider this post... Never mind, I've built that into the revised code above, just in case. :thumbsup:

 

Cheers

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • ReMark

    7

  • SimonC

    7

  • BlackBox

    4

  • dbroada

    3

Popular Days

Top Posters In This Topic

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