Jump to content

Recommended Posts

Posted

Every so often I come across a .dwg with orphaned or unloaded image files.

 

I know I can do a "-image" "d" "*" but that means every image gets detached. Does anyone know of a lisp or diesel routine that only detaches those images that aren't actually loaded into the drawing ?

 

Thanks in advance.

Posted

To clarify:

 

I want the xref's, if any, to be left alone. Or in other words that only the not used image files get detached.

 

Perhaps I'm just not connecting the proverbial dots so to speak but I can't see how to do it.

Posted

here's for unloaded imagedefinitions, i havent found a way how to detach ophaned/not found ones, may be others can help.

 

 

(defun c:imgdet (/ im_dict im_ent im_lst wiz_cnt)
   (vl-load-com)
   (setq im_dict (dictsearch (namedobjdict) "ACAD_IMAGE_DICT"))
   (setq wiz_cnt -1)
   (setq im_lst '())
   (while
       (setq im_ent
                (nth
                    (setq wiz_cnt (1+ wiz_cnt))
                    im_dict
                ) ;_ {nth
       ) ;_ {setq
          (if (eq (car im_ent) 3)
              (setq im_lst
                       (cons
                           (cons
                               (cdr im_ent)
                               (cdr
                                   (nth
                                       (setq wiz_cnt (+ wiz_cnt 1))
                                       im_dict
                                   ) ;_ {nth
                               ) ;_ {cdr
                           ) ;_ {cons
                           im_lst
                       ) ;_ {cons
              ) ;_ {setq
          ) ;_ {if
   ) ;_ end_while
   (mapcar
       (function
           (lambda (x)
               (if (zerop (cdr (assoc 280 (entget (cdr x)))))
                   (vla-delete (vlax-ename->vla-object (cdr x)))
               ) ;_ {if
           ) ;_ {lamda
       ) ;_ {function
       im_lst
   ) ;_ {mapcar
   (princ)
) ;_ {defun

Posted

Thank you kindly wizman.

 

I tried it out and it does what you said. Would it be nice if it dealt with orphaned/not found ones, ofcourse but.... even this helps a bunch.

Posted

please test thoroughly first:

 

;|***********************---wiz24MAR09---**************************
lisproutine for detaching not_found/unreferenced/orphaned/unloaded
images,not yet tested on nested images|;

(defun c:imgdet (/
                imgpath_lst
                img_dep
                img_info
                img_info340
                img_path
                img_set
                im_dict
                im_ent
                im_ent_1
                im_lst
                im_lst_1
                wiz_cnt
               )

   (vl-load-com)
;;;------------------------------------------------------------
   ;;List all images which are present in the drawing in var = im_lst_1
   (setq img_set (ssget "_x" '((0 . "IMAGE"))))
   (setq i (sslength img_set))
   (while (not (minusp (setq i (1- i))))
       (setq im_ent_1 (ssname img_set i))
       (setq img_info (entget im_ent_1))
       (setq img_info340 (entget (cdr (assoc 340 img_info))))
       (setq img_path (cdr (assoc 1 img_info340)))
       (if (not (member img_path im_lst_1))
           (setq im_lst_1 (cons img_path im_lst_1))
       ) ;_ {if
   ) ;_ {while

;;;------------------------------------------------------------  
   ;;List all images saved in the file_dependencies in var = imgpath_lst
   (setq imgpath_lst '())
   (vlax-for
            i
             (setq img_dep
                      (vla-get-FileDependencies
                          (vla-get-ActiveDocument
                              (vlax-get-Acad-Object)
                          ) ;_ {vla-get-ActiveDocument
                      ) ;_ {vla-get-FileDependencies
             ) ;_ {vla-get-FileDependencies
       (if (= (vla-get-Feature i) "Acad:Image")
           (setq imgpath_lst
                    (cons
                        (vl-catch-all-apply
                            (function
                                (lambda ()
                                    (vla-get-FullFileName i)
                                ) ;_ {lambda
                            ) ;_ {function
                        ) ;_ {VL-CATCH-ALL-APPLY
                        imgpath_lst
                    ) ;_ {cons
           ) ;_ {setq
       ) ;_ {if
   ) ;_ {vlax-for
                   ;(vlax-release-object img_dep)


;;;------------------------------------------------------------  
   ;;List all images saved in the image_dictionary in var im_lst
   (setq im_dict (dictsearch (namedobjdict) "ACAD_IMAGE_DICT"))
   (setq wiz_cnt -1)
   (setq im_lst '())
   (while
       (setq im_ent
                (nth
                    (setq wiz_cnt (1+ wiz_cnt))
                    im_dict
                ) ;_ {nth
       ) ;_ {setq
          (if (eq (car im_ent) 3)
              (setq im_lst ;_Image list to process below
                       (cons
                           (cons
                               (cdr im_ent)
                               (cdr
                                   (nth
                                       (setq wiz_cnt (+ wiz_cnt 1))
                                       im_dict
                                   ) ;_ {nth
                               ) ;_ {cdr
                           ) ;_ {cons
                           im_lst
                       ) ;_ {cons
              ) ;_ {setq
          ) ;_ {if
   ) ;_ end_while




;;;------------------------------------------------------------  
   ;;Begin Process
   ;;Check if im_lst is present in im_lst_1 and imgpath_lst
   ;;
   (mapcar
       (function
           (lambda (x)
               (if
                   (or
                       ;;If im_lst is not member of im_lst_1
                       ;;then it is orphaned/unreferenced
                       (not (member (cdr (assoc 1 (entget (cdr x)))) im_lst_1))

                       ;;if im_list is not member of imgpath_lst
                       ;;then it is not found
                       (not (member (cdr (assoc 1 (entget (cdr x))))
                                    imgpath_lst
                            ) ;_ {member
                       ) ;_ {not

                       ;;if assoc 280 is 0 then it is unloaded
                       (zerop (cdr (assoc 280 (entget (cdr x)))))
                   ) ;_ {or
                      (vl-catch-all-apply
                          (function
                              (lambda ()
                                  (vla-delete (vlax-ename->vla-object (cdr x)))
                              ) ;_ {lambda
                          ) ;_ {function
                      ) ;_ {vl-catch-all-apply
               ) ;_ {if
           ) ;_ {lamda
       ) ;_ {function
       im_lst
   ) ;_ {mapcar
   (princ)
) ;_ {defun

Posted

First testing of it shows that there are instances that a picture that is "loaded" also gets dumped but only if it is not showing and there for not used.

 

In other words it only actually leaves images that are used and viewable.

Fantastic!

 

Looking very promising indeed. Will test more thoroughly and get back to you if I see anything going amiss.

 

Thank you again.

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