Author Topic: List & repath Images with ObjectDBX  (Read 4719 times)

0 Members and 1 Guest are viewing this topic.

EddieFromDc

  • Newt
  • Posts: 34
List & repath Images with ObjectDBX
« on: September 24, 2008, 11:15:05 AM »
Hello,

With examples from this website I am able to repath xrefs in a drawing without
opening them. I also use Doslib's "dos_xreflist" to get a list of xreference
drawings, then I run my program. (See code below).

Now for archiving purposes I need something similar to work with
images...(and if possible with ole/excel entities too).

Could somebody please show me how to:
1. Get a list of images from drawings with ObjectDBX.
2. Repath images in drawings with ObjectDBX.

Any help with be greatly appreciated.

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun XrefRepathEx ( File Newpath / odbxSaveFlag file  odbx index oldFileName yetRedefine newFileName saveError objBlock)

; main
  (progn
      (if (< (atoi (substr (getvar "ACADVER") 1 2)) 17)
        (setq odbx (vlax-get-or-create-object "ObjectDBX.AxDbDocument"))
        (setq odbx (vlax-get-or-create-object (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2))))
     )

      ; main loop
;      (acet-ui-status (strcat "File : " (itoa (setq index (1+ index))) " on " (itoa (length files)) " files \n" file) "BATodbxXrefsRename is working...")
       (if (vl-catch-all-error-p (vl-Catch-All-Apply '(lambda () (vla-open odbx (strcat file)))))
          (alert (strcat "Sorry..This drawing is open :\n" file))
          (progn
          (setq odbxSaveFlag nil)
          (vlax-for objBlock (vla-get-blocks odbx)
               (if (= (vlax-get objBlock 'IsXRef) -1)(progn
                                                     (setq oldFileName (vl-filename-base (vla-get-path objBlock)))
                                                     (progn
                                                     (setq $NewPath (strcat NewPath "\\" oldfilename ))
                                                     (vla-put-path objBlock $NewPath)
                                                     (setq odbxSaveFlag T)
                                                     (setq xrefsListGlobal (cons (list oldFileName newFileName) xrefsListGlobal))
                                                     );progn
                                                     );progn
              );if
         );;;vlax-for

         (if odbxSaveFlag (vla-saveas odbx (strcat file)))
         );progn
      );if vl-catch
      (acet-ui-status)
      (vlax-release-object odbx)
   );progn
   (princ)
)


; variables set
 (setq
    saveError *error*
    *error* errorFunction
    index 0
 )

; error function
(defun errorFunction ()
  (setq *error* saveError)
  (acet-ui-status)
  (if (and objBlock (not (vlax-object-released-p objBlock))) (vlax-release-object objBlock))
  (if (and odbx (not (vlax-object-released-p odbx))) (vlax-release-object odbx))
  (foreach x '( odbxSaveFlag file $NewPath odbx index oldFileName yetRedefine newFileName xrefsListGlobal saveError objBlock) 
    (set x nil)
  )
  (gc)
  (princ)
)
(princ)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Usage
;(XrefRepath_Ex File Newpath)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

<edit: code tags added>
« Last Edit: September 24, 2008, 12:06:00 PM by CAB »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: List & repath Images with ObjectDBX
« Reply #1 on: September 24, 2008, 11:24:59 AM »
From some code that I did a while ago, it looks like you step through all objects in the drawing.  When you come across one that is of type 'AcDbRasterImage'; it has a property 'ImageFile'.  That is the property you would change.  Here is something I posted here to tell you if an xref and image will load correctly when the drawing is open.  I don't use this one anymore, as I have since written one in C#.
[ http://www.theswamp.org/index.php?topic=12505.0 ]

Welcome to theSwamp Eddie.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

EddieFromDc

  • Newt
  • Posts: 34
Re: List & repath Images with ObjectDBX
« Reply #2 on: September 24, 2008, 11:51:56 AM »
Hi Tim,

Thank you for welcoming me.....The code you wrote I think is a little bit
beyond me. But I think if I understand the code right, I may be able to get
a list of the images. How about repathing it?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: List & repath Images with ObjectDBX
« Reply #3 on: September 24, 2008, 11:54:53 AM »
To repath them, just change the 'ImageFile' property of the 'AcDbRasterImage' object.  How are you trying to repath them?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

EddieFromDc

  • Newt
  • Posts: 34
Re: List & repath Images with ObjectDBX
« Reply #4 on: September 24, 2008, 12:06:10 PM »

Okay. I'm going to try that.
>How are you trying to repath them?
If I understand your question, I might repath them to a specific location or "..\Xref".

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: List & repath Images with ObjectDBX
« Reply #5 on: September 24, 2008, 12:06:45 PM »
Welcome aboard Eddie. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: List & repath Images with ObjectDBX
« Reply #6 on: September 24, 2008, 12:17:18 PM »
Here is a quick sample.

Code: [Select]
(defun c:Test (/ ImFile DwgFile dbxApp oVer *error*)
   
    (defun *error* (msg)
       
        (vlax-release-object dbxApp)
        (setq dbxApp nil)
        (if msg
            (progn
                (prompt (strcat "\n Error-> " msg))
                (vl-bt)
            )
        )
    )
    ;----------------------------------------------------------
    (if
        (and
            (setq ImFile (getfiled "Select New image file." "" "jpg" 4))
            (setq DwgFile (getfiled "Select drawing to repath image files." "" "dwg" 4))
            (setq dbxApp
                (if (< (atoi (setq oVer (substr (getvar "acadver") 1 2))) 16)
                    (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")
                    (vla-GetInterfaceObject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." oVer))
                )
            )
            (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-Open (list dbxApp DwgFile))))
        )
        (progn
            (vlax-for lo (vla-get-Layouts dbxApp)
                (vlax-for i (vla-get-Block lo)
                    (if (= (vla-get-ObjectName i) "AcDbRasterImage")
                        (vla-put-ImageFile i ImFile)
                    )
                )
            )
            (vla-SaveAs dbxApp DwgFile)
        )
    )
    (*error* nil)
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

EddieFromDc

  • Newt
  • Posts: 34
Re: List & repath Images with ObjectDBX
« Reply #7 on: September 24, 2008, 12:32:10 PM »
Tim,

This is an awesome example! Thank you!...Can this also be done with
excel/Ole files? Please say yes.

Eddie

T.Willey

  • Needs a day job
  • Posts: 5251
Re: List & repath Images with ObjectDBX
« Reply #8 on: September 24, 2008, 12:41:35 PM »
Tim,

This is an awesome example! Thank you!...Can this also be done with
excel/Ole files? Please say yes.

Eddie
Eddie,

I have never dealt with them, so I couldn't tell you.  If you posted a sample drawing I could test, then I might be able to give you an answer.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

EddieFromDc

  • Newt
  • Posts: 34
Re: List & repath Images with ObjectDBX
« Reply #9 on: September 24, 2008, 01:26:57 PM »
Tim,

Here is an example of a drawing with excel links. But for archiving purposes
I dont think I need a list or to repath the excel link. Which brings me to another
entirely new programming project....Can you "break" the excel link with ObjectDBX?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: List & repath Images with ObjectDBX
« Reply #10 on: September 24, 2008, 03:17:47 PM »
I do not see a way through code to do what I think you want.  I see they are linked, but I wasn't able to change them to embedded, or change the name of the application to nothing, so I will have to say I don't know, or I couldn't do it.  Maybe someone will chime in and say where to check, or how to do it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

EddieFromDc

  • Newt
  • Posts: 34
Re: List & repath Images with ObjectDBX
« Reply #11 on: September 24, 2008, 03:40:52 PM »
Tim,

Thank you for looking into it...Sorry, One last favor when you get the chance. I've been
studying your "WillXrefLoad2.lsp" and I am having a difficult time trying to extract the
code I need. Could you please write a simple lisp code to get or return a list of images
in a drawing using ObjectDBX...Thanks.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: List & repath Images with ObjectDBX
« Reply #12 on: September 24, 2008, 05:08:13 PM »
Eddie,

  Here are two ways.

Code: [Select]
(defun GetImageList1 (Doc / ImList)
   
    (vlax-for lo (vla-get-Layouts Doc)
        (vlax-for i (vla-get-Block lo)
            (if (= (vla-get-ObjectName i) "AcDbRasterImage")
                (setq ImList (cons (vla-get-Name i) ImList))
            )
        )
    )
    ImList
)
Code: [Select]
(defun GetImageList2 (Doc / Dict ImDict ImList)
   
    (setq Dict (vla-get-Dictionaries Doc))
    (if (not (vl-catch-all-error-p (setq ImDict (vl-catch-all-apply 'vla-Item (list Dict "ACAD_IMAGE_DICT")))))
        (foreach pair (entget (vlax-vla-object->ename ImDict))
            (if (equal (car pair) 3)
                (setq ImList (cons (cdr pair) ImList))
            )
        )
    )
    ImList
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

EddieFromDc

  • Newt
  • Posts: 34
Re: List & repath Images with ObjectDBX
« Reply #13 on: September 24, 2008, 05:22:13 PM »
Tim,

Thank you! I really appreciate your help.

Eddie

T.Willey

  • Needs a day job
  • Posts: 5251
Re: List & repath Images with ObjectDBX
« Reply #14 on: September 24, 2008, 05:26:06 PM »
Tim,

Thank you! I really appreciate your help.

Eddie
You're welcome Eddie.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.