Author Topic: Anyway to check image path and repath the image's path ?  (Read 398 times)

0 Members and 1 Guest are viewing this topic.

CatDance

  • Newt
  • Posts: 34
Anyway to check image path and repath the image's path ?
« on: September 08, 2021, 04:47:38 AM »
Example I have a folder containing a jpg file
D:\Sam\images\1.jpg.
and I have inserted this 1.jpg into Autocad "Picture.dwg"

If I give this folder PLUS the Autocad "Picture.dwg" to Ben and he will put it in his Pc under different drive and folder eg.
C:\Ben\images\1.jpg
"Picture.dwg"

when Ben opens the dwg and he will not see the image 1.jpg becos of the image path has changed.

Anyway to write a lisp to
(1). check if image's path has changed ?
(2).  If yes then repath image's path

Thanks
you can't find great actors like these anymore these days cos these are legends. Very few of them.
https://www.youtube.com/watch?v=Jd10x8LiuBc

CodeDing

  • Newt
  • Posts: 24
Re: Anyway to check image path and repath the image's path ?
« Reply #1 on: September 08, 2021, 09:49:44 AM »
CatDance,

It seems unusual to me to write a lisp for this check. We have the same ability (with very similar ease) to open our External References window, via the XREF command, and immediately see which references are pathed incorrectly and they can also be re-pathed.

Can you explain why that workflow does not work for you?

Best,
~DD

CatDance

  • Newt
  • Posts: 34
Re: Anyway to check image path and repath the image's path ?
« Reply #2 on: September 08, 2021, 11:17:30 AM »
CatDance,

It seems unusual to me to write a lisp for this check. We have the same ability (with very similar ease) to open our External References window, via the XREF command, and immediately see which references are pathed incorrectly and they can also be re-pathed.

Can you explain why that workflow does not work for you?

Best,
~DD


Reason is the folders have about 800 number of jpg images. I thought it would be easier to make it auto repath.

you can't find great actors like these anymore these days cos these are legends. Very few of them.
https://www.youtube.com/watch?v=Jd10x8LiuBc

CodeDing

  • Newt
  • Posts: 24
Re: Anyway to check image path and repath the image's path ?
« Reply #3 on: September 08, 2021, 11:46:55 AM »
I thought it would be easier to make it auto repath.

"auto repath"

Would you be able to elaborate more on how you envision this process going?
- How many users will need an "auto repath"?
- How many possible paths are there? (how will the program know which path is correct?)
- Will you have to pick the folder each time?
- If user-selection is still involved, how much time are we saving?

Please provide more detail so we can get you on the right ...path   :wink:

Best,
~DD

MatGrebe

  • Mosquito
  • Posts: 10
Re: Anyway to check image path and repath the image's path ?
« Reply #4 on: September 08, 2021, 11:58:54 AM »
Why not put images in a subfolder in the same directory as picture.dwg and use realtiv paths when inserting ?
Mathias

BIGAL

  • Swamp Rat
  • Posts: 829
  • 30 + years of using Autocad
Re: Anyway to check image path and repath the image's path ?
« Reply #5 on: September 08, 2021, 10:14:08 PM »
Agree with Matgrebe so much easier save image with dwg same directory. 8 users, 1 or more images in every project.
A man who never made a mistake never made anything

PM

  • Bull Frog
  • Posts: 274
Re: Anyway to check image path and repath the image's path ?
« Reply #6 on: September 09, 2021, 09:05:42 AM »
I have an old lisp code for this .  I found it beforo 6 years with this

Code: [Select]
"??? ?????????"
  in the texts .If any one have the original code please post it. The most of the times work perfect.

Code - Auto/Visual Lisp: [Select]
  1. ;;;CHP - change of the absolute (kept) way of rasters and XREF's
  2. (defun C:chp ( / what to pat )
  3. (defun BrowseFolder ( / ShlObj Folder FldObj OutVal)
  4. (setq ShlObj (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")
  5. Folder (vlax-invoke-method ShlObj 'BrowseForFolder 0 "Locate a folder with bitmaps and drawings" 0))
  6. (vlax-release-object ShlObj)(if Folder (progn (setq FldObj (vlax-get-property Folder 'Self)
  7. OutVal (vlax-get-property FldObj 'Path))(vlax-release-object Folder)(vlax-release-object FldObj)))
  8. OutVal)
  9. (initget "?????? Image ???????? Xref ??? All ?????? Undo _Image Image Xref Xref All All Undo Undo")
  10. (setq what (getkword (if (= (strcase (getvar "SYSCODEPAGE")) "ANSI_1251")
  11.  "\n???????? ???? [??????/????????/???/??????] <???> :"
  12. "\n&#917;&#960;&#945;&#957;&#945;&#954;&#945;&#952;&#959;&#961;&#953;&#963;&#956;&#972;&#962; &#948;&#953;&#945;&#948;&#961;&#959;&#956;&#942;&#962; &#934;&#945;&#954;&#941;&#955;&#959;&#965; [Image/Xref/All/Undo] <All> :")))
  13. (cond ((= what "Image")(setq pat 1))((= what "Xref")(setq pat 2))((= what "Undo")(setq pat nil))
  14. (t (setq pat 3)))(if (and pat (setq to (BrowseFolder)))(mip_ch_path to pat))(princ))
  15. (defun lib:massoc (key alist)
  16.   (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= key (car x)))) alist)))
  17. ;;; to - ???? ???? ( a way where)
  18. ;;;pat - ????? 1 - ?????? 2 - ?? ?????? (the sum 1 - rasters 2 - xrefs)
  19. ;;;(logand pat 1)=1 - Image
  20. ;;;(logand pat 2)=2 - Xref
  21. (defun mip_ch_path ( to pat / files sset item_list *error* ipath)
  22. (defun *error* (msg)(princ msg)(foreach item *list-layer-status*
  23.   (vla-put-lock (car item) (cdr (assoc "lock" (cdr item)))))
  24.   (setq *list-layer-status* nil)(vla-EndUndoMark *activedoc*))
  25. (vl-load-com)(or *activedoc*
  26. (setq files (z-files-in-directory to "*.*" nil))
  27. (setq to (VL-STRING-RIGHT-TRIM "\\" to))
  28.   (if *list-layer-status* (setq *list-layer-status* nil)) ;_ end of if
  29.   (vlax-for item (vla-get-layers *activedoc*)
  30.     (setq *list-layer-status* (append *list-layer-status*
  31.       (list(list item(cons "lock" (vla-get-lock item)))))) ;_ end of setq
  32.       (vla-put-lock item :vlax-false))(vla-StartUndoMark *activedoc*)  
  33. ;;(setq to (lib:BrowseFolder))    
  34.     (if (=(logand pat 1) 1);_Image
  35.  (progn (princ "\n===== Image =====")
  36.           (setq item_list(lib:massoc 350 (dictsearch (namedobjdict) "ACAD_IMAGE_DICT")))
  37.           (FOREACH IMG item_list
  38.             (SETQ IMG1 IMG)
  39.              (setq ipath (cdr(assoc 1 (entget img))))
  40.             (if ipath
  41.                         (progn
  42.    (if (member ipath files)(progn
  43.     (princ "\n?????? ")(princ (cdr(assoc 1 (entget img))))(princ "->")
  44.     (setq ipath (strcat to "\\" ipath))
  45.                                 (entmod(subst (cons 1 ipath)
  46.                                        (assoc 1 (entget img))
  47.                                        (entget img)
  48.                                        ))
  49.     (princ ipath)))
  50.                         )
  51.                         )
  52.             )
  53.           ))
  54.     (if (=(logand pat 2) 2);_XREF
  55.  (progn (princ "\n===== Xref =====")
  56.    (if (setq sset nil sset (ssget "_X" '((0 . "INSERT"))))
  57.     (setq item_list (mapcar 'vlax-ename->vla-object(vl-remove-if 'listp (mapcar 'cadr (ssnamex sset)))))
  58.     (setq item_list nil))
  59.            (setq item_list (vl-remove-if-not '(lambda(x)(vlax-property-available-p x 'Path)) item_list))
  60.     (mapcar '(lambda( xrf / ipath)
  61.                      (if (and (vlax-property-available-p xrf 'Path)(vlax-write-enabled-p xrf)
  62.                               (setq ipath (vl-catch-all-apply 'vla-get-Path (list xrf)))
  63.                               (not (VL-CATCH-ALL-ERROR-P ipath))
  64.                               )
  65.                        (progn
  66.         (setq ipath (strcase(strcat (VL-FILENAME-BASE ipath)(VL-FILENAME-EXTENSION ipath))))
  67.         (if (member ipath files)(progn
  68.                         (princ "\nChange ")(princ(vla-get-Path xrf))(princ "->")
  69.    (setq ipath (strcat to "\\" ipath))(vla-put-Path xrf ipath)
  70.                         (princ ipath)))))) item_list)
  71.           (vl-catch-all-apply '(lambda()(vl-cmdf "_.-xref" "_reload" (apply 'strcat (mapcar '(lambda(x)(strcat (vla-get-name x) ",")) item_list)))))
  72.           ))
  73. (princ " ")(foreach item *list-layer-status*
  74.     (vla-put-lock (car item) (cdr (assoc "lock" (cdr item)))))
  75. (setq *list-layer-status* nil)(vla-EndUndoMark *activedoc*)
  76. (vla-regen *activedoc* acallviewports))
  77. ;|=============================================================================
  78. *    ??????? z-files-in-directory ?????????? ?????? ?????? ??????????? ? ????????
  79. * ??????????
  80. *    ????? : ?????? ??????? (ZZZ)
  81. *  ?????????:
  82. *    directory  ???? ? ????? ???????? "D:\\??? ?????????\\ZEF\\Lisp"
  83. *    pattern    ?????? ???????? "*.lsp" ??? ?????? '("*.dwg" "*.dxf")
  84. *    nested    ?????? ? ????????? ??????: t (??) ??? nil (???)
  85. * ?????? ??????:
  86. (z-files-in-directory "D:\\??? ?????????\\ZEF\\Lisp" "*.dwg" t)
  87. (z-files-in-directory "D:\\??? ?????????\\ZEF\\Lisp" '("*.dwg" "*.dwt") t)
  88. =============================================================================|;
  89. (defun z-files-in-directory (directory pattern nested /)
  90.   (if (not (listp pattern))(setq pattern (list pattern)))
  91.   (if nested (apply 'append (append (mapcar '(lambda (_pattern)
  92.    (mapcar '(lambda (f) (strcat directory "\\" f))
  93.    (vl-directory-files directory _pattern 1))) pattern) ;_ mapcar
  94.    (mapcar '(lambda (d) (z-files-in-directory (strcat directory "\\" d)
  95.    pattern nested))
  96.   (vl-remove "." (vl-remove ".." (vl-directory-files directory nil -1))))))
  97.   (apply 'append (mapcar '(lambda (_pattern)(mapcar '(lambda (f) (strcat directory "\\" f))
  98.   (vl-directory-files directory _pattern 1))) pattern))))
  99.  
  100.  
  101.  

CatDance

  • Newt
  • Posts: 34
Re: Anyway to check image path and repath the image's path ?
« Reply #7 on: September 10, 2021, 02:34:43 AM »
I solved the problem by putting each type of images in it's own folder.

Example Club player's faces in Club Players folder etc. There are total 9 type of faces so 9 different folders. Some have more players than others. Each type have 5 expressions so do the maths and almost 900 images to repath.

The block name is the same as the image name so I read them from it's folder to get it's filename then use that to repath if other people put them it a different folder that is different from mine. 

well, it is lockdown time for us here so got plenty of time at home and trying to write a playing cards game.

you can't find great actors like these anymore these days cos these are legends. Very few of them.
https://www.youtube.com/watch?v=Jd10x8LiuBc

CatDance

  • Newt
  • Posts: 34
Re: Anyway to check image path and repath the image's path ?
« Reply #8 on: September 10, 2021, 02:36:49 AM »
I have an old lisp code for this .  I found it beforo 6 years with this

Code: [Select]
"??? ?????????"
  in the texts .If any one have the original code please post it. The most of the times work perfect.

Code - Auto/Visual Lisp: [Select]
  1. ;;;CHP - change of the absolute (kept) way of rasters and XREF's
  2. (defun C:chp ( / what to pat )
  3. (defun BrowseFolder ( / ShlObj Folder FldObj OutVal)
  4. (setq ShlObj (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")
  5. Folder (vlax-invoke-method ShlObj 'BrowseForFolder 0 "Locate a folder with bitmaps and drawings" 0))
  6. (vlax-release-object ShlObj)(if Folder (progn (setq FldObj (vlax-get-property Folder 'Self)
  7. OutVal (vlax-get-property FldObj 'Path))(vlax-release-object Folder)(vlax-release-object FldObj)))
  8. OutVal)
  9. (initget "?????? Image ???????? Xref ??? All ?????? Undo _Image Image Xref Xref All All Undo Undo")
  10. (setq what (getkword (if (= (strcase (getvar "SYSCODEPAGE")) "ANSI_1251")
  11.  "\n???????? ???? [??????/????????/???/??????] <???> :"
  12. "\n&#917;&#960;&#945;&#957;&#945;&#954;&#945;&#952;&#959;&#961;&#953;&#963;&#956;&#972;&#962; &#948;&#953;&#945;&#948;&#961;&#959;&#956;&#942;&#962; &#934;&#945;&#954;&#941;&#955;&#959;&#965; [Image/Xref/All/Undo] <All> :")))
  13. (cond ((= what "Image")(setq pat 1))((= what "Xref")(setq pat 2))((= what "Undo")(setq pat nil))
  14. (t (setq pat 3)))(if (and pat (setq to (BrowseFolder)))(mip_ch_path to pat))(princ))
  15. (defun lib:massoc (key alist)
  16.   (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (= key (car x)))) alist)))
  17. ;;; to - ???? ???? ( a way where)
  18. ;;;pat - ????? 1 - ?????? 2 - ?? ?????? (the sum 1 - rasters 2 - xrefs)
  19. ;;;(logand pat 1)=1 - Image
  20. ;;;(logand pat 2)=2 - Xref
  21. (defun mip_ch_path ( to pat / files sset item_list *error* ipath)
  22. (defun *error* (msg)(princ msg)(foreach item *list-layer-status*
  23.   (vla-put-lock (car item) (cdr (assoc "lock" (cdr item)))))
  24.   (setq *list-layer-status* nil)(vla-EndUndoMark *activedoc*))
  25. (vl-load-com)(or *activedoc*
  26. (setq files (z-files-in-directory to "*.*" nil))
  27. (setq to (VL-STRING-RIGHT-TRIM "\\" to))
  28.   (if *list-layer-status* (setq *list-layer-status* nil)) ;_ end of if
  29.   (vlax-for item (vla-get-layers *activedoc*)
  30.     (setq *list-layer-status* (append *list-layer-status*
  31.       (list(list item(cons "lock" (vla-get-lock item)))))) ;_ end of setq
  32.       (vla-put-lock item :vlax-false))(vla-StartUndoMark *activedoc*)  
  33. ;;(setq to (lib:BrowseFolder))    
  34.     (if (=(logand pat 1) 1);_Image
  35.  (progn (princ "\n===== Image =====")
  36.           (setq item_list(lib:massoc 350 (dictsearch (namedobjdict) "ACAD_IMAGE_DICT")))
  37.           (FOREACH IMG item_list
  38.             (SETQ IMG1 IMG)
  39.              (setq ipath (cdr(assoc 1 (entget img))))
  40.             (if ipath
  41.                         (progn
  42.    (if (member ipath files)(progn
  43.     (princ "\n?????? ")(princ (cdr(assoc 1 (entget img))))(princ "->")
  44.     (setq ipath (strcat to "\\" ipath))
  45.                                 (entmod(subst (cons 1 ipath)
  46.                                        (assoc 1 (entget img))
  47.                                        (entget img)
  48.                                        ))
  49.     (princ ipath)))
  50.                         )
  51.                         )
  52.             )
  53.           ))
  54.     (if (=(logand pat 2) 2);_XREF
  55.  (progn (princ "\n===== Xref =====")
  56.    (if (setq sset nil sset (ssget "_X" '((0 . "INSERT"))))
  57.     (setq item_list (mapcar 'vlax-ename->vla-object(vl-remove-if 'listp (mapcar 'cadr (ssnamex sset)))))
  58.     (setq item_list nil))
  59.            (setq item_list (vl-remove-if-not '(lambda(x)(vlax-property-available-p x 'Path)) item_list))
  60.     (mapcar '(lambda( xrf / ipath)
  61.                      (if (and (vlax-property-available-p xrf 'Path)(vlax-write-enabled-p xrf)
  62.                               (setq ipath (vl-catch-all-apply 'vla-get-Path (list xrf)))
  63.                               (not (VL-CATCH-ALL-ERROR-P ipath))
  64.                               )
  65.                        (progn
  66.         (setq ipath (strcase(strcat (VL-FILENAME-BASE ipath)(VL-FILENAME-EXTENSION ipath))))
  67.         (if (member ipath files)(progn
  68.                         (princ "\nChange ")(princ(vla-get-Path xrf))(princ "->")
  69.    (setq ipath (strcat to "\\" ipath))(vla-put-Path xrf ipath)
  70.                         (princ ipath)))))) item_list)
  71.           (vl-catch-all-apply '(lambda()(vl-cmdf "_.-xref" "_reload" (apply 'strcat (mapcar '(lambda(x)(strcat (vla-get-name x) ",")) item_list)))))
  72.           ))
  73. (princ " ")(foreach item *list-layer-status*
  74.     (vla-put-lock (car item) (cdr (assoc "lock" (cdr item)))))
  75. (setq *list-layer-status* nil)(vla-EndUndoMark *activedoc*)
  76. (vla-regen *activedoc* acallviewports))
  77. ;|=============================================================================
  78. *    ??????? z-files-in-directory ?????????? ?????? ?????? ??????????? ? ????????
  79. * ??????????
  80. *    ????? : ?????? ??????? (ZZZ)
  81. *  ?????????:
  82. *    directory  ???? ? ????? ???????? "D:\\??? ?????????\\ZEF\\Lisp"
  83. *    pattern    ?????? ???????? "*.lsp" ??? ?????? '("*.dwg" "*.dxf")
  84. *    nested    ?????? ? ????????? ??????: t (??) ??? nil (???)
  85. * ?????? ??????:
  86. (z-files-in-directory "D:\\??? ?????????\\ZEF\\Lisp" "*.dwg" t)
  87. (z-files-in-directory "D:\\??? ?????????\\ZEF\\Lisp" '("*.dwg" "*.dwt") t)
  88. =============================================================================|;
  89. (defun z-files-in-directory (directory pattern nested /)
  90.   (if (not (listp pattern))(setq pattern (list pattern)))
  91.   (if nested (apply 'append (append (mapcar '(lambda (_pattern)
  92.    (mapcar '(lambda (f) (strcat directory "\\" f))
  93.    (vl-directory-files directory _pattern 1))) pattern) ;_ mapcar
  94.    (mapcar '(lambda (d) (z-files-in-directory (strcat directory "\\" d)
  95.    pattern nested))
  96.   (vl-remove "." (vl-remove ".." (vl-directory-files directory nil -1))))))
  97.   (apply 'append (mapcar '(lambda (_pattern)(mapcar '(lambda (f) (strcat directory "\\" f))
  98.   (vl-directory-files directory _pattern 1))) pattern))))
  99.  
  100.  
  101.  

That's a long coding. I am trying to use cheap, dirty short quick way to do it. By using folder and filename to get around the problem. It should work in theory.
you can't find great actors like these anymore these days cos these are legends. Very few of them.
https://www.youtube.com/watch?v=Jd10x8LiuBc

CatDance

  • Newt
  • Posts: 34
Re: Anyway to check image path and repath the image's path ?
« Reply #9 on: September 10, 2021, 02:41:38 AM »
Why not put images in a subfolder in the same directory as picture.dwg and use realtiv paths when inserting ?
Mathias

Actually I am not very good at images xref. I used the "image" command and inside the dialog box have a lot of images path. Do I have to click all the images to change the path or any easy way that I may have overlooked ?

For example those images in the same folder, I still have to click each image to repath it ... right ?

Or am I doing the wrong way ?

you can't find great actors like these anymore these days cos these are legends. Very few of them.
https://www.youtube.com/watch?v=Jd10x8LiuBc

CatDance

  • Newt
  • Posts: 34
Re: Anyway to check image path and repath the image's path ?
« Reply #10 on: September 10, 2021, 02:44:48 AM »
Agree with Matgrebe so much easier save image with dwg same directory. 8 users, 1 or more images in every project.

supposing I have 75 images in one folder, is there any way with just I click on a repath button that it will repath all 75 images ?
Or do I have to click one by one to repath them ?

I am not good at images xref  :idiot2:
you can't find great actors like these anymore these days cos these are legends. Very few of them.
https://www.youtube.com/watch?v=Jd10x8LiuBc

CatDance

  • Newt
  • Posts: 34
Re: Anyway to check image path and repath the image's path ?
« Reply #11 on: September 11, 2021, 01:39:12 AM »
Why not put images in a subfolder in the same directory as picture.dwg and use realtiv paths when inserting ?
Mathias

This is something about autocad knowledge and not autolisp, I assumed.

Maybe I am not familiar or good at xref thing.

How to use relative (realtiv = relative ?) path when inserting ?
you can't find great actors like these anymore these days cos these are legends. Very few of them.
https://www.youtube.com/watch?v=Jd10x8LiuBc

CatDance

  • Newt
  • Posts: 34
Re: Anyway to check image path and repath the image's path ?
« Reply #12 on: September 11, 2021, 03:23:22 AM »
I have an old lisp code for this .  I found it beforo 6 years with this

THANK YOU PM.
your codes led me to the right direction.
Several days ago I surfed the net to find a way to extract the image database and I found one in Autodesk community forum which did not end fruitful.

Today I looked at your lisp and also came across the same  "ACAD_IMAGE_DICT" thingy.
But I poke around to learn more, trial and error and finally got it
(or did I ?? still not sure if this is the proper way to do it).

Below is part of your codes

Code - Auto/Visual Lisp: [Select]
  1. ;FIND the WHOLE dwg image list
  2. (setq egi (dictnext (namedobjdict) "ACAD_IMAGE_DICT")) ;go to the 1st image in dictionary
  3.  
  4. (setq WHOLE_dwg_image_list (dictnext (cdr (assoc 330 egi))))    ;what is this info ? then stepping to the
  5. (setq WHOLE_dwg_image_list (dictnext (cdr (assoc 330 egi))))    ;next dict database and got the whole image list
  6.  
  7. (setq eg_imag (entget (cdr (assoc 350 WHOLE_dwg_image_list))))  ;each image data is in assoc 350.
  8. ;(assoc 3 WHOLE_dwg_image_list)
you can't find great actors like these anymore these days cos these are legends. Very few of them.
https://www.youtube.com/watch?v=Jd10x8LiuBc

BIGAL

  • Swamp Rat
  • Posts: 829
  • 30 + years of using Autocad
Re: Anyway to check image path and repath the image's path ?
« Reply #13 on: September 11, 2021, 08:05:21 PM »
Not tested but maybe a different direction.

Code: [Select]
(setq obj (vlax-ename->vla-object (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_IMAGE_DICT")))))
(setq cnt (vla-get-count obj)) ; how many images

do a loop
(setq img (vla-item obj 0)) ' note 0 is 1st image
(setq hand (vla-get-handle img)) ; get handle (entget (handent hand)) ; this will expose the image name and path

(1 . "D:\\Screenshots\\1m.bmp")

(setq ent (entget (handent hand)))
<Entity name: 69a06440>
(entmod (subst (cons 1 "D:\\Screenshots\\5m.bmp") (assoc 1 ent) ent))
 image changed
« Last Edit: September 11, 2021, 08:11:27 PM by BIGAL »
A man who never made a mistake never made anything