BlackBox Posted June 26, 2013 Posted June 26, 2013 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. Cheers Quote
Recommended Posts
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.