TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: GDF on July 20, 2006, 03:00:27 PM

Title: Repath xrefs with new path
Post by: GDF on July 20, 2006, 03:00:27 PM
Here is the following request, if it is possible.

I would like to use objectdbx to repath xrefs, similar to AutoCAD's Reference Manager.
Select all drawings within a directory and repath the xrefs like the following example:

F:\Jobs\2005\050112\...
to
F:\Jobs\2006\060614\...
where the ... would be different folders, so would have to use a wild card to get them all.

the 2005\050112 would change to 2006\060614
F:\Jobs\ would remain the same

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 20, 2006, 03:08:44 PM
Not hard.  Do you want to code it, with some help?

Edit:  Adding code to show how you would get the xrefs.
Code: [Select]
(defun ListXref (Doc / tmpList EndList BlkCol)
;| List all xref's within a drawing (document), nested Xrefs also.
   Returns = (("Model" (#<VLA-OBJECT IAcadExternalReference 030dac54> . "Base-Plan"))
             ("Layout1" (#<VLA-OBJECT IAcadExternalReference 0305d934> . "Title-Block"))
            )
|;

(if (not Doc)
 (setq Doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
)
(setq BlkCol (vla-get-Blocks Doc))
(vlax-for Layout (vla-get-Layouts Doc)
 (setq tmpList nil)
 (vlax-for i (vla-get-Block Layout)
  (if
   (and
    (= (vla-get-ObjectName i) "AcDbBlockReference")
    (vlax-property-available-p i 'Path)
   )
   (progn
    (if (not (member (vla-get-Name i) tmpList))
     (setq tmpList (cons (vla-get-Name i) tmpList))
    )
    (setq tmpBlk (vla-Item BlkCol (vla-get-Name i)))
    (vlax-for Obj tmpBlk
     (if
      (and
       (= (vla-get-ObjectName Obj) "AcDbBlockReference")
       (vlax-property-available-p Obj 'Path)
      )
      (if (not (member (vla-get-Name Obj) tmpList))
       (setq tmpList (cons (vla-get-Name Obj) tmpList))
      )
     )
    )
   )
  )
 )
 (if tmpList
  (progn
   (setq tmpList (mapcar '(lambda (x) (cons (vla-Item BlkCol x) x)) tmpList))
   (setq EndList (cons (cons (vla-get-Name Layout) tmpList) EndList))
  )
 )
)
EndList
)
Title: Re: Repath xrefs with new path
Post by: GDF on July 20, 2006, 03:13:40 PM
Tim

Thanks, let me try first. The express tools redir.lsp does not seem to work with wildcards.
I was hoping to plug your code above into your CreateSheetIndex routine. That should work, right?

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 20, 2006, 03:24:08 PM
Tim

Thanks, let me try first. The express tools redir.lsp does not seem to work with wildcards.
I was hoping to plug your code above into your CreateSheetIndex routine. That should work, right?

Gary
I don't know.  I don't remember what that code looks like, but the code I posted will work with drawings opened with ObjectDBX which I think got used in that routine.
Title: Re: Repath xrefs with new path
Post by: GDF on July 20, 2006, 03:39:09 PM
Tim

Thanks, let me try first. The express tools redir.lsp does not seem to work with wildcards.
I was hoping to plug your code above into your CreateSheetIndex routine. That should work, right?

Gary
I don't know.  I don't remember what that code looks like, but the code I posted will work with drawings opened with ObjectDBX which I think got used in that routine.

Tim

Here is the code I am thinking of:

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MsgBox.lsp (c) 2001-2003, John F. Uhden, Cadlantic/CADvantage
;; A cute little utility to invoke a VBA message box and return a
;; value to AutoLisp.
;; Requires AutoCAD 2000 (R15) or higher.
;; The buttons are a Boolean value representing a logical sum of
;; the following values:
;;--------------------------------------------------------
;; MsgBox(prompt[, buttons][, title][, helpfile, context])
;; Buttons:
;; vbOKOnly    0 Display OK button only.
;; vbOKCancel    1 Display OK and Cancel buttons.
;; vbAbortRetryIgnore    2 Display Abort, Retry, and Ignore buttons.
;; vbYesNoCancel    3 Display Yes, No, and Cancel buttons.
;; vbYesNo    4 Display Yes and No buttons.
;; vbRetryCancel    5 Display Retry and Cancel buttons.
;; vbCritical   16 Display Critical Message icon.
;; vbQuestion   32 Display Warning Query icon.
;; vbExclamation   48 Display Warning Message icon.
;; vbInformation   64 Display Information Message icon.
;; vbDefaultButton1    0 First button is default.
;; vbDefaultButton2  256 Second button is default.
;; vbDefaultButton3  512 Third button is default.
;; vbDefaultButton4  768 Fourth button is default.
;; vbApplicationModal    0 Application modal; the user must respond to the
;; message box before continuing work in the current application.
;; vbSystemModal 4096 System modal; all applications are suspended until the
;; user responds to the message box.
;;
;; Revised (01-27-03) thanks to Ed Jobe's contribution about snagging the return value.
;;
;;(ARCH:MsgBox "Title" 64 "Message")
;;
(defun ARCH:MsgBox (Title Buttons Message / useri1 value)
  (vl-load-com)
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (setq useri1 (getvar "useri1"))
  (acad-push-dbmod)
  (vla-eval
    *acad*
    (strcat
      "ThisDrawing.SetVariable \"USERI1\","
      "MsgBox (\""
      Message
      "\","
      (itoa Buttons)
      ",\""
      Title
      "\")"
    )
  )
  (setq value (getvar "useri1"))
  (setvar "useri1" useri1)
  (acad-pop-dbmod)
  value)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;function to extract 2 attribute values from a specific block in the drawings of a specified folder
;;;by Jeff Mishler Feb. 9, 2006
;;;
;;;new functions and rewrite by Allen Butler
;;;
;;;added BrowseForFolder title and info
;;;added AutoCAD's progress bar while routine runs
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;pulled out this function from getindex below
(defun getfolder ()
  (defun BrowseForFolder (/ sh parentfolder folderobject result folder)
    ;;as posted the autodesk discussion customization group by Tony Tanzillo
    (vl-load-com)
    (setq sh
   (vla-getInterfaceObject
     (vlax-get-acad-object)
     "Shell.Application"
   )
    )
    (if (not ARCH#LOGO)(setq ARCH#LOGO " Your Logo"))
    (setq folder
   (vlax-invoke-method
     sh 'BrowseForFolder 0 (strcat ARCH#LOGO " : Select drawing location for ''Sheet Files''\n\t\t  Repath of all drawings in folder.\n\t\t  By: theswamp.org") 0)
    ) ;;added BrowseForFolder title and info
    (vlax-release-object sh)

    (if folder
      (progn
(setq parentfolder
       (vlax-get-property folder 'ParentFolder)
)
(setq FolderObject
       (vlax-invoke-method
ParentFolder
'ParseName
(vlax-get-property Folder 'Title)
       )
)
(setq result
       (vlax-get-property FolderObject 'Path)
)
(mapcar 'vlax-release-object
(list folder parentfolder folderobject)
)
result
      )
    )
  )
  (defun getdwglist (folderlist)
    (apply 'append
   (mapcar '(lambda (f)
      (mapcar '(lambda (name)
(strcat f "\\" name)
       )
      (vl-directory-files f "*.dwg" 1)
      )
    )
   folderlist
   )
    )
  )
  (browseforfolder) ; return the folder ;Allen Butler fix
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;by: Tim Willey
(defun ListXref (Doc / tmpList EndList BlkCol)
;| List all xref's within a drawing (document), nested Xrefs also.
   Returns = (("Model" (#<VLA-OBJECT IAcadExternalReference 030dac54> . "Base-Plan"))
             ("Layout1" (#<VLA-OBJECT IAcadExternalReference 0305d934> . "Title-Block"))
            )
|;

(if (not Doc)
 (setq Doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
)
(setq BlkCol (vla-get-Blocks Doc))
(vlax-for Layout (vla-get-Layouts Doc)
 (setq tmpList nil)
 (vlax-for i (vla-get-Block Layout)
  (if
   (and
    (= (vla-get-ObjectName i) "AcDbBlockReference")
    (vlax-property-available-p i 'Path)
   )
   (progn
    (if (not (member (vla-get-Name i) tmpList))
     (setq tmpList (cons (vla-get-Name i) tmpList))
    )
    (setq tmpBlk (vla-Item BlkCol (vla-get-Name i)))
    (vlax-for Obj tmpBlk
     (if
      (and
       (= (vla-get-ObjectName Obj) "AcDbBlockReference")
       (vlax-property-available-p Obj 'Path)
      )
      (if (not (member (vla-get-Name Obj) tmpList))
       (setq tmpList (cons (vla-get-Name Obj) tmpList))
      )
     )
    )
   )
  )
 )
 (if tmpList
  (progn
   (setq tmpList (mapcar '(lambda (x) (cons (vla-Item BlkCol x) x)) tmpList))
   (setq EndList (cons (cons (vla-get-Name Layout) tmpList) EndList))
  )
 )
)
EndList
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:XrefsRepath  (/) 
  (setq folder (getfolder)) ;by Allen Butler 
  (setq xreflist (getindex ListXref ? folder))

  (foreach dwg xreflist

    bla bla bla

  ) 
  (princ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(princ)
(C:XrefsRepath)

I just need to know how to use your function "ListXref"

Gary



Title: Re: Repath xrefs with new path
Post by: T.Willey on July 20, 2006, 03:48:57 PM
To use my routine, just supply it with a valid Document object.  So to run it one the current drawing, it would be

(ListXref (vla-get-ActiveDocument (vlax-get-Acad-Object)))

To run it on a drawing that is opened with ObjectDBX (looking at your code) it would be...
Wait, you don't have the ObjectDBX part in the code as is.  So you would need to get the folder, which it looks like you are doing.  Then you need to get the drawing files.  Then open it with ODBX, and pass the OBDX variable to the function (I usually call my dbxApp, so that is what I'm showing).

(ListXref dbxApp)


Does that make sense?
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 20, 2006, 03:51:38 PM
Here is one I wrote a little while ago.  It is used to rename a file, then find where that file is xref'ed into, and change the path to match the new one.  You can see how this works, and change it (steal lines from it) to match the needs for the routine you are looking to do.
Title: Re: Repath xrefs with new path
Post by: GDF on July 20, 2006, 04:04:08 PM
Tim

 -Error no function definition: DIRECTORY-DIA

I can't find my copy.

Gary
Title: Re: Repath xrefs with new path
Post by: GDF on July 20, 2006, 04:25:30 PM
Tim

 -Error no function definition: DIRECTORY-DIA

I can't find my copy.

Gary

Is this the latest one?

Code: [Select]
(defun Directory-Dia ( Message / sh folder folderobject result)
;; By Tony Tanzillo
;; Modified by Tim Willey
(vl-load-com)
(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
(setq folder
  (vlax-invoke-method sh 'BrowseForFolder (vla-get-HWND
(vlax-get-Acad-Object)) Message 0)
)
(vlax-release-object sh)
(if folder
  (progn
    (setq folderobject (vlax-get-property folder 'Self))
    (setq result (vlax-get-property FolderObject 'Path))
    (vlax-release-object folder)
    (vlax-release-object FolderObject)
      (if (/= (substr result (strlen result)) "\\")
        (setq result (strcat result "\\"))
        result
      )
  )
 )
)

Gary


Title: Re: Repath xrefs with new path
Post by: GDF on July 20, 2006, 04:40:01 PM
Here is one I wrote a little while ago.  It is used to rename a file, then find where that file is xref'ed into, and change the path to match the new one.  You can see how this works, and change it (steal lines from it) to match the needs for the routine you are looking to do.

Tim

Ok, it's working now. My next question is how do you use your routine when typing in the new path?
I would like to process the whole directory with  a wildcard change in the new path, without the prompt
for each drawing. Does this make sense?

Code: [Select]
Command: RePathOnly
 Old path equals: F:\Jobs\2006\060614\ACAD\seal.dwg
 Old file name equals: SEAL.DWG

 Enter new file name (include .dwg), [enter to always skip]:
 Old path equals: F:\Jobs\2006\060614\ACAD\2436TB.dwg
 Old file name equals: 2436TB.DWG

 Enter new file name (include .dwg), [enter to always skip]:
 Old path equals: F:\Jobs\2006\060614\ACAD\job-data\Cover.dwg
 Old file name equals: COVER.DWG

...


 Enter new file name (include .dwg), [enter to always skip]:
Here is what I want if possible:
F:\jobs\2006\060614\acad\<wildcard>.dwg


Gary
Title: Re: Repath xrefs with new path
Post by: GDF on July 20, 2006, 04:45:04 PM
Tim

Now I'm getting this error:

 No file created. Still renaming xref.
; error: no function definition: SAVEASEX

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 20, 2006, 04:54:09 PM
Tim

Now I'm getting this error:

 No file created. Still renaming xref.
; error: no function definition: SAVEASEX

Gary
That is a lisp from the help file for an arx file provided by Tont T. on the Adesk site.  Search for Thumbnailer.arx.  About changing the whole path, I would have to look at the code.  I wrote it, and only used it like once.  It was written for someone else, I just accepted the challenge.

I will let you know.
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 20, 2006, 05:08:40 PM
Here you go.  This is all you need to change the path of an xref.  If you didn't find the arx by Tony T., then comment out that one, and uncomment the other one.

Code: [Select]
(defun Testing (Doc OldPath NewPath / SaveChanges)

(vlax-for Lo (vla-get-Layouts Doc)
 (vlax-for Obj (vla-get-Block Lo)
  (if
   (and
    (= (vla-get-ObjectName Obj) "AcDbBlockReference")
    (vlax-property-available-p Obj 'Path)
    (or
     (= (strcase (vla-get-Path Obj)) (strcase OldPath))
     (= (strcase (findfile (vla-get-Path Obj))) (strcase OldPath))
    )
   )
   (progn
    (vla-put-Path Obj NewPath)
;    (vla-Reload (vla-Item (vla-get-Blocks Doc) (vla-get-Name Obj)))
    (setq SaveChanges T)
   )
  )
 )
)
(if SaveChanges
 (SaveAsEx (vla-get-FullName Doc))
; (vla-SaveAs Doc (vla-get-FullName Doc))
)
)
Title: Re: Repath xrefs with new path
Post by: GDF on July 20, 2006, 05:11:05 PM
Tim

Now I'm getting this error:

 No file created. Still renaming xref.
; error: no function definition: SAVEASEX

Gary
That is a lisp from the help file for an arx file provided by Tont T. on the Adesk site.  Search for Thumbnailer.arx.  About changing the whole path, I would have to look at the code.  I wrote it, and only used it like once.  It was written for someone else, I just accepted the challenge.

I will let you know.


Tim

Thanks. I know a lot of use could use this routine. Right now I am having to do it manually.
The express routine and Refernce Manager do not do this very good.

See image, where I paste in 2005\050717 with 2006\060614

Gary

Title: Re: Repath xrefs with new path
Post by: GDF on July 20, 2006, 05:18:24 PM
Tim

Don't have SaveAsEx function.
Thanks.

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 20, 2006, 05:31:41 PM
What it does is save the preview image for the darwing.  If you save with ObjectDBX you lose the preview.
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 20, 2006, 05:45:54 PM
Here is the link (http://discussion.autodesk.com/thread.jspa?messageID=4987978) to the thread on the Adesk Ng where Tony T. posted his arx.  Just look for his post.
Title: Re: Repath xrefs with new path
Post by: GDF on July 21, 2006, 11:04:39 AM
Tim

This is beyond my abilities, so I am willing to pay you for this routine. What i want is to select all of my sheet files
within a directory and repath all of the xrefs with a new path. The differnce for each drawing path is illustrated
by the following example in bold:

F:\Jobs\2005\050212\acad\job-data\Cover.dwg
F:\Jobs\2006\060614\acad\job-data\Cover.dwg

The routine using objectdbx would repath all of the attached xrefs with the new saved path. I don't want to
rely on using Thumbnailer16.arx <Thumbnailer17.arx ?>.

The routine would have to use wildcards <I quess> for each drawings path:
F:\Jobs\2006\060614\acad\<wildcard>.dwg

This would save me tons of time, sense we routinely copy whole projects over to a new directory when
starting a new job that is similar.

How about $200.00 for your efferts if this can be done.

Gary
Title: Re: Repath xrefs with new path
Post by: drizzt on July 21, 2006, 11:09:49 AM
Man! I really need to get a better understanding of lisp! This looks like it could be really usefull!
Title: Re: Repath xrefs with new path
Post by: MP on July 21, 2006, 11:11:30 AM
Warning: One would be well advised to check the terms of use of any third party utilities used in the execution of any commercial work.
Title: Re: Repath xrefs with new path
Post by: drizzt on July 21, 2006, 11:13:34 AM
Quote
Warning: One would be well advised to check the terms of use of any third party utilities used in the execution of any commercial work.

understood!
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 21, 2006, 11:16:34 AM
Warning: One would be well advised to check the terms of use of any third party utilities used in the execution of any commercial work.
Here is the header in his ReadMe file.  Thanks for the warning Michael.  I don't usually write code to get paid for it, it's just fun.
Quote
Thumbnailer.arx  Copyright 2005  www.caddzone.com

   Thumbnailer ActiveX Server Documentation

   Library:   Thumbnailer.arx

   Class:     Application

   ProgID:    "Thumbnailer.Application"

   Reference: "Thumbnailer 1.0 Type Library"

   Requirements:  AutoCAD 2004-2006

   Terms and conditions of use:

      This software may be used and freely distributed,
      provided this notice and the copyright notice
      displayed by the application when it loads, is not
      removed, altered, or concealed.

      This software is not warranted to be free of defects.
      Any and all use of this software is undertaken at the
      risk of the user. The author is not responsible for
      any loss resulting directly or indirectly from the
      use of this software.

      Your use of this software constitutes your acceptance
      of these terms and conditions.

Gary,

  Let me see what I can do.
Title: Re: Repath xrefs with new path
Post by: GDF on July 21, 2006, 11:25:22 AM
Warning: One would be well advised to check the terms of use of any third party utilities used in the execution of any commercial work.
Here is the header in his ReadMe file.  Thanks for the warning Michael.  I don't usually write code to get paid for it, it's just fun.
Quote
Thumbnailer.arx  Copyright 2005  www.caddzone.com

   Thumbnailer ActiveX Server Documentation

   Library:   Thumbnailer.arx

   Class:     Application

   ProgID:    "Thumbnailer.Application"

   Reference: "Thumbnailer 1.0 Type Library"

   Requirements:  AutoCAD 2004-2006

   Terms and conditions of use:

      This software may be used and freely distributed,
      provided this notice and the copyright notice
      displayed by the application when it loads, is not
      removed, altered, or concealed.

      This software is not warranted to be free of defects.
      Any and all use of this software is undertaken at the
      risk of the user. The author is not responsible for
      any loss resulting directly or indirectly from the
      use of this software.

      Your use of this software constitutes your acceptance
      of these terms and conditions.

Gary,

  Let me see what I can do.

Tim

That is why I don't want to rely on any third party programs. No Thumbnailer.arx or any other third party routines.
I am not paying for the routine, think of it as paying for your time. And yes I am serious about reimburseing you
for your efferts. You can post it to this forum for all to use. I still want to pay you anyway.

Thanks

I thought all work was commercial...

Gary
Title: Re: Repath xrefs with new path
Post by: MP on July 21, 2006, 11:29:14 AM
Thumbnailer.arx  Copyright 2005  www.caddzone.com ...

Label me surprised. While I don't use TT's stuff I recall posts of his on the ngs years ago where he included terms to the effect of "can only be used for non commercial work / in-house works"; adviseable to ensure one understands and is in compliance with any such terms.

Edit: Now just provided as a general warning to all since Gary indicated he isn't interested in employing third party utils.
Title: Re: Repath xrefs with new path
Post by: GDF on July 21, 2006, 11:32:04 AM
Tim

This is beyond my abilities, so I am willing to pay you for this routine. ...

Quick question Gary, and to be clear my inquirey has nothing to do with the coinage above, nor is it to take away potential work from Tim (who can most certainly code anything you need) but have you looked into exploiting the system variable ProjectName to repath the xrefs?

I repathed about 5000 drawings a couple years ago using said variable inside a wrapper of sorts (a lisp program).

Form the help <quote>If an xref or image is not found at the original path, the project paths associated with the project name are searched. If the xref or image is not found there, the AutoCAD search path is searched ...</quote>.

Need more info?

Michael

I am not familiar with this var or how to use it. When we start a new project that is very similar to one in the past,
we copy the whole directory over to a new one. So yes I quess the ProjectName is all that changes.

One of these days I will learn how to use AutoCAD to its full potiential. I've given up on lisping <did I say that right>.

Gary
Title: Re: Repath xrefs with new path
Post by: MP on July 21, 2006, 11:36:42 AM
Carp. I deleted that post Gary because (despite my attempts to pen to the contrary) it reads like I'm trying to take a gig from Tim.

So let me say this -- Tim knows about said variable and more, so I'm going to voluntarilly back off and let Tim have dibs at any responses; trying to do the honourable thing here.
Title: Re: Repath xrefs with new path
Post by: GDF on July 21, 2006, 11:42:40 AM
Carp. I deleted that post Gary because (despite my attempts to pen to the contrary) it reads like I'm trying to take a gig from Tim.

So let me say this -- Tim knows about said variable and more, so I'm going to voluntarilly back off and let Tim have dibs at any responses; trying to do the honourable thing here.

Michael

No problem, Tim has helped me so much in the past already, that I owe him. There comes a point in time
when you have to bring out the check book. This routine will save me tons of time. AutoCAD's
"Refernce Manager" is crap and the express tool does not do what I want. I don't care if the preview image
is not saved, that part is easily fixed.

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 21, 2006, 11:52:40 AM
Carp. I deleted that post Gary because (despite my attempts to pen to the contrary) it reads like I'm trying to take a gig from Tim.

So let me say this -- Tim knows about said variable and more, so I'm going to voluntarilly back off and let Tim have dibs at any responses; trying to do the honourable thing here.
It's all good Michael.  I wasn't going to take Gary's money, as I fill my skills are not that good yet, likes yours and many others who share their code here.  I don't use the ProjectName variable, so if you want to explain it, be my guest.  From what I understand is, it is like a relative path, and will keep the xref path until that folder.
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 21, 2006, 12:01:48 PM
Try this Gary.

Code: [Select]
(defun c:RepathXref (/ *error* OldPath NewPath DwgList dbxApp Opened)

(defun *error* (msg)

(prompt (strcat "\n  Error--> " msg))
(if Opened
 (close Opened)
)
(if dbxApp
 (progn
  (vlax-release-object dbxApp)
  (setq dbxApp nil)
 )
)
)
;-------------------------------------------------------------------------------------------
(defun Directory-Dia ( Message / sh folder folderobject result)
;; By Tony Tanzillo
;; Modified by Tim Willey

  (vl-load-com)
  (setq sh
     (vla-getInterfaceObject
        (vlax-get-acad-object)
        "Shell.Application"
     )
  )


  (setq folder
     (vlax-invoke-method
         sh
         'BrowseForFolder
         (vla-get-HWND (vlax-get-Acad-Object))
         Message
         0
      )
  )
  (vlax-release-object sh)


  (if folder
     (progn
        (setq folderobject
           (vlax-get-property folder 'Self)
        )
        (setq result
           (vlax-get-property FolderObject 'Path)
        )
        (vlax-release-object folder)
        (vlax-release-object FolderObject)
        (if (/= (substr result (strlen result)) "\\")
          (setq result (strcat result "\\"))
          result
        )
     )
  )
)
;----------------------------------------------------------------------------
(defun RePathXref (Doc OldPath NewPath / SaveChanges OldDir DwgName)

(vlax-for Lo (vla-get-Layouts Doc)
 (vlax-for Obj (vla-get-Block Lo)
  (if
   (and
    (= (vla-get-ObjectName Obj) "AcDbBlockReference")
    (vlax-property-available-p Obj 'Path)
    (setq OldDir (strcat (vl-filename-directory (vla-get-Path Obj)) "\\"))
    (setq DwgName (strcat (vl-filename-base (vla-get-Path Obj)) ".dwg"))
    (or
     (= (strcat OldDir) (strcase OldPath))
     (= (strcase OldDir) (strcase OldPath))
    )
   )
   (progn
    (vla-put-Path Obj (strcat NewPath DwgName))
    (write-line (strcat "  Xref name: " (vla-get-Name Obj)) Opened)
    (write-line (strcat "    Xref path " (vla-get-Path Obj)) Opened)
    (setq SaveChanges T)
   )
  )
 )
)
(if SaveChanges
; (SaveAsEx (vla-get-FullName Doc))
 (vla-SaveAs Doc (vla-get-FullName Doc))
)
)
;-----------------------------------------------------------------------------------

(if
 (and
  (setq OldPath (Directory-dia "Select OLD path of drawings."))
  (setq NewPath (Directory-dia "Select NEW path for drawings."))
  (setq DwgList (vl-directory-files NewPath "*.dwg" 1))
  (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))
   )
  )
  (setq Opened (open (strcat NewPath "RepathXref.txt") "a"))
 )
 (foreach Dwg DwgList
  (setq SaveChanges nil)
  (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Open (list dbxApp (strcat Newpath Dwg))))
   (write-line (strcat "\n+++ Could not open \"" NewPath Dwg "\"") Opened)
   (progn
    (write-line (strcat " - Drawing \"" NewPath Dwg "\" report") Opened)
    (RePathXref dbxApp OldPath NewPath)
   )
  )
 )
)
(if Opened
 (progn
  (close Opened)
  (initget "Yes No")
  (if (= (getkword "\n Open log file [<Y>es/No]: ") "No")
   (prompt (strcat "n Log file location: " NewPath "RepathXref.txt"))
   (startapp "notepad.exe" (strcat NewPath "RepathXref.txt"))
  )
 )
)
(if dbxApp
 (progn
  (vlax-release-object dbxApp)
  (setq dbxApp nil)
 )
)
(princ)
)
Title: Re: Repath xrefs with new path
Post by: GDF on July 21, 2006, 12:18:39 PM
Tim

Command: REPATHXREF
  Error--> ActiveX Server returned the error: unknown name: FullName
Command:

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 21, 2006, 12:52:23 PM
Tim

Command: REPATHXREF
  Error--> ActiveX Server returned the error: unknown name: FullName
Command:

Gary
Sorry about that, that part was written from memory, guess I was wrong.  Change this spot in the RePathXref sub
Code: [Select]
(if SaveChanges
; (SaveAsEx (vla-get-FullName Doc))
 (vla-SaveAs Doc (vla-get-FullName Doc))
)
to
Code: [Select]
(if SaveChanges
; (SaveAsEx (vla-get-Name Doc))
 (vla-SaveAs Doc (vla-get-Name Doc))
)
Title: Re: Repath xrefs with new path
Post by: GDF on July 21, 2006, 02:18:23 PM
Tim

Wow, works perfectly...check is being mailed.

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 21, 2006, 02:22:39 PM
Tim

Wow, works perfectly...check is being mailed.

Gary
You're welcome.  Check your pm's before you send any check.   :wink:
Title: Re: Repath xrefs with new path
Post by: GDF on July 21, 2006, 02:35:47 PM
Tim

Thanks, thanks again. This is a great time saver, well worth the cost.

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 21, 2006, 02:41:29 PM
Tim

Wow, works perfectly...check is being mailed.

Gary
What can I say, but THANKS.  :oops:
I still don't think I deserve it, but if you have made up you mind, there is nothing I can do.
Title: Re: Repath xrefs with new path
Post by: CAB on July 21, 2006, 04:08:21 PM
Tim,
Would you deny Gary the pleasure of giving?
After all that is why you give isn't it?  8-)
Title: Re: Repath xrefs with new path
Post by: MP on July 21, 2006, 04:25:56 PM
Now that it's done (good job Tim, and no surprise) let me illuminate a little on the ProjectName variable with regards to some bulk xref repathing I had to do a couple years back.

I worked on a project that had in excess of 5000 (it may have been 11000, that number seems to be familiar) production drawings that referenced some 500 or so different models (xreferences). Each xref would reside in a directory like:

    drive\project\discipline\plant\model.dwg

e.g.

    X:\999\elec\21\21-E-0001.dwg
    X:\999\elec\21\21-E-0002.dwg
    X:\999\elec\21\21-E-0003.dwg
    X:\999\elec\37\37-E-0001.dwg
    X:\999\elec\42\42-E-0001.dwg
    X:\999\elec\63\63-E-0001.dwg

    etc. for the civil, piping, inst ... disciplines


For reasons I won't detail all xrefs were copied to a different drive and folder structure for another need (read "relative xref paths" wouldn't be a quick fix).

e.g.

    z:\client\models\elec\21-E-0001.dwg
    z:\client\models\elec\21-E-0002.dwg
    z:\client\models\elec\21-E-0003.dwg
    z:\client\models\elec\37-E-0001.dwg
    z:\client\models\elec\42-E-0001.dwg
    z:\client\models\elec\63-E-0001.dwg

    etc. for the civil, piping, inst ... disciplines


So --

I wrote a routine to repath the xrefs based on the paths associated with the current ProjectName, as said variable will host multiple paths, not just one.

e.g. ProjectName "Repath999" might have had these paths --

    z:\client\models\elec
    z:\client\models\civil
    z:\client\models\piping
    z:\client\models\inst


Stored in the registry as --

    "z:\client\models\elec;z:\client\models\civil;z:\client\models\piping;z:\client\models\inst"

I could have done it differently, but it served other repathing needs that emerged about the same time that could also exploit the ProjectName variable, i.e. have the user select a ProjectName value from a list (i.e. read the resistry and display all the valid ProjectName values) and then repath all xrefs accordingly.

Anyway --

As the code was written for a client I just bashed this all out anew to demonstrate (hopefully no bugs). First the core code which knows nothing of the ProjectName variable, it just blithely repaths each xref in the supplied document (read objectDbx compatible) to the first path that resolves and repaths without error in a list of alternate paths.

Code: [Select]
(defun _RepathXrefs ( document paths / _GetXrefNames _RepathXref _Main )

    ;;  repath each xref in the document to the first path
    ;;  in the list of supplied paths that resolves and repaths
    ;;  without error

    (defun _GetXrefNames ( document / result )

        ;;  get the document's xref names

        (vlax-for block (vla-get-blocks document)
            (if (eq :vlax-true (vla-get-isxref block))
                (setq result
                    (cons (vla-get-name block)
                        result
                    )
                )
            )
            result
        )
    )

    (defun _RepathXref ( xref paths )

        ;;  attempt to repath the xref to the first path in
        ;;  the supplied alternate paths that hosts the xref's
        ;;  filename AND can be remapped to w/out error
        ;;
        ;;  note, each path in the paths argument is expected
        ;;  to be valid and clean, no terminating back or forward
        ;;  slashes

        (   (lambda ( filename )
                (vl-some
                   '(lambda ( candidatePath / tryPath result )
                        (cond
                            (   (findfile
                                    (setq tryPath
                                        (strcat
                                            candidatePath
                                            "\\"
                                            filename
                                        )
                                    )
                                )
                                (vl-catch-all-apply
                                   '(lambda ( )
                                        (vla-put-path xref tryPath)
                                        (setq result t)
                                    )
                                )
                                result
                            )
                        )
                    )
                    paths
                )
            )
            (strcat (vl-filename-base (vla-get-path xref)) ".dwg")
        )
    )

    (defun _Main ( document paths / xrefNames )

        ;;  get the document's xref names

        (setq xrefNames (_GetXrefNames document))

        ;;  iterate the xrefs in the document, trying to
        ;;  remap 'em to the first valid path found in the
        ;;  supplied paths

        (vlax-for layout (vla-get-layouts document)
            (vlax-for object (vla-get-block layout)
                (if (eq "AcDbBlockReference" (vla-get-objectname object))
                    (if (member (vla-get-name object) xrefNames)
                        (_RepathXref object paths)
                    )
                )
            )
        )
    )

    (_Main document paths)

)

Now an example program that repaths xrefs in the current document to the first valid path in the paths associated with the ProjectName's current value.

Code: [Select]
(defun c:Example ( / _GetProjectPath _SearchPathToList _Main *debug* )

    ;;  use the paths associated with the projectname
    ;;  variable as an alternate path for each xref
    ;;  in the current document

    (defun _GetProjectPath ( name )

        ;;  get the paths associate with the project
        ;;  name (note: result if non nil will be semi
        ;;  colon delimited string)

        (vl-registry-read
            (strcat "HKEY_CURRENT_USER\\"
                (vlax-product-key)
                "\\Profiles\\"
                (getvar "cprofile")
                "\\Project Settings\\"
                Name
            )
            "RefSearchPath"
        )
    )

    (defun _SearchPathToList ( searchPath / path result )

        (foreach code (reverse (vl-string->list searchPath))
            (if (eq 59 code) ;; ascii ";" = 59
                (if path
                    (setq
                        result (cons path result)
                        path   nil
                    )
                )
                (setq path (cons code path))
            )
        )

        (mapcar
           '(lambda (lst) (vl-string-right-trim "/\\" (vl-list->string lst)))
            (if path (cons path result) result)
        )

    )

    (defun _Main ( document / paths )

        ;;  if there are paths associated with
        ;;  the current projectname ...

        (cond
            (
                (setq paths
                    (_GetProjectPath
                        (vlax-invoke
                            document
                           'GetVariable
                           "projectname"
                        )
                    )
                )

                ;;  do it

                (_RepathXrefs
                    document
                    (_SearchPathToList paths)
                )

                ;;  reload all xrefs

                (vlax-for block (vla-get-blocks document)
                    (if (eq :vlax-true (vla-get-isxref block))
                        (vla-reload block)
                    )
                )

                ;;  force a regen

                (vla-regen
                    document
                    acAllViewports
                )
            )
        )

        (princ)

    )

    (_Main
        (vla-get-activedocument
            (vlax-get-acad-object)
        )
    )

)

Hope it makes sense.

:)
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 21, 2006, 05:02:04 PM
Tim,
Would you deny Gary the pleasure of giving?
After all that is why you give isn't it?  8-)
I'm modest about stuff that I'm not good at, so I don't feel the need is there, that is all I'm trying to say.  I argued with him all I could, and I gave in to what he wants.  You make a good point Alan.

Now that it's done (good job Tim, and no surprise) let me illuminate a little on the ProjectName variable with regards to some bulk xref repathing I had to do a couple years back.

<snip>

Hope it makes sense.

:)
Good explaination Michael, and good example of coding it.  Oh yea, thanks for the kudos. :wink:
Title: Re: Repath xrefs with new path
Post by: GDF on July 21, 2006, 05:04:27 PM
Anyway --

As the code was written for a client I just bashed this all out anew to demonstrate (hopefully no bugs). First the core code which knows nothing of the ProjectName variable, it just blithely repaths each xref in the supplied document (read objectDbx compatible) to the first path that resolves and repaths without error in a list of alternate paths.


Hope it makes sense.

:)

Michael

I'm lost. So how is this routine to be used?

Gary
Title: Re: Repath xrefs with new path
Post by: MP on July 21, 2006, 05:04:51 PM
One thing I should note about the ProjectName variable, and something that's annoying (which my coding addresses).

Say you have a bunch of xrefs that don't resolve because their paths have changed. You create a ProjectName c/w the new paths and make it active. Save the drawing then re-open it. Now all the xrefs resolve =BUT= AutoCAD does not update each xre's path. That is, if you check its properties it still points to the invalid path.

But back to Gary's original inquirey, using the code I previously supplied his challenge could be solved via the following pseudo code --

Code: [Select]
(defun c:PseudoCode ( / axDbDocument )
    (foreach fullpath (MyGetFilesFunction "F:\\Jobs\\2005\\050112\\*.dwg")
        (if (setq axDbDocument (MyOpenAxDbDocument fullpath))
            (progn           
                (_RepathXrefs AxDbDocument '("F:\\Jobs\\2006\\060614"))
                (MySaveAxDbDocument axDbDocument fullpath)
                (vlax-release-object axDbDocument)
            )
        )
    )
    (princ)
)

FWIW; cheers.

PS: As I was posting this Tim snuck in a post: Thanks and my pleasure Tim => you're a generous friend and resource to all swampers. So did Gary: See snip above.

:)
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 21, 2006, 05:07:48 PM
On a side note, Tony T. also provide the source code for the arx file (at least I think it is), so it can be recompiled for future releases.
Title: Re: Repath xrefs with new path
Post by: MP on July 21, 2006, 05:11:06 PM
On a side note, Tony T. also provide the source code for the arx file (at least I think it is), so it can be recompiled for future releases.

Even though I don't use it a nod of appreciation to Mr. Tanzillo.
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 21, 2006, 05:14:06 PM
On a side note, Tony T. also provide the source code for the arx file (at least I think it is), so it can be recompiled for future releases.

Even though I don't use it a nod of appreciation to Mr. Tanzillo.
I still read his post, because he knows a lot, and has helped me out a lot.  I wonder if he has calmed down since you were on the Adesk site.  I come across some post where you two would battle with ideas and opinions when searching for stuff.  I like those because I can learn a lot of different ways to skin a cat. :-D
Title: Re: Repath xrefs with new path
Post by: GDF on July 21, 2006, 05:28:17 PM
One thing I should note about the ProjectName variable, and something that's annoying (which my coding addresses).

Say you have a bunch of xrefs that don't resolve because their paths have changed. You create a ProjectName c/w the new paths and make it active. Save the drawing then re-open it. Now all the xrefs resolve =BUT= AutoCAD does not update each xre's path. That is, if you check its properties it still points to the invalid path.

But back to Gary's original inquirey, using the code I previously supplied his challenge could be solved via the following pseudo code --

Code: [Select]
(defun c:PseudoCode ( / axDbDocument )
    (foreach fullpath (MyGetFilesFunction "F:\\Jobs\\2005\\050112\\*.dwg")
        (if (setq axDbDocument (MyOpenAxDbDocument fullpath))
            (progn           
                (_RepathXrefs AxDbDocument '("F:\\Jobs\\2006\\060614"))
                (MySaveAxDbDocument axDbDocument fullpath)
                (vlax-release-object axDbDocument)
            )
        )
    )
    (princ)
)

FWIW; cheers.

PS: As I was posting this Tim snuck in a post: Thanks and my pleasure Tim => you're a generous friend and resource to all swampers. So did Gary: See snip above.

:)

Michael

MyGetFilesFunction?
MySaveAxDbDocument?
MyOpenAxDbDocument?

Gary





Title: Re: Repath xrefs with new path
Post by: Bob Wahr on July 21, 2006, 05:29:11 PM
It's not how one skins the cat but the sauce one serves it with which matters most.
I should write fortune cookies
Title: Re: Repath xrefs with new path
Post by: MP on July 21, 2006, 07:07:37 PM
Michael

MyGetFilesFunction?
MySaveAxDbDocument?
MyOpenAxDbDocument?

Gary

Hi Gary. Like I said, it is / was pseudo code (not intended to be executable as is), a framework or outline to use as a coding recipe of sorts.

MyGetFilesFunction is a user supplied function that returns a list of path qualified files that meet a spec.

e.g. given a spec of "c:\\path\\*.dwg" might return --

    (   
        "c:\\path\\drawing1.dwg"
        "c:\\path\\drawing2.dwg"
        "c:\\path\\drawing3.dwg"
    )


MyOpenAxDbDocument is a user supplied function that takes care of creating an creating an ObjectDBX instance and opening the specified document, trapping all potential errors and returning nil if errors are encountered or an AxDbDocument if the instance is successfully created and the drawing successfully opened.

MySaveAxDbDocument is a user supplied function that is responsible for saving an AxDbDocument. As documents opened via ObjectDBX do not support the Save method it means it has to perform some slight of hand to achieve this. For example it might use the SaveAs method to save the document to a temporary file, close the document, and then use vl-file-copy to copy the temp file over the desired file (qualifying / error trapped accordingly as it goes).

Hope this clarifies.
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 21, 2006, 07:30:03 PM
MySaveAxDbDocument is a user supplied function that is responsible for saving an AxDbDocument. As documents opened via ObjectDBX do not support the Save method it means it has to perform some slight of hand to achieve this. For example it might use the SaveAs method to save the document to a temporary file, close the document, and then use vl-file-copy to copy the temp file over the desired file (qualifying / error trapped accordingly as it goes).

Hope this clarifies.
FYI......
ObjectDBX doesn't have a Save method, but you can use the SaveAs method to the same file name and path as the opened file, so it works like a Save method. (which I'm sure you know Michael)
Title: Re: Repath xrefs with new path
Post by: MP on July 21, 2006, 07:43:19 PM
MySaveAxDbDocument is a user supplied function that is responsible for saving an AxDbDocument. As documents opened via ObjectDBX do not support the Save method it means it has to perform some slight of hand to achieve this. For example it might use the SaveAs method to save the document to a temporary file, close the document, and then use vl-file-copy to copy the temp file over the desired file (qualifying / error trapped accordingly as it goes).

Hope this clarifies.
FYI......
ObjectDBX doesn't have a Save method, but you can use the SaveAs method to the same file name and path as the opened file, so it works like a Save method. (which I'm sure you know Michael)

When I first started using ObjectDBX 6 years ago you couldn't use the SaveAs method to save an ObjectDBX document over itself (if memory serves me correctly), hense the slight of hand mention above, but meh, of the things I've lost I miss my mind the most (subtitle, no I didn't know that Tim). Thank you sir, noted for future use (going to have to test this in various versions of AutoCAD next week, only have 2006 here and I confirmed what you noted above).
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 21, 2006, 09:01:10 PM
MySaveAxDbDocument is a user supplied function that is responsible for saving an AxDbDocument. As documents opened via ObjectDBX do not support the Save method it means it has to perform some slight of hand to achieve this. For example it might use the SaveAs method to save the document to a temporary file, close the document, and then use vl-file-copy to copy the temp file over the desired file (qualifying / error trapped accordingly as it goes).

Hope this clarifies.
FYI......
ObjectDBX doesn't have a Save method, but you can use the SaveAs method to the same file name and path as the opened file, so it works like a Save method. (which I'm sure you know Michael)

When I first started using ObjectDBX 6 years ago you couldn't use the SaveAs method to save an ObjectDBX document over itself (if memory serves me correctly), hense the slight of hand mention above, but meh, of the things I've lost I miss my mind the most (subtitle, no I didn't know that Tim). Thank you sir, noted for future use (going to have to test this in various versions of AutoCAD next week, only have 2006 here and I confirmed what you noted above).
I have used that method on 2004 also.  Just so you know.  Glad I could help you once.  :-D
Title: Re: Repath xrefs with new path
Post by: GDF on July 24, 2006, 10:35:26 AM
Thanks

Tim and Michael

One of these days I am going to have to learn this vlisp stuff...

Code: [Select]
MyGetFilesFunction is a user supplied function that returns a list of path qualified files that meet a spec.

e.g. given a spec of "c:\\path\\*.dwg" might return --

    (   
        "c:\\path\\drawing1.dwg"
        "c:\\path\\drawing2.dwg"
        "c:\\path\\drawing3.dwg"
    )

MyOpenAxDbDocument is a user supplied function that takes care of creating an creating an ObjectDBX instance and opening the specified document, trapping all potential errors and returning nil if errors are encountered or an AxDbDocument if the instance is successfully created and the drawing successfully opened.

MySaveAxDbDocument is a user supplied function that is responsible for saving an AxDbDocument. As documents opened via ObjectDBX do not support the Save method it means it has to perform some slight of hand to achieve this. For example it might use the SaveAs method to save the document to a temporary file, close the document, and then use vl-file-copy to copy the temp file over the desired file (qualifying / error trapped accordingly as it goes).

Hope this clarifies.


Tim

Your original routine works great, but sometimes it does not pick and change the xref paths. I was wondering if
Michaels approach would work any better. Since this vl stuff is beyond me, I was hoping you could try combining
Michael's and your routine to see if this would work any better.

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 24, 2006, 11:09:10 AM
Gary,

  I would have to see some test drawings, so that I can see why it doesn't work.  It could be that the paths are not completely stored.  Can you post a small zip file with some of the drawings?
Title: Re: Repath xrefs with new path
Post by: GDF on July 24, 2006, 11:49:19 AM
Gary,

  I would have to see some test drawings, so that I can see why it doesn't work.  It could be that the paths are not completely stored.  Can you post a small zip file with some of the drawings?

Tim

Thanks. Only the titleblock within the sheet files A2-01a thru A2-01c was repathed. The test was for the new
directory location of C:\Jobs\2006\069999 and the original directory of F:\Jobs\2006\060614

- Drawing "C:\Jobs\2006\069999\acad\2436TB.dwg" report
 - Drawing "C:\Jobs\2006\069999\acad\A2-01a.dwg" report
  Xref name: 2436TB
    Xref path C:\Jobs\2006\069999\acad\2436TB.dwg
 - Drawing "C:\Jobs\2006\069999\acad\A2-01b.dwg" report
  Xref name: 2436TB
    Xref path C:\Jobs\2006\069999\acad\2436TB.dwg
 - Drawing "C:\Jobs\2006\069999\acad\A2-01c.dwg" report
  Xref name: 2436TB
    Xref path C:\Jobs\2006\069999\acad\2436TB.dwg
 - Drawing "C:\Jobs\2006\069999\acad\A2-02a.dwg" report
  Xref name: 2436TB
    Xref path C:\Jobs\2006\069999\acad\2436TB.dwg
 - Drawing "C:\Jobs\2006\069999\acad\A2-02b.dwg" report
  Xref name: 2436TB
    Xref path C:\Jobs\2006\069999\acad\2436TB.dwg
 - Drawing "C:\Jobs\2006\069999\acad\A2-02c.dwg" report
  Xref name: 2436TB
    Xref path C:\Jobs\2006\069999\acad\2436TB.dwg

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 24, 2006, 12:10:34 PM
Gary,

  Run this file, and post the log file created.
Title: Re: Repath xrefs with new path
Post by: GDF on July 24, 2006, 12:24:23 PM
Gary,

  Run this file, and post the log file created.

Tim

Still the same, only the titleblock is repathed in each of the xrefs.

 - Drawing "C:\Jobs\2006\069999\acad\2436TB.dwg" report
 - Drawing "C:\Jobs\2006\069999\acad\A2-01a.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
 - Drawing "C:\Jobs\2006\069999\acad\A2-01b.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
 - Drawing "C:\Jobs\2006\069999\acad\A2-01c.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 24, 2006, 12:31:33 PM
Do you see the differences though.
Quote
- Drawing "C:\Jobs\2006\069999\acad\A2-01b.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
The two xref's old paths are not the same.  So now I'm guessing that you want just the beginning of the paths changed?  In other words, whenever the program sees a path of
 F:\Jobs\2006\060614\ACAD\
change it to
C:\Jobs\2006\069999\acad\
no matter what is after it.  And you are picking the path
 F:\Jobs\2006\060614\ACAD\
right?
Title: Re: Repath xrefs with new path
Post by: GDF on July 24, 2006, 12:50:38 PM
Correct

- Drawing "C:\Jobs\2006\069999\acad\2436TB.dwg" report
 - Drawing "C:\Jobs\2006\069999\acad\A2-01a.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
 - Drawing "C:\Jobs\2006\069999\acad\A2-01b.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
 - Drawing "C:\Jobs\2006\069999\acad\A2-01c.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg


I started over from scratch with drawings copied over from F:\Jobs\2006\060614\acad and
placed them in C:\Jobs\2006\069999\acad and then ran your new routine...picking the old
and then the new folder location.

The tiltleblock resides in the same folder as the sheet files and is repathed. the unit plans
are xrefed into the bulding plan and are not repathed.

Here is the directory structure:

[] F:\Jobs\2006
   [] 060614 <old project folder>
      [] acad <folder for sheet files and titleblock>
         []  building  <folder for building plan>
         []  units  <folder for unit plans>
 
[] C:\Jobs\2006
   [] 069999 <new project folder>
      [] acad <folder for sheet files and titleblock>
         []  building  <folder for building plan>
         []  units  <folder for unit plans>

I hope I am running this right.

Title: Re: Repath xrefs with new path
Post by: T.Willey on July 24, 2006, 12:52:29 PM
Correct

<snip>

I hope I am running this right.
You are.  Here is a new version that should suites your needs.  Let me know

Edit:
Not sure how it will run on nested xrefs, but if it repaths them all, and get the main one right, then hopefully the rest will follow.

I think you might want to set up you future projects with relative paths for xrefs.  Which is kind of what Michael was talking about with the ProjectName stuff.  We used to use the relative paths here, but now we don't, but I think it will work with you folder structure.
Title: Re: Repath xrefs with new path
Post by: GDF on July 24, 2006, 02:36:36 PM
Tim

I did not pick up the nested xrefs, but it did pick up the building plan. Thank you.
This still a great time saver.

 - Drawing "C:\Jobs\2006\069999\acad\2436TB.dwg" report
 - Drawing "C:\Jobs\2006\069999\acad\A2-01a.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
 - Drawing "C:\Jobs\2006\069999\acad\A2-01b.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
 - Drawing "C:\Jobs\2006\069999\acad\A2-01c.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
 - Drawing "C:\Jobs\2006\069999\ACAD\2436TB.dwg" report
 - Drawing "C:\Jobs\2006\069999\ACAD\A2-01a.dwg" report
  Xref name: 2436TB
    Xref path old C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
 - Drawing "C:\Jobs\2006\069999\ACAD\A2-01b.dwg" report
  Xref name: 2436TB
    Xref path old C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
 - Drawing "C:\Jobs\2006\069999\ACAD\A2-01c.dwg" report
  Xref name: 2436TB
    Xref path old C:\Jobs\2006\069999\acad\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
 - Drawing "C:\Jobs\2006\069999\ACAD\2436TB.dwg" report
 - Drawing "C:\Jobs\2006\069999\ACAD\A2-01a.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\ACAD\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
    Xref path new C:\Jobs\2006\069999\ACAD\building\BL-01.dwg
 - Drawing "C:\Jobs\2006\069999\ACAD\A2-01b.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\ACAD\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
    Xref path new C:\Jobs\2006\069999\ACAD\building\BL-01.dwg
 - Drawing "C:\Jobs\2006\069999\ACAD\A2-01c.dwg" report
  Xref name: 2436TB
    Xref path old F:\Jobs\2006\060614\ACAD\2436TB.dwg
    Xref path new C:\Jobs\2006\069999\ACAD\2436TB.dwg
  Xref name: BL-01
    Xref path old F:\Jobs\2006\060614\ACAD\building\BL-01.dwg
    Xref path new C:\Jobs\2006\069999\ACAD\building\BL-01.dwg

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on July 24, 2006, 02:43:43 PM
I'm not sure how to pick up nested xref's since they are not really pathed from the current drawing.  I guess you could search each xref at it's path, and then change all those xrefs to the new paths also.  If you like I can see if I could code this up.   Let me know.

Glad it works for what you want.  You're welcome.  :-)
Title: Re: Repath xrefs with new path
Post by: GDF on July 24, 2006, 03:01:03 PM
I'm not sure how to pick up nested xref's since they are not really pathed from the current drawing.  I guess you could search each xref at it's path, and then change all those xrefs to the new paths also.  If you like I can see if I could code this up.   Let me know.

Glad it works for what you want.  You're welcome.  :-)

Tim

Thanks again for all of your hard work.

Gary
Title: Re: Repath xrefs with new path
Post by: GDF on August 08, 2006, 04:04:47 PM
Tim

Used this routine today for a large project that we had to repath. Thanks again for your
time saving routine. Works perfectly.

Gary
Title: Re: Repath xrefs with new path
Post by: T.Willey on August 08, 2006, 05:15:11 PM
Tim

Used this routine today for a large project that we had to repath. Thanks again for your
time saving routine. Works perfectly.

Gary
Gary,

  I saw a new post here, and got scared.  I'm glad it's GOOD news.  Glad you still like/use it.