Author Topic: Edit path type for images via lisp  (Read 139 times)

0 Members and 1 Guest are viewing this topic.

densan

  • Mosquito
  • Posts: 5
Edit path type for images via lisp
« on: June 11, 2019, 08:32:22 PM »
Hello everyone,
I am trying to find a function to set the path of attached images to NONE. I am familiar with the reference manager tool but I am looking for automation via lisp, as it will be part of a major cleanup process in 1000's of drawings.

Found the following code but it's only removing the path for one image even though the drawing contains multiple images.
I only know basic lisp concepts but I don't understand why the code it's not looping.
Thank you for any help you can offer,

Code - Auto/Visual Lisp: [Select]
  1. ;;;Jeff Mishler, Dec 2, 2004
  2. ;;;Removes path from images
  3. (defun repath_images (/ ss i img iname)
  4.  (setq ss (ssget "X" '((0 . "IMAGE"))))
  5.  (setq i -1)
  6.  (while (< (setq i (1+ i)) (sslength ss))
  7.    (setq img (vlax-ename->vla-object (ssname ss i))
  8.  Iname (vla-get-imagefile img)
  9.    )
  10.    (while (vl-string-search "\\" Iname)
  11.      (setq Iname (substr Iname 2))
  12.    )
  13.    (vla-put-imagefile img Iname)
  14.  )
  15. )
  16.  

kdub

  • Mesozoic relic
  • SuperMod
  • Swamp Rat
  • Posts: 1290
  • class keyThumper<T>:ILazy<T>
Re: Edit path type for images via lisp
« Reply #1 on: June 11, 2019, 09:55:19 PM »
Welcome to the swamp.

Jeff's routine works for me.
This is from BricsCAD V19

I can't see anything in the code that would fail and cause your issue in AutoCAD.

called Kerry in my other life

Sometimes the question is more important than the answer.

densan

  • Mosquito
  • Posts: 5
Re: Edit path type for images via lisp
« Reply #2 on: June 12, 2019, 11:11:09 AM »
Thank you Kdub, I moved the lisp to a trusted location folder and the weird behavior disappeared.
May I ask, what would be the correct way to add an IF statement (line 5 in revised code) or a way to process the function if images exist in the drawing.

Code - Auto/Visual Lisp: [Select]
  1. ;;;Jeff Mishler, Dec 2, 2004
  2. ;;;Removes path from images
  3. (defun c:repath_images (/ ss i img iname)
  4.  (setq ss (ssget "X" '((0 . "IMAGE"))))
  5. ;; (if (/= ss nil) then? <- where to start the IF
  6.  (setq i -1)
  7.  (while (< (setq i (1+ i)) (sslength ss))
  8.    (setq img (vlax-ename->vla-object (ssname ss i))
  9.  Iname (vla-get-imagefile img)
  10.    )
  11.    (while (vl-string-search "\\" Iname)
  12.      (setq Iname (substr Iname 2))
  13.    )
  14.    (vla-put-imagefile img Iname)
  15.  )
  16. )

ribarm

  • Water Moccasin
  • Posts: 2080
  • Marko Ribar, architect
Re: Edit path type for images via lisp
« Reply #3 on: June 12, 2019, 11:27:51 AM »
Code - Auto/Visual Lisp: [Select]
  1. ...
  2. (if (setq ss (ssget "X" '((0 . "IMAGE"))))
  3.  (progn
  4.  ...
  5.  )
  6. )
  7. ...
  8.  

Just edit line 4 and 5 and add closing ) at the end of (progn ...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12214
  • London, England
Re: Edit path type for images via lisp
« Reply #4 on: June 12, 2019, 01:02:08 PM »
Here's an alternative that will also target unreferenced image xrefs -
Code - Auto/Visual Lisp: [Select]
  1. (defun c:repath_images ( / d i x )
  2.    (if (setq d (cdr (assoc -1 (dictsearch (namedobjdict) "acad_image_dict"))))
  3.        (while (setq i (dictnext d (not i)))
  4.            (if (wcmatch (cdr (setq x (assoc 1 i))) "*\\*")
  5.                (entmod (subst (cons 1 (apply 'strcat (cdr (fnsplitl (cdr x))))) x i))
  6.            )
  7.        )
  8.    )
  9.    (princ)
  10. )

densan

  • Mosquito
  • Posts: 5
Re: Edit path type for images via lisp
« Reply #5 on: June 12, 2019, 03:53:06 PM »
I want to say thank very much to everyone in this post, I appreciate the help and I look forward to continue learning from this great forum.  :-)