Lisp routine that updates the saved path of an attached tiff image to the same saved path of the associated dwg file

Lisp routine that updates the saved path of an attached tiff image to the same saved path of the associated dwg file

gv6823otG42ZL
Enthusiast Enthusiast
1,199 Views
12 Replies
Message 1 of 13

Lisp routine that updates the saved path of an attached tiff image to the same saved path of the associated dwg file

gv6823otG42ZL
Enthusiast
Enthusiast

Hello community.

I wanted to see if there has been any LISP routines created or can be created that takes the saved path of a tiff image that is associated with a drawing, and automatically updates the saved path to the saved path of the associated DWG file that the tiff image is associated with. I have recently found another LISP routine for a different situation and it works perfectly but when the saved path of the tiff image is different then the saved path of the dwg file, the LISP doesn't seem to work because its looking in the old saved file path. I will attach the LISP routine that I am mentioning if it helps as well as a screen shot of the "Saved path" i am referring to. Any help would be great.

 

gv6823otG42ZL_0-1718023782980.png

 

(defun C:check ()
(setq images nil)
(setq images (ssget "X" (list (cons 0 "IMAGE"))))
(if images
(progn
(setq C 0)
(repeat (sslength images)
(setq img (entget (ssname images C)))
(setq img_ent (entget (cdr (assoc 340 img))))
(setq loaded (cdr (assoc 280 img_ent)))
(setq nam (cdr (assoc 1 img_ent)))
(if (findfile nam)
(setq FileFlag 1)
(setq FileFlag 0)
); if
(if (and (= FileFlag 1)(= loaded 1))
(prompt (strcat "\nIMAGE: " nam " IS Loaded and Image File FOUND."))
); if
(if (and (= FileFlag 1)(= loaded 0))
(prompt (strcat "\nIMAGE: " nam " IS NOT Loaded and Image File FOUND."))
); if
(if (and (= FileFlag 0)(= loaded 1))
(prompt (strcat "\nIMAGE: " nam " IS Loaded and Image File NOT FOUND."))
); if
(if (and (= FileFlag 0)(= loaded 0))
(prompt (strcat "\nIMAGE: " nam " IS NOT Loaded and Image File NOT FOUND."))
); if
(setq C (+ C 1))
); repeat
); progn
(prompt "\nNo Images Found!")
); if
(princ)
); function

0 Likes
Accepted solutions (1)
1,200 Views
12 Replies
Replies (12)
Message 2 of 13

paullimapa
Mentor
Mentor

I’m a little confused as to what you want to do. The only way to successfully change the path of the image to a different location is that you’ll need to make sure there’s a copy of the image in that new path location which in your case is the path of the dwg

So is this what you want?  I assume you don’t want to move the image to that location in case that image is attached into other dwgs correct?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 13

gv6823otG42ZL
Enthusiast
Enthusiast

Yes. I don't want to move the physical file to a different location. Whenever i sign out a dwg file, i also sign out the associated tiff image with it, so wherever the dwg's saved path is should be the same saved path as the associated tiff image, but sometimes when i view the saved path of the tiff image, the location is somewhere in no mans land, so i just need the path to be updated to the same path as the dwg file.

0 Likes
Message 4 of 13

paullimapa
Mentor
Mentor

So if not already there, you want a copy of the image to be made to the location where the dwg is saved?  What do you mean by sign out the drawing file?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 13

gv6823otG42ZL
Enthusiast
Enthusiast

So we have a drawing database called adept. It serves as a "Library" that we can go in and search for drawings to "check out" to our personal folders to work on (See snip below). When ever we have a tiff image associated with the drawing, we also have to sign out that tiff image, to the same exact file location that the dwg is being checked out to. The issue is, when the drawing & tiff are signed out and I open the drawing in AutoCAD and do an external references on the drawing, the saved path for the tiff image doesn't always update to the new saved path that I checked it out to. The dwg files saved path always updates to the new saved path I checked the drawing to. Therefore, If there is a LISP that does an external references and copies the saved path of the dwg file and pastes it into the saved path of the tiff image, and saves it, that would be perfect. Does it make it a little clearer?

0 Likes
Message 6 of 13

paullimapa
Mentor
Mentor

Sounds like your adept check out system is problematic. I don’t think you should change your image storage location structure to fit your adept check out program. Otherwise you could end up with the same image copied onto multiple folder locations. Then whenever you make a change to the image you would have to find all instances of the same image file to replace them all which introduces a different problem. Your OP shows screenshot of the image with a relative path pointing to the current folder location which should match the same location as the dwg path. Have you tried changing the relative path of the image to full path so that it matches with the dwg path location?   Does the adept checkout program then work with that minor change?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 13

gv6823otG42ZL
Enthusiast
Enthusiast

Alright, i had to do some research into absolute VS relative path. I think the original lisp routine fails because some of the tiffs are actually set to absolute path instead of relative path. My first question is what's the benefit of each and if i should have it set to one or the other. My second question would be if i set everything to the relative path, would this mess up the drawing structure?

 

0 Likes
Message 8 of 13

paullimapa
Mentor
Mentor

As per your OP screenshot the tif image path shows as: .\S001-03A-11.tif

The period (“.”) that precedes the “\” shows “relative” path is being used. The period tells AutoCAD to look in the current folder for the tif file. “Absolute” path would show the entire folder path where the tif file is stored. There are advantages and disadvantages to both methods. With Relative path you can then move the entire project path from one location to another. Since the entire path is not designed with relative path, AutoCAD can still locate the tif image. But in the case where you’re currently using a 3rd party app to checkout the dwg file which copies the dwg from the project folder to your local drive then it can not locate the tif image. But if absolute path was used then regardless of where the dwg file is located since the entire path is included in the image reference AutoCAD will be able to locate your tif image file. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 13

gv6823otG42ZL
Enthusiast
Enthusiast
Okay. So with that being said are there lisps to change the path of these tiff images to relative path if they are set on absolute paths ?
0 Likes
Message 10 of 13

paullimapa
Mentor
Mentor

Instead of looking for lisp routines first do a test to see if what I stated actually solves your problem. You can easily manually change a tif reference from relative to absolute or vice a versa within the Reference Manager. So open the dwg file normally with AutoCAD without using your 3rd party checkout app. Make the path change, save and close the file. Now use your dwg checkout method and see if your reference tif can be located when AutoCAD opens the dwg from your local drive


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 11 of 13

gv6823otG42ZL
Enthusiast
Enthusiast
I think we are deviating from the main goal I’m looking for. My main lisp routine works for when the path is set to relative but fails for when the path is set to absolute. I want to run this as a script and trust it will run successfully. To do this, I need to change the path type of these drawings from absolute to relative and then run the main lisp. The goal is to run this on 100’s of drawings and have the confidence you don’t have to go and open each individual one up to check and see if it ran successfully. What your stating, requires me to open drawings up manually before I even run the main lisp and potentially change the path. Changing the path doesn’t do anything with how the drawings are checked out or managed from what I have gathered from working with this company. They still get checked out to wherever we check them out to and get checked back in perfectly fine.
0 Likes
Message 12 of 13

pendean
Community Legend
Community Legend

@gv6823otG42ZL wrote:
...What your stating, requires me to open drawings up manually...

Not quite, @paullimapa is referring to this external app that does not require AutoCAD/Files to open, it installs with AutoCAD for all of us unless you opted out of it or your IT/CAD Manager blocked it from your use

 

pendean_0-1718034245974.png

 

pendean_1-1718034318823.png

 

0 Likes
Message 13 of 13

paullimapa
Mentor
Mentor
Accepted solution

doing a search online yields excellent results like this one which I just slightly modified to set the relative image path to the current dwg folder which again is what your OP screenshot already shows so I’m not sure why you would still need this lisp to make that change. This again only works if your tif image is actually located in the current folder location as I’ve thoroughly described in my previous responses 

(defun repath_images (/ ss i img iname)
(setq ss (ssget "X" '((0 . "IMAGE"))))
(setq i -1)
(while (< (setq i (1+ i)) (sslength ss))
(setq img (vlax-ename->vla-object (ssname ss i))
Iname (vla-get-imagefile img))
(while (vl-string-search "\\" Iname)
(setq Iname (substr Iname 2))
)
; (vla-put-imagefile img Iname)
; include current folder prefix here
(vla-put-imagefile img (strcat ".\\" Iname))
)
)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes