Jump to content

Changing Reference Names for Images


Recommended Posts

Posted (edited)

Simplified:

 

Make any kind of autocad dwg file.

Xref an image into in (jpg)

 

The image will have some path associated with it (C:\temp\Daryl.JPG)

 

It will also have a "reference name" (myjunkyname)

 

How can I change that reference name to the name of the image, minus the .JPG

Edited by MarkytheSparky
Easier to read
Posted

Still I have no luck using Lisp or VB to identify and change an image's reference name. Please - If anyone knows, I really could use the help.

Posted

Is there anyway to modify this code such that it would look for names with wild cards?

I that three company logos loaded as images into my DWG.

 

 

there is a Prefix and a Suffix of junk characters with the company logo name in the middle

 

 

123abcTACOLOGO456def.jpg

 

 

(the highlighted red part is all I want to change the Reference Name to)

Posted

Stop asking your question on other threads.

Posted

Try the following:

(defun c:renameallimages ( / dic img itm lst )
   (if (setq lst (dictsearch (namedobjdict) "acad_image_dict")
             dic (cdr (assoc -1 lst))
       )
       (while (setq lst (member (assoc 3 lst) lst))
           (setq itm (cdr (assoc 3 lst))
                 img (vl-filename-base (cdr (assoc 1 (entget (cdr (assoc 350 lst))))))
                 lst (cdr lst)
           )
           (if (not (or (= img itm) (dictsearch dic img)))
               (dictrename dic itm img)
           )
       )
   )
   (princ)
)

You will need to 'Reload All References' after running the above command.

Posted

Lee Mac - it worked! Thank you. Now I am going to spend some time teaching myself what all the steps do (learn the vocabulary and make REM's). You just saved me years of painful carpal tunnel pain.

Posted

Good stuff Mark - feel free to ask if you have any questions about the code.

Posted

Hi Guys!

 

I made a code friday, I didn't forsee the multiple assoc possibility in the image dict right away (very clever approach on that in your code Lee btw). I just finished to come back here to see that Lee beat me to the finish line.

 

I took a slightly different approach, taking into consideration that the user might not want to systematically rename all pictures to their file name and prompt for the user to select the images that require a reference name restoration. I could have used fewer variables and code lines, but opted for a better readability.

 

usage: launch, select the image on the screen (either loaded or unloaded) and the ref name will be restored. The load/unload status of the image won't change, and no "manual" reload is required.

 

(defun c:RES ( / img_enam img_entdesc img_hardrefEname image_hardref image_path image_dict img_newiname newiname_dxf newimage_dict)
 ;Restore image reference name by the name of the source image file (found at, without path/extension)
 ;made by Jef! on 2016 March 29.
 (setvar 'errno 0)
 (while (not (and (setq img_enam (car(entsel "\nSelect the image to restore path: ")))
	   (eq "IMAGE" (cdr (assoc 0 (entget img_enam))))
             )
 )
 (cond
           (   (= 52 (getvar 'errno))
               (princ "\nYou must select an image object. Press \"ESCAPE\" to cancel")
        (setvar 'errno 0)
           )	   
           (   (null img_enam)
               (princ "\nYou missed, try again.")
           )
    (   (not (eq "IMAGE" (cdr (assoc 0 img_entdesc))))
        (princ "\nYou must select an image object.")
    )
        )
 )
 (setq img_entdesc   (entget img_enam)
img_hardrefEname (cdr (assoc 340 img_entdesc))
       image_hardref (entget img_hardrefEname)
image_path    (cdr (assoc 1 image_hardref))
image_dict    (entget (cdr (assoc 330 image_hardref)))
img_newiname  (substr image_path
		      (+ 2 (vl-string-position 92 image_path 0 t))
		      (- (vl-string-position 46 image_path 0 t)
			 (vl-string-position 92 image_path 0 t)
			 1
		      )
	      )
newiname_dxf  (cons 3 img_newiname)
newimage_dict (subst newiname_dxf (nth 1 (member (cons 350 img_hardrefEname) (reverse image_dict))) image_dict);massoc!!
 )
 (entmod newimage_dict)
 (entmod image_hardref)
 (princ)
)

  • 7 years later...
Posted

Can i hijack this thread and ask for a way to add a prefix or suffix to an image reference name?

 

start with SW_370000_8110000_1km etc. and end with SW_370000_8110000_1km_2023

Posted

Two steps, rename the file then update the image path in the dwg.

 

image.png.99fbbff18d75031ed31003a0f9a45c53.png

Posted
16 hours ago, BIGAL said:

Two steps, rename the file then update the image path in the dwg.

 

image.png.99fbbff18d75031ed31003a0f9a45c53.png

That all depends on if they want the file renamed. It seems to me they want to rename the reference which can differ from the filename.

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