Detach image with LISP
How can I detach image from drawing with LISP (whitout dialog box)
Tihomir Bojanic
Comments
-
Here is an attempt to remove an image with lisp... it is not working properly though. I expect each image insertion to be removed by the imagedef_reactor once the imagedef is deleted but that is not happening. I don't have time to dig any deeper but maybe this is enough to get you going or someone else may be able to help you more.
;;; Save to a file called remove_image.lsp
;;;
(defun remove_image ( en / en ed idef idef_r)
(setq ed (entget en))
(cond
((= (cdr (assoc 0 ed)) "IMAGE")
;; get the entity name for the imagedef
(setq idef (cdr (assoc 340 ed)))
;; get the entity name of the imagedef_reactor
(setq idef_r (cdr (assoc 360 ed)))
;;delete the imagedef entity
(entdel idef)
;; delete the imagedef_reactor
(entdel idef_r)
(not (entget en))
)
(1
(princ "\nERR: invalid entity...")
NIL
)
)
)
(defun C:TEST ()
(if
(remove_image
(car (entsel "Select an image to remove: ")))
(princ "\nOK: image removed...")
(princ "\nERR: image not removed...")
)
(princ)
)
(princ "\nTEST to run...")
(princ)0 -
Oh yeah, I'm not sure if it safe to entdel reactors... you should look that up.
0 -
Thank you Greg, but I have already found code for that
http://www.caduser.ru/forum/index.php?PAGE_NAME=read&FID=22&TID=39973
Tihomir
;********************************************************************************PASTE CODE HERE
(defun C:ImgDet (/ all_raster_image_name image_set used_raster_image_name)
(defun DetachImage (ImgName)
(vl-catch-all-apply
'(lambda ()
(vla-delete
(vla-item
(vla-item
(vla-get-dictionaries
(vla-get-activedocument (vlax-get-acad-object))
) ;_ end of vla-get-dictionaries
"ACAD_IMAGE_DICT"
) ;_ end of vla-Item
ImgName
) ;_ end of vla-Item
) ;_ end of vla-Delete
) ;_ end of lambda
) ;_ end of vl-catch-all-apply
) ;_ end of defun
(vl-load-com)
(setvar "CMDECHO" 0)
(if
(setq all_raster_image_name
(mapcar 'cdr
(vl-remove-if-not
(function (lambda (x) (= 3 (car x))))
(dictsearch (namedobjdict) "ACAD_IMAGE_DICT")
) ;_ end of vl-remove-if-not
) ;_ end of mapcar
) ;_ end of setq
(setq all_raster_image_name (mapcar 'strcase all_raster_image_name))
) ;_ end of if
(if (setq image_set (ssget "_X" '((0 . "IMAGE"))))
(progn
(setq used_raster_image_name
(mapcar
'vla-get-name
(mapcar 'vlax-ename->vla-object
(vl-remove-if
'listp
(mapcar 'cadr (ssnamex image_set))
) ;_ end of vl-remove-if
) ;_ end of mapcar
) ;_ end of mapcar
) ;_ end of setq
(setq used_raster_image_name (mapcar 'strcase used_raster_image_name))
) ;_ end of progn
) ;_ end of if
(mapcar
'(lambda (img) (setq all_raster_image_name (vl-remove img all_raster_image_name)))
used_raster_image_name
) ;_ end of mapcar
; (foreach item all_raster_image_name (command "_.-IMAGE" "_Detach" item))
(mapcar 'DetachImage all_raster_image_name)
(mapcar '(lambda (x) (princ x) (princ " ")) all_raster_image_name)
(princ)
) ;_ end of defun0 -
hi,
just in case it is to any reader here of any help:
http://blog.jtbworld.com/2009/06/purge-unreferenced-images-in-autocad.html
0