re-path an image .. (or multiple images)

Discussion in 'AutoCAD' started by C Witt, Dec 2, 2004.

  1. C Witt

    C Witt Guest

    ok.. the problem..

    we have the occasional drawing that requires the use of a tif file (or
    jpeg..bmp.. etc.) and all works great for in house use. this get bad
    when we have to send the cad files to someone else (along with the
    image(s)).. but the image won't appear (because the drawing is still
    looking for it based on the original "path").

    I need a way of scanning a drawing for "referenced" images and changing
    the path type for each one, from "full path" to "relative path" (hard
    part of this is it can't be done after the fact.. so this "lisp" will
    need to acquire the image name, insertion point.. scale.. etc. ..
    remove the original.. and insert a new "version" (i.e. the same image,
    but now a relative path).

    Can anyone help me out??..

    I'm attaching a lisp I was given for scanning my drawings and removing
    unattached images from my files.. (perhaps someone could mod it to also
    do what i described above).

    Thanks..
     
    C Witt, Dec 2, 2004
    #1
  2. C Witt

    C Witt Guest

    oops.. forgot that lisp.. lol

    ;| c:RUI by Jeff Mishler 4/23/03 - Routine
    deletes images not found in support paths or
    no longer exist at location inserted from, then
    removes reference to unreferenced images
    Modified 6/19/03 to handle drawings where the image
    had been deleted but was still referenced in the
    image dictionary.|;


    (defun rem-undef-image (/ ssimage
    ;; selection set
    ctr
    ;; counter
    id
    ;; image dictionary
    symlst
    ;; symbol list in id
    enamelst
    ;; enames associated with symbols
    delent
    ;; entity to be checked for validity
    vl_delent
    ;; vl-object
    ipath
    ;; image insertion path
    index
    ;; counter
    itest
    ;; in final form, filename
    len
    ;; total # images found
    tmp
    ;;
    )
    (vl-load-com)
    (setq ssimage (ssget "x" '((0 . "IMAGE")))
    ctr 0
    )
    (setq len 0)
    (setq id (dictsearch (namedobjdict) "acad_image_dict"))
    (setq symlst (massoc 3 id))
    (setq enamelst (massoc 350 id))
    (if ssimage
    (progn
    (setq len (sslength ssimage))
    (while (< ctr (sslength ssimage))
    (setq delent (ssname ssimage ctr))
    (setq vl_delent (vlax-ename->vla-object delent))
    (setq ipath (vla-get-ImageFile vl_delent)
    index (- (strlen ipath) 5)
    itest (substr ipath index (1+ (- (strlen ipath) index)))
    )
    (remlst)
    (while
    (and (/= T (wcmatch itest "\\*")) (not (zerop (1- index))))
    (setq iname itest)
    (setq index (1- index))
    (setq itest (substr ipath index (1+ (strlen iname))))
    ) ;while

    (if (and (not (findfile ipath))
    ;;searches for image at path inserted
    ;;from
    (not (findfile iname))
    ;;searches for image in support path
    )
    (progn
    (dictremove (cdr (car id)) (car tmp))
    (append tmp symlst)
    (ssdel delent ssimage)
    (entdel delent)
    ) ;progn
    (progn
    (setq ctr (1+ ctr))
    ;;nothing deleted, increment index
    )
    ) ;if
    ) ;while
    (setq tmp (length symlst))
    (while symlst
    (dictremove (cdr (car id)) (car symlst))
    (setq symlst (cdr symlst))
    )
    ) ;progn
    (progn
    (setq tmp (length symlst))
    (while symlst
    (dictremove (cdr (car id)) (car symlst))
    (setq symlst (cdr symlst))
    )
    )
    )
    (prompt (strcat "\n" (itoa len) " images found...removed " (itoa tmp) " unreferenced images."))

    ) ;defun
    (defun c:ruimage ()
    (rem-undef-image)
    (princ)
    )


    (defun massoc (key alist / x nlist)
    (foreach x alist
    (if (eq key (car x))
    (setq nlist (cons (cdr x) nlist))
    )
    )
    (reverse nlist)
    )

    (defun remlst (/ tmp1)
    (setq tmp (length (member (cdr (assoc 340 (entget delent))) enamelst)))
    (repeat (- (length symlst) tmp)
    (setq tmp1 (cons (car symlst) tmp1))
    (setq symlst (cdr symlst))
    )
    (setq tmp (list (car symlst)))
    (setq symlst (append (reverse tmp1) (cdr symlst)))
    )
     
    C Witt, Dec 2, 2004
    #2
  3. C Witt

    Walt Engle Guest

    Will a dwf file work? Never tried it myself, so just a thought.
     
    Walt Engle, Dec 2, 2004
    #3
  4. C Witt

    Jeff Mishler Guest

    You can change the ImageFile property of the Image which allows you to
    re-path it as you want. This example removes all pathing and returns just
    the image. For instance, say the Image was originally loaded from
    C:\MyDocuments\MyPictures\Image003.jpg this will change the location to
    Image003.jpg . As long as the image location is in Acad's search path it
    will be found.


    (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)
    )
    )
     
    Jeff Mishler, Dec 2, 2004
    #4
  5. C Witt

    C Witt Guest

    as you say .."As long as the image location is in Acad's search path"..
    and the images never will be (they are each saved in their own job's
    folder (sames folder as the drawing)).
     
    C Witt, Dec 2, 2004
    #5
  6. If ther are in the same folder as the drawing that references them, AutoCad
    should find them in the support file search path as it looks there first.

    check out the REDIR command to remove paths from images / xrefs etc.

    Redir<enter>
    *<enter>
    <enter>

    For multiple drawings, perhaps a script file?


    Casey
     
    Casey Roberts, Dec 2, 2004
    #6
  7. C Witt

    C Witt Guest

    redir works great.. thank you.

     
    C Witt, Dec 2, 2004
    #7
  8. C Witt

    C Witt Guest

    gave your lisp a try (as casey said it shouldn't matter that the image
    is in the drawing folder).. it gave me an error..

    error: Automation Error. File access error

    ideas?

    thanks..
     
    C Witt, Dec 2, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.