MarkytheSparky Posted March 22, 2016 Posted March 22, 2016 (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 March 24, 2016 by MarkytheSparky Easier to read Quote
MarkytheSparky Posted March 28, 2016 Author Posted March 28, 2016 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. Quote
MarkytheSparky Posted March 28, 2016 Author Posted March 28, 2016 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) Quote
Lee Mac Posted March 28, 2016 Posted March 28, 2016 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. Quote
MarkytheSparky Posted March 29, 2016 Author Posted March 29, 2016 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. Quote
Lee Mac Posted March 29, 2016 Posted March 29, 2016 Good stuff Mark - feel free to ask if you have any questions about the code. Quote
Jef! Posted March 29, 2016 Posted March 29, 2016 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) ) Quote
JDB Posted October 24, 2023 Posted October 24, 2023 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 Quote
BIGAL Posted October 24, 2023 Posted October 24, 2023 Two steps, rename the file then update the image path in the dwg. Quote
ronjonp Posted October 25, 2023 Posted October 25, 2023 16 hours ago, BIGAL said: Two steps, rename the file then update the image path in the dwg. 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. Quote
Recommended Posts
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.