Jump to content

Recommended Posts

Posted
Just as a side-line suggestion: wouldn't it be "better" to have such a thing run as a login script? Though even then I'd add some form of check before deleting, since others may already have the DWGs open before you login.

I want it to activate upon each drawing being opened. That way it cleans all the random crap files out of the directory. We've been using this for quite some time, and we'll have everyone in the office working in drawings from the same directory and have NEVER had a problem. If a dwl or dwl2 is part of an active drawing (you or anyone else has it open), it's considered read-only and vl-file-delete just nils and moves on.

  • Replies 35
  • Created
  • Last Reply

Top Posters In This Topic

  • Ahankhah

    10

  • irneb

    10

  • alanjt

    8

  • Lee Mac

    2

Top Posters In This Topic

Posted

Where is your code alanjt? I could use that. :thumbsup:

Posted
Where is your code alanjt? I could use that. :thumbsup:

; cleanup drawing directory
((lambda (path)
  (or (wcmatch (getvar 'dwgname) "Drawing*")
      (foreach file (vl-directory-files path nil 1)
        (if (wcmatch (strcase file) "*.LOG,*.ERR,*.DWL,*.DWL2")
          (vl-file-delete (strcat path file))
        )
      )
  )
)
 (getvar 'dwgprefix)
)

Posted

I hope your routine doesn't simply delete all of them! Since then you'll get the UnknownReadonly returned by my function. :o

Are you sure? When dwg is read only, dwl is also not eraseable:wink:.

Posted

For this I'd advise Ahankhah to rather put the close call as close as possible to the open - I'd actually place it directly after the open inside each cond condition. Even though you then need 2 duplicates in your function, it's just safer (you never know if you're going to extend your function later and have something work with that *f* variable, this is too critical to leave to chance). Even add a comment there to explain that you should never write anything to the *f* variable, just to remind yourself never to do so.

 

You are right Irné, thank you very much for your adviseo:).

Posted
Are you sure? When dwg is read only, dwl is also not eraseable:wink:.
Thanks yes, I just did the check for myself. So it is possible to simply "delete" them, since they're kept open! Other than I at first thought! So perhaps that function could actually delete them in the case of EditableAfterCrash.

 

I want it to activate upon each drawing being opened. That way it cleans all the random crap files out of the directory. We've been using this for quite some time, and we'll have everyone in the office working in drawings from the same directory and have NEVER had a problem. If a dwl or dwl2 is part of an active drawing (you or anyone else has it open), it's considered read-only and vl-file-delete just nils and moves on.
Thanks Alan! That's possibly a very good piece of code I'd like to add to our library as well!

 

Actually, running the vl-file-delete (purposefully) on a DWL of the current DWG ... I noticed it doesn't have a lag as the open function does before returning nil. So there's definitely a way of performing this much more efficiently and safely, though it's probably in C++.

Posted

Irné,,

the 'ReadOnly or '(ReadOnly) flag in my code indicates that the file has been set readonly attribute:whistle:.

Posted
; cleanup drawing directory
((lambda (path)
  (or (wcmatch (getvar 'dwgname) "Drawing*")
      (foreach file (vl-directory-files path nil 1)
        (if (wcmatch (strcase file) "*.LOG,*.ERR,*.DWL,*.DWL2")
          (vl-file-delete (strcat path file))
        )
      )
  )
)
 (getvar 'dwgprefix)
)

 

Thank you kind sir. Much appreciated. :thumbsup:

Posted

Oh, OK, then simply change the last condition in my defun to return 'ReadOnly instead of UnknownReadonly.

 

BTW, if you want to inspect the attributes of the file, then you can do so through the ActiveX object "Scripting.FileSystemObject": http://www.devguru.com/technologies/vbscript/quickref/file.html

 

From that you can find the attributes bitcode: http://www.devguru.com/technologies/vbscript/quickref/file_attributes.html

Posted
; cleanup drawing directory
((lambda (path)
  (or (wcmatch (getvar 'dwgname) "Drawing*")
      (foreach file (vl-directory-files path nil 1)
        (if (wcmatch (strcase file) "*.LOG,*.ERR,*.DWL,*.DWL2")
          (vl-file-delete (strcat path file))
        )
      )
  )
)
 (getvar 'dwgprefix)
)

 

Alan, what about hard coded directory location, how it will looks like?

Posted
Alan, what about hard coded directory location, how it will looks like?

swap out the (getvar 'dwgprefix) line.

Posted

Alan,

 

In this check:

 

(wcmatch (getvar 'dwgname) "Drawing*")

 

Are you checking whether the drawing has been saved as yet? If I've understood your intentions, you may be better to use:

 

(zerop (getvar 'DWGTITLED))

 

Lee

Posted

Another thing you could do is have a list of folders to work through. E.g. say you want to also test for such files in your temp folder and support paths:

(mapcar
 '(lambda (path)
    (and (vl-file-directory-p path)
         (foreach file (vl-directory-files path nil 1)
           (if (wcmatch (strcase file) "*.LOG,*.ERR,*.DWL,*.DWL2")
             (vl-file-delete (strcat path file))
           )
         )
    )
  )
 (append (if (wcmatch (getvar 'dwgname) "Drawing*")
           (list (getvar 'tempprefix))
           (list (getvar 'dwgprefix) (getvar 'tempprefix))
         )
         (LM:str->lst (getenv "ACAD") ";")
         '("My other folder path 1" "My other folder path 2")
 )
)

I've use Lee's string to list routine to split the support paths on semi-colons.

 

Though in such case you'd probably also need to check if that folder actually exists - else it may cause errors. Thus I've added the vl-file-directory-p check. Also moved the Drawing* check outside, since you only want this happening once.

Posted
Alan,

 

In this check:

 

(wcmatch (getvar 'dwgname) "Drawing*")

Are you checking whether the drawing has been saved as yet? If I've understood your intentions, you may be better to use:

 

(zerop (getvar 'DWGTITLED))

Lee

You know, I always forget about that system variable. In truth, the only reason I added the check was because if a drawing isn't saved, the dwgprefix return is the documents folder and I didn't want it filtering through a mountain of files that may reside in ones documents folder.

 

code changed...

 

; cleanup drawing directory
((lambda (path)
  (if (eq (getvar 'DWGTITLED) 1)
    (foreach file (vl-directory-files path nil 1)
      (if (wcmatch (strcase file) "*.LOG,*.ERR,*.DWL,*.DWL2")
        (vl-file-delete (strcat path file))
      )
    )
  )
)
 (getvar 'dwgprefix)
)

Posted

Here was one I used before we switched from XP to 7 when we were having all kinds of undo error (few threads floating around about it - one I started).

 

(defun c:CleanTemp nil
 ;; delete all UND* and RED* temp files
 (foreach x (vl-directory-files (getvar 'tempprefix))
   (if (wcmatch (strcase x) "UND*,RED*")
       (vl-catch-all-apply (function vl-file-delete) (list (strcat (getvar 'tempprefix) x)))
   )
 )
 (princ)
)

 

The vl-catch-all-apply isn't required, but I wasn't thinking that day and since I don't use it anymore, I don't really care.

Posted

How about doing it the other way round?

(defun c:CleanJunkFiles (/ path)
 (if (= (getvar 'DWGTitled) 1)
   (progn
     (setq path (getvar 'DWGPrefix))
     (foreach wc '("*.LOG" "*.ERR" "*.DWL" "*.DWL2")
       (foreach f (vl-directory-files path wc 1)
         (vl-file-delete (strcat path f))
       )
     )
   )
 )
 (setq path (getvar 'TempPrefix))
 (foreach wc '("UND*.*" "RED*.*" "*.LOG" "ACIS.*")
   (foreach f (vl-directory-files path wc 1)
     (vl-file-delete (strcat path f))
   )
 )
 (princ)
)

It should be a bit quicker if there's a huge amount of files in the folder.

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