PDA

View Full Version : Image Name


Rnykster
2008-07-28, 12:08 AM
Is there a way to use autolisp to extract just the image name of a selected image? The below code generates the full path. How can I isolate only the image name? Thanks.

(defun Get_Image_Name ()
(setq EN (car (entsel "\n Select an Object :")))
(setq ENLIST (entget EN))
(setq EN2 (cdr (assoc 340 (entget EN))))
(setq SUBEN (entget EN2))
(setq IMAGEPATH (cdr (assoc 1 SUBEN)))
(print IMAGEPATH)
(princ)
)

Moderator Note:
Please use [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code)

rkmcswain
2008-07-28, 04:31 AM
You mean the image file name, not the name of the image as far as AutoCAD is concerned, right? If so, this should work...


(defun Get_Image_Name (/ EN EN2 ENLIST FN IMAGEPATH SUBEN)
(setq EN (car (entsel "\n Select an Object :")))
(setq ENLIST (entget EN))
(setq EN2 (cdr (assoc 340 (entget EN))))
(setq SUBEN (entget EN2))
(setq IMAGEPATH (cdr (assoc 1 SUBEN)))
(setq fn (strcat
(vl-filename-base IMAGEPATH)
(vl-filename-extension IMAGEPATH)
)
)
(print fn)
(princ)
)

Rnykster
2008-07-28, 05:11 AM
You mean the image file name, not the name of the image as far as AutoCAD is concerned, right? If so, this should work...


(defun Get_Image_Name (/ EN EN2 ENLIST FN IMAGEPATH SUBEN)
(setq EN (car (entsel "\n Select an Object :")))
(setq ENLIST (entget EN))
(setq EN2 (cdr (assoc 340 (entget EN))))
(setq SUBEN (entget EN2))
(setq IMAGEPATH (cdr (assoc 1 SUBEN)))
(setq fn (strcat
(vl-filename-base IMAGEPATH)
(vl-filename-extension IMAGEPATH)
)
)
(print fn)
(princ)
)



That did the trick. It looks like this VL is more powerful than regular Autolisp. Thanks R.K. McSwain!

patrick35
2008-07-28, 09:19 AM
Hi

In vlisp

(vl-load-com)
(and (ssget '((0 . "IMAGE")))
(vlax-for ent (setq sel (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
(setq nom (vla-get-imagefile ent))
(princ (strcat "\nFind image : " (vl-filename-base nom) (vl-filename-extension nom)))
)
(vla-delete sel)
)

@+

rkmcswain
2008-07-28, 02:03 PM
It looks like this VL is more powerful than regular Autolisp.

It's all the same as far as I'm concerned... ;)