(vl-file-delete) Not Work

(vl-file-delete) Not Work

neam
Collaborator Collaborator
1,939 Views
10 Replies
Message 1 of 11

(vl-file-delete) Not Work

neam
Collaborator
Collaborator

HI every body

i found unref.lsp in autocad forums and I tried to delete some unused images in dwg file from Windows folder with some modifications to this module.

but this modifications (vl-file-delete) doesn't work.

can you help me find the bug. 

 

0 Likes
Accepted solutions (2)
1,940 Views
10 Replies
Replies (10)
Message 2 of 11

dlanorh
Advisor
Advisor

Hmm, it works for me in a small test. Are the image files you want to delete in the same folder as the drawing? If not, they won't be deleted as the path reference used is the folder in which the drawing resides.

I am not one of the robots you're looking for

0 Likes
Message 3 of 11

neam
Collaborator
Collaborator

Thanks for reply dlanorh

Be sure it is

I really don't know what to check

 

0 Likes
Message 4 of 11

neam
Collaborator
Collaborator

My windows is seven

my autcad is 2013

my folder isn’t right protected 

i administrator on my pc

.........

i tired 

0 Likes
Message 5 of 11

john.uhden
Mentor
Mentor

Somehow I may remember that the vl-file-delete function is not reliable, so I think I always used the DOSLIB version instead.  Wrong.  I just checked and I use to use it a lot.  It was only back when transitioning from R14 to R15 that I had to use dos_delete.

Most likely, any problems you have are related to either the file's path or rights.

John F. Uhden

0 Likes
Message 6 of 11

neam
Collaborator
Collaborator

it is necessary to mention

When i change status of images from unreferenced to unloaded by classicimage command   It’s work 

0 Likes
Message 7 of 11

neam
Collaborator
Collaborator

Thankful john

 Please look at my last reply 

0 Likes
Message 8 of 11

john.uhden
Mentor
Mentor
Accepted solution
It appears that AutoCAD is trying to protect us from ourselves. But that
is stupid because if the reference has been erased then you have no choice
but to reattach it if you want it back. It's like keeping a nagging ghost
around. Shoo, shoo.

John F. Uhden

0 Likes
Message 9 of 11

dlanorh
Advisor
Advisor
Accepted solution

OK, try this. It works on my system Win7 Autocad 2012. NO error routine

 

;;Remove Unreferenced Images. Parts based on code by T Willey
(defun c:RUI ( / rh:referenced d_lst dict i_lst u_lst img i_path tmp cnt) (defun rh:referenced (ent / cnt e_lst i_path) (setq cnt 0) (foreach pr (entget ent) (if (= (car pr) 1) (setq i_path (cdr pr))) (if (and (equal (car pr) 330) (setq e_lst (entget (cdr pr))) (= (cdr (assoc 0 e_lst)) "IMAGEDEF_REACTOR")) (foreach itm e_lst (if (and (equal (car itm) 330) (entget (cdr itm))) (setq cnt (1+ cnt)))) );end_if );end_foreach (if (> cnt 0) nil i_path) );end_defun (setq sv_lst (list 'dynmode 'dynprompt) sv_vals (mapcar 'getvar sv_lst) );end_setq (mapcar 'setvar sv_lst (list 3 1)) (if (setq d_lst (dictsearch (namedobjdict) "ACAD_IMAGE_DICT")) (foreach pr d_lst (cond ( (and img (equal (car pr) 350)) (setq i_lst (entget (setq ent (cdr pr)))) (if (or (equal (cdr (assoc 280 i_lst)) 0) (setq i_path (rh:referenced (cdr pr)))) (setq u_lst (cons (list img (cdr pr) i_path) u_lst)) ) ) ( (equal (car pr) 3) (setq img (cdr pr))) (t (setq img nil)) );end_cond );end_foreach );end_cond (cond (u_lst (initget "Yes No") (setq tmp (cond ( (getkword "\nDelete Unreferenced Images from Disk : ? [Yes/No] <No> ")) ("No"))) (setq dict (cdr (assoc -1 d_lst)) cnt (length u_lst)) (foreach itm u_lst (dictremove dict (car itm)) (entdel (cadr itm)) (if (= tmp "Yes") (vl-file-delete (caddr itm))) );end_foreach (if (= tmp "No") (prompt (strcat "\n" (itoa cnt) " Image definition(s) removed.")) (prompt (strcat "\n" (itoa cnt) " Image definition(s) Removed & " (itoa cnt) " File(s) Deleted.")) );end_if ) );end_cond (mapcar 'setvar sv_lst sv_vals) (princ) );end_defun

I've tested this on my system by inserting raster images into a drawing, then deleting some of them. This leaves unreferenced items as seen in the External References. The path information for each image definition is stored. This is collected for unreferenced images and used to delete them from disk. You will be prompted using the dynamic prompt and asked if you want to delete unreferenced images from disk "Yes/No"  (default "No").

 

Yes will remove the unreferenced image definitions and delete the image files

No will just remove the unreferenced image definitions

I am not one of the robots you're looking for

Message 10 of 11

neam
Collaborator
Collaborator

dear john

Thank you very much for you guide

🙏🙏

0 Likes
Message 11 of 11

neam
Collaborator
Collaborator

Dear dlanorh

Thank you very much 

Because of the time you asked me to answer

🙏🙏

0 Likes