Jump to content

Working with Nil


Cylis0509

Recommended Posts

Hi everyone,

 

I am using a LiSP found online as part of a larger LiSP I am building. The routine looks for not_found/unreferenced/orphaned/unloaded images and removes them. It works when images are present. The problem with the LiSP right now is that if there is not an image it errors out as ; error: bad argument type: lselsetp nil.

 

How can I modify this to move on in the code if no image is present? If nil do nothing. Also it seems to remove valid images as well. I would like it to just remove not_found/unreferenced/orphaned/unloaded images if present.

 

Thanks!

 

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

(defun c:imgdet2 (/
                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

Link to comment
Share on other sites

After a cursory glance, change:

    (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

to:

    (if (setq img_set (ssget "_x" '((0 . "IMAGE"))))
       (progn
           (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
       )
   )

Link to comment
Share on other sites

Lee,

 

That did it thank you very much! I feel like an idiot, I was so close, I had the (If and forgot to add the (progn. Thank you again. :)

Link to comment
Share on other sites

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