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