Author Topic: Help to improve lisp purge  (Read 1814 times)

0 Members and 1 Guest are viewing this topic.

Aldo

  • Newt
  • Posts: 22
Help to improve lisp purge
« on: October 12, 2016, 11:54:04 AM »
Dear
I have this lisp purge all files in a particular folder is very useful, the problem is that not purge the scales I'm not using, forcing me to use a second lisp and do it manually, I would like you could give me a hand and try to bring together these two lisp into one, and eventually also purge the list of scales. very grateful for the help

The first lisp is:


;;; This lisp purge dwg files from selected folder


(vl-load-com)

(defun c:PurgeAuditFiles (/ FilesList DwgPath SubDir Files File)

(defun GetFolder (/ Dir Item Path)
 (cond
  ((setq Dir (vlax-invoke (vlax-get-or-create-object "Shell.Application") 'browseforfolder 0 "Select folder with DWG files:" 1 ""))
   (cond
    ((not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-invoke-method (list Dir 'Items))))
     (setq Item (vlax-invoke-method (vlax-invoke-method Dir 'Items) 'Item))
     (setq Path (vla-get-path Item))
     (if (not (member (substr Path (strlen Path) 1) (list "/" "\\")))
      (setq Path (strcat Path "\\"))
     );end if
    )
   );end cond
  )
 );end cond
 Path
);end GetFolder


(defun vl-findfile (Location / DirList Path AllPath)
 (MakeDirList Location)
 (setq DirList (cons Location DirList))
 (foreach Elem DirList
  (if (setq Path (vl-directory-files Elem "*.dwg"))
   (foreach Item Path (setq AllPath (cons (strcat Elem "/" Item)  AllPath)))
  );end if
 )
 (reverse AllPath)
);end vl-findfile

(defun MakeDirList (Arg / TmpList)
 (setq TmpList (cddr (vl-directory-files Arg nil -1)))
 (cond
  (TmpList
   (setq DirList (append DirList (mapcar '(lambda (z) (strcat Arg "/" z)) TmpList)))
   (foreach Item TmpList (MakeDirList (strcat Arg "/" Item)))
  )
 );end cond
);end MakeDirList

(if (not FileSystemObject)
  (setq FileSystemObject (vla-getInterfaceObject (vlax-get-acad-object) "Scripting.FileSystemObject"))
);end if

(cond
((= (getvar "SDI") 0)
(cond
 ((setq DwgPath (GetFolder))
  (initget "Yes No")
  (setq Subdir (cond ((getkword "\nLooking for subfolders? No,[Yes]: "))
           (T "Yes")))
  (if (equal SubDir "Yes")
   (setq Files (vl-findfile (substr DwgPath 1 (1- (strlen DwgPath)))))
   (setq Files (mapcar '(lambda (x) (strcat dwgpath x))(vl-directory-files DwgPath "*.dwg" 1)))
  );end if
  (setq Files (mapcar 'strcase Files))
  (cond
    (Files
     (vlax-for & (vla-get-documents (vlax-get-acad-object )) (setq FilesList (cons (strcase (vla-get-fullname &)) FilesList)))
     (foreach & Files
      (cond
   ((not (member & FilesList ))
         (cond
     ((/= (logand (vlax-get-property (vlax-invoke-method FileSystemObject 'getfile &) 'Attributes) 1) 1)
      (cond
        ((setq File (vla-open (vla-get-documents (vlax-get-acad-object)) &))
         (prompt (strcat "\nPurge " & ". Please wait..."))
              (vla-purgeall File)
              (vla-AuditInfo File T)
         (prompt (strcat "\nSave and close " &))
         (vla-save File)
         (vla-close File)
         (vlax-release-object File)
        )
        (T (prompt (strcat "\nCannot open " & "\nDrawing file was created by an incompatible version. ")))
      );end cond
     )
     (T (prompt (strcat & " is read-only. Purge canceled. ")))
    );end cond
   )
   (T (prompt (strcat & " is open now. Purge canceled. ")))
      );end cond

     );end foreach
    )
    (T (prompt "\nNothing files found to purge. "))
  );end cond
 )
 (T (prompt "\nNothing selected. "))
);end cond
)
(T (prompt "\nThe routine is not available in SDI mode. "))
);end cond
(princ)
);end c:PurgeFile

(prompt "\nLoaded new command PurgeFiles. ")
(princ)




The second lisp is:

;;; This routine removes unused files scales

(defun c:PUS () (c:Purgelistscale))
(defun c:Purgelistscale (/)

(command "_.-scalelistedit" "_r" "n" "_d" "*" "e")
);end c:Purgelistscale

(prompt "\nLoaded new command Purgelistscale. ")
(princ)


Thanks for the help

stevej

  • Newt
  • Posts: 30
Re: Help to improve lisp purge
« Reply #1 on: October 12, 2016, 01:01:58 PM »
Code header for PurgeAuditFiles LISP:
Code: [Select]
;;;CADALYST 03/05 Tip2023: PurgeFiles.lsp Directory Clean Up (c) Andrzej Gumula
 
;;; [c]2004 Andrzej Gumula, Katowice, Poland
;;; e-mail: a.gumula@wp.pl
;;; This routine purge dwg files from selected folder
« Last Edit: October 12, 2016, 01:08:21 PM by stevej »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help to improve lisp purge
« Reply #2 on: October 12, 2016, 01:15:09 PM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Help to improve lisp purge
« Reply #3 on: October 13, 2016, 01:56:59 AM »
http://www.theswamp.org/index.php?topic=33516.0

if you're running AutoCAD 2012 or later, you'd rather use the RadicalPurge plugin (free) or BatchPurge (payed), both provide the gc-purge LISP function in addition to the commands.
Speaking English as a French Frog