Jump to content

Recommended Posts

Posted

I have the task of updating 1000+ CAD files with the wrong image name attached.
Each file has a corresponding image attached with this naming convention "A1234-X-01-1000.tif"
I have to change the attachment prefix from A1234 to A5678 but keep the rest of the image name.
               Old attachment name:  A1234-X-01-1000.tif -> New attachment name: A5678-X-01-1000.tif
The new images and drawings are saved in the same folder, and the path type is set to none in all CAD files.

 

I think Lee’s code below does a big part of what I need, but I know renaming the reference is not the same as renaming the attachment.
Does this work, or do I have to copy the image settings and reinsert the new image with the old settings?

I am just learning on how to reference and use the main dictionary.

Thank you for any of your recommendations,

 

(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)
)

 

cadtutor.net - Changing Reference Names for Images - Lee Code

ExampleFile.dwg

Posted (edited)

Is there only one image with the same name for all the files ?

 

@densan

Try this mod of Lee's code ... test it!

(defun c:renameallimages (/ a b dic ext i img itm lst new)
  (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 (setq b (cdr (assoc 1 (setq a (entget (cdr (assoc 350 lst))))))))
	    ext	(vl-filename-extension b)
	    lst	(cdr lst)
      )
      ;; Only add new prefix if a dash is in the name
      (if (setq i (vl-string-search "-" img))
	(progn (setq new (strcat "A5678" (substr img (1+ i))))
	       (if (not (or (= new itm) (dictsearch dic new)))
		 (dictrename dic itm new)
	       )
	       (entmod (append a (list (cons 1 (strcat new ext)))))
	)
      )
    )
  )
  (princ)
)

 

Edited by ronjonp
Posted

Thank you for the reply ronjonp; the code is perfect.
And to answer your question, each file has one image with a different name, but all follow the same naming convention.

    Filename01 has image A1234-X-01-1000.tif

    Filename02 has image A1234-X-01-1001.tif

    Filename03 has image A1234-X-01-1002.tif

Again thank you very much for the help. I will be studying the code to get better at this coding thing. Thank you,

Posted
30 minutes ago, densan said:

Thank you for the reply ronjonp; the code is perfect.
And to answer your question, each file has one image with a different name, but all follow the same naming convention.

    Filename01 has image A1234-X-01-1000.tif

    Filename02 has image A1234-X-01-1001.tif

    Filename03 has image A1234-X-01-1002.tif

Again thank you very much for the help. I will be studying the code to get better at this coding thing. Thank you,

Glad to help out. 🍻

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