Z1000 Posted June 17, 2011 Share Posted June 17, 2011 Hi all , Newbie LSP person here, long time user of AutoCAD. Working with various consultants having to integrate their drawings onto ours (Interior design) our drawings become bloated with crap.. Does anyone have an LSP routine that will automatically run on 'opening' of a file to audit / purge all / quick save? I require a step by step of where to save it and how to get it to work too please!! any help is much appreciated! thanks Quote Link to comment Share on other sites More sharing options...
Ahankhah Posted June 17, 2011 Share Posted June 17, 2011 1- Save the following code in your AutoCAD support folder with your desired name (I offer APQC.LSP). ;;; APQC.LSP, Audit-->Purge-->Qsave-->Close ;;; Mehre Taban Co., Mehrdad Ahankhah, [url="http://www.irancad.com/"]www.irancad.com[/url], [email="ahankhah@irancad.com"]ahankhah@irancad.com[/email] (vl-load-com) (defun [b][color=purple]C:APQC[/color][/b] () (MT:Do:Audit) (MT:Do:PurgeAllNested) (if (MT:Do:Qsave) (MT:Do:CloseDwg) ) ) (defun [b][color=purple]MT:Do:Audit[/color][/b] () (command "_.Audit" "y" "")) (defun [b][color=purple]MT:Do:PurgeAllNested[/color][/b] (/ Cont) (princ "\nPurging unused objects...\n") (setq Cont T) (while Cont (MT:Do:PurgeALL) (if (zerop (boole 1 1 (getvar 'Dbmod))) (progn (acad-pop-dbmod) (setq Cont nil)) (progn (acad-pop-dbmod) (if (not (zerop (getvar 'Dbmod))) (progn (MT:Do:Qsave) (acad-pop-dbmod)) ) (princ "\n\tPurging unused nested objects...") ) ; if false ) ; if ) ; while (princ "\nPurging unused objects done.\n") ) (defun [b][color=purple]MT:Do:PurgeALL[/color][/b] () (vla-PurgeAll (vla-get-ActiveDocument (vlax-get-acad-object) ) ); Visual Lisp version ;;(command "_.PURGE" "_All" "*" "_No"); AutoLISP version ) (defun [b][color=purple]MT:Do:Qsave[/color][/b] (/ ret) (if (zerop (getvar "Dwgtitled")) (progn (alert "Drawing has no name, QSAVEing is not probable.") (setq ret nil) ) (progn (command "_.QSAVE") (setq ret T)) ) ret ) (defun [b][color=purple]MT:Do:CloseDwg[/color][/b] () (command "_.CLOSE") (and (= 1 (getvar 'cmdactive)) (command "_Yes")) ) [b][color=purple](C:APQC)[/color][/b] 2- Open AutoCAD. 3- Issue APPLOAD. 4- In the dialog, select Contents button in "Startup Suite" area. 5- Select "APQC.LSP" to add it to the list. 6- Close APPLOAD dialog. 7- Drag drawings into any point in AutoCAD GUI except "Drawing Area". 8- Wait and see how all drawings are processed one by one. 9- After completing the task, go to step 3. Now you must remove "APQC.LSP" from the Startup Suite's Contents list. Quote Link to comment Share on other sites More sharing options...
David Bethel Posted June 17, 2011 Share Posted June 17, 2011 Also see the 'Similar Threads' section below the last reply on this page. It should help as well. -David Quote Link to comment Share on other sites More sharing options...
Z1000 Posted June 20, 2011 Author Share Posted June 20, 2011 Hi, thanks for replies, your code worked well, however it closes the drawing after auditing and purging, i would like the drawing to stay open, so i can continue to work on it. i tried removing the last few lines of code but that unfortunetely caused a problem in the loop and thus it no longer works, is there a way to delete the 'close drawing' bit of code and still have the rest of it work? CHeers!!! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 20, 2011 Share Posted June 20, 2011 A quick modification, I hope Mehrdad doesn't mind: ;;; APQC.LSP, Audit-->Purge-->Qsave-->Close ;;; Mehre Taban Co., Mehrdad Ahankhah, www.irancad.com, ahankhah@irancad.com ;;; Modified by Lee Mac - 20.06.11 in places marked 'LM' (vl-load-com) (defun C:APQC nil (MT:Do:Audit) (MT:Do:PurgeAllNested) ;;; (if (MT:Do:Qsave) ;;; (MT:Do:CloseDwg) ;;; ) ) (defun MT:Do:Audit nil (command "_.Audit" "y" "")) (defun MT:Do:PurgeAllNested (/ Cont) (princ "\nPurging unused objects...\n") (setq Cont T) (while Cont (MT:Do:PurgeALL) (if (zerop (boole 1 1 (getvar 'Dbmod))) (progn (acad-pop-dbmod) (setq Cont nil)) (progn (acad-pop-dbmod) (if (not (zerop (getvar 'Dbmod))) (progn (MT:Do:Qsave) (acad-pop-dbmod)) ) (princ "\n\tPurging unused nested objects...") ) ; if false ) ; if ) ; while (princ "\nPurging unused objects done.\n") ) (defun MT:Do:PurgeALL nil (or *acdoc (setq *acdoc (vla-get-activedocument (vlax-get-acad-object)))) ;; LM (vla-PurgeAll *acdoc) ;; LM ) (defun MT:Do:Qsave (/ ret) (if (zerop (getvar "Dwgtitled")) (progn (alert "Drawing has no name, QSAVEing is not probable.") (setq ret nil) ) (progn (command "_.QSAVE") (setq ret T)) ) ret ) ;;;(defun MT:Do:CloseDwg nil ;;; (command "_.CLOSE") ;;; (and (= 1 (getvar 'cmdactive)) (command "_Yes")) ;; (C:APQC) Quote Link to comment Share on other sites More sharing options...
Z1000 Posted June 20, 2011 Author Share Posted June 20, 2011 Fantastic Lee Mac, thanks very much Quote Link to comment Share on other sites More sharing options...
Ahankhah Posted June 20, 2011 Share Posted June 20, 2011 A quick modification, I hope Mehrdad doesn't mind:... Lee, thank you very much for the nice and useful modifications. Quote Link to comment Share on other sites More sharing options...
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.