Author Topic: Repath xrefs with new path  (Read 22972 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Repath xrefs with new path
« 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
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Repath xrefs with new path
« Reply #1 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
)
« Last Edit: July 20, 2006, 03:10:06 PM by T.Willey »
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Repath xrefs with new path
« Reply #2 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
« Last Edit: July 20, 2006, 03:16:48 PM by Gary Fowler »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Repath xrefs with new path
« Reply #3 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.
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Repath xrefs with new path
« Reply #4 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



Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Repath xrefs with new path
« Reply #5 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?
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Repath xrefs with new path
« Reply #6 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.
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Repath xrefs with new path
« Reply #7 on: July 20, 2006, 04:04:08 PM »
Tim

 -Error no function definition: DIRECTORY-DIA

I can't find my copy.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Repath xrefs with new path
« Reply #8 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


Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Repath xrefs with new path
« Reply #9 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
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Repath xrefs with new path
« Reply #10 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
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Repath xrefs with new path
« Reply #11 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.
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Repath xrefs with new path
« Reply #12 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))
)
)
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Repath xrefs with new path
« Reply #13 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

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Repath xrefs with new path
« Reply #14 on: July 20, 2006, 05:18:24 PM »
Tim

Don't have SaveAsEx function.
Thanks.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64