Author Topic: Repath Xref dwgs to specific folder path  (Read 865 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 798
Repath Xref dwgs to specific folder path
« on: February 14, 2018, 05:56:55 AM »
Hello everyone.

I have a drawing that it has a bunch of Xref drawings that are not available now due to change of their path.

is there a way to re-path those Xref to another path of specific Folder to be able to reload them and to show up normally as before?

Thank you.

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: Repath Xref dwgs to specific folder path
« Reply #1 on: February 14, 2018, 08:12:37 AM »
Use the Reference Manager provided with AutoCAD.

Coder

  • Swamp Rat
  • Posts: 798
Re: Repath Xref dwgs to specific folder path
« Reply #2 on: February 14, 2018, 08:22:40 AM »
Use the Reference Manager provided with AutoCAD.
Thank you Lee for your reply.
I tried that while searching for a solution before starting my thread here but I could not understand the way it works.  :-(


dgorsman

  • Water Moccasin
  • Posts: 2423
Re: Repath Xref dwgs to specific folder path
« Reply #4 on: February 14, 2018, 10:11:47 AM »
You can also use the Project setting to create a separate set of folders for searching for XREFs with missing paths.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Coder

  • Swamp Rat
  • Posts: 798
Re: Repath Xref dwgs to specific folder path
« Reply #5 on: February 14, 2018, 10:24:30 AM »
You can also use the Project setting to create a separate set of folders for searching for XREFs with missing paths.

Thank you.

How can I do that please ?

MP

  • Seagull
  • Posts: 17664
  • Have thousands of dwgs to process? Contact me.
Re: Repath Xref dwgs to specific folder path
« Reply #6 on: February 14, 2018, 10:29:53 AM »
Be careful leveraging the projectname variable. While powerful when used judiciously Autodesk fubar'd the implementation IMO so unless you know what you're doing -- and fully appreciate the impacts of using it -- don't.
Engineering Technologist CAD Specialist Programmer Analyst
Design Drafting Document Control Automation.
cadanalyst@fastmail.com https://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9484
Re: Repath Xref dwgs to specific folder path
« Reply #7 on: February 14, 2018, 10:47:56 AM »
Unfortunately, I don't have much of my old stuff but I did find the following two routines I used.

The first one was I remember on a large project with hundreds of drawings that needed to be re-pathed so I quickly penned the following for my specific needs at the time (I had my own scripting system/procedure/"thing"). The second example is something I created while teaching autolisp to a co-worker (he came up with the idea and we coded it together).

I'm afraid you'd have to decipher these because I just don't have the skills or time anymore. And I'm sorry for the lack of comments in the first one (but I included the pseudo code I had with it, if that helps); it was a total one-off I needed at the time and I was most likely in a time crunch.

EDIT: And neither probably work or employ very bad code practices so please take them with a grain of salt.

Code: [Select]
;; find and replace/rename xrefs.
;;
;; pseudo code:
iterate thru xrefs.
        if unreferenced
                check name
                        if has `mm' in name
                                prefix name with `P1_'
                                redo path to include `P1_' in file to xref


Code - Auto/Visual Lisp: [Select]
  1. ( (lambda (/ entry xname xpath saved-xref-name)
  2.     (while
  3.       ;; itterate thru all xrefs in dwg
  4.  
  5.       (setq entry (tblnext "block" (not entry)))
  6.       ;; get the first block
  7.  
  8.       (if (= (cdr (assoc 70 entry)) 12)
  9.         (progn
  10.           (command "xref" "P" (cdr (assoc 2 entry))
  11.                    (strcat
  12.                      "<BLAH<BLAH>\\0 - MASTER SHEETS\\P1_"
  13.                      (cdr (assoc 2 entry))))
  14.           (setq xref
  15.                 (subst
  16.                   (cons 2
  17.                         (strcat
  18.                           "P1_"
  19.                           (cdr (assoc 2 entry))))
  20.                   (assoc 2 entry)
  21.                   entry
  22.                   )
  23.                 ;;                   xref
  24.                 ;;                   (subst
  25.                 ;;                     (cons 1
  26.                 ;;                           (strcat
  27.                 ;;                             "<BLAH<BLAH>\\0 - MASTER SHEETS\\P1_"
  28.                 ;;                             (cdr (assoc 2 entry))))
  29.                 ;;                     (assoc 1 entry)
  30.                 ;;                     entry)
  31.                 )
  32.           (entmod xref)
  33.           (print xref)
  34.           )
  35.         ) ; if
  36.       ) ; while
  37.     (princ)
  38.     )
  39.  )
Code - Auto/Visual Lisp: [Select]
  1. (defun c:relpath ( / )
  2.    ;;
  3.    ;; Needs echo off
  4.    ;; need to test with nested xrefs
  5.    ;;
  6.    ;; By: Orig concept Eric H 03-31-06
  7.    ;;     John Kaul 04-03-06
  8.  
  9.    (defun StringStrip-End ( Str Char )
  10.      ;; Strip the end of a string off.
  11.      ;; e.g. (StringStrip-End "This is a test" "i")
  12.      ;;   -> "This "
  13.      (defun ListStriper ( lst dec )
  14.        (if (= (car lst) dec)
  15.          (cdr lst)
  16.          (ListStriper (cdr lst) dec)) )
  17.      (if (not (and Str Char))
  18.        ;; if neither the str or char are present, return an empty str
  19.        ""
  20.      (vl-List->String
  21.        (reverse
  22.          (ListStriper (reverse (vl-string->list Str)) (ascii Char)))) ))
  23.  
  24.    (defun strParse (aStr delim / strList pos)
  25.       (while (setq pos (vl-string-search delim aStr 0))
  26.              (setq strList (cons (substr aStr 1 POS) strList)
  27.                    aStr (substr aStr (+ pos 2))))
  28.       (reverse (cons aStr strList)) )
  29.  
  30.    ( (lambda (/ entry xname xpath saved-xref-name)
  31.        (while
  32.          ;; itterate thru all xrefs in dwg
  33.  
  34.         (setq entry (tblnext "block" (not entry)))
  35.          ;; get the first block
  36.  
  37.          (if (cdr (assoc 1 entry))
  38.            ;; check to see if it has a path
  39.            ;;
  40.            ;; if it does...
  41.            (progn
  42.              (setq saved-xref-name (cdr (assoc 2 entry))
  43.              ;; get the name saved in database
  44.                    xname (strcase (car (reverse (strParse (cdr (assoc 1 entry)) "\\"))))
  45.              ;; get the drawing name saved for name in database
  46.                    xpath (strcat "..\\B\\" xname) )
  47.              ;; set a reletive path based upon company standards.
  48.              (if (findfile xpath)
  49.                ;; try to find the drawing with the reletive path
  50.                ;;
  51.                ;; if found... then load it
  52.                (command "-xref" "path" saved-xref-name xpath)
  53.  
  54.                
  55.                ;; Try to make it reletive based on working drawing path.
  56.                ;;
  57.                ;; NOTE: This is not `correct', but I cant think of
  58.                ;;       another way right now.
  59.  
  60.                (if (eq
  61.                      (strcat (StringStrip-End (findfile xname) "\\") "\\")
  62.                      (getvar 'DWGPREFIX))
  63.                  ;; If all else fails, check to see if the saved
  64.                  ;; path is the same as the current drawing path...
  65.                  ;; Lets hope this is the place for the drawing
  66.                  (command "-xref" "path" saved-xref-name (strcat ".\\" xname))
  67.                ) ; if
  68.              ) ; if
  69.            ) ; progn
  70.          ) ; if
  71.       ) ; while
  72.     (princ)
  73.    )
  74.   )
  75. )
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: Repath Xref dwgs to specific folder path
« Reply #8 on: February 14, 2018, 01:07:33 PM »
Use the Reference Manager provided with AutoCAD.
Thank you Lee for your reply.
I tried that while searching for a solution before starting my thread here but I could not understand the way it works.  :-(

Did you attempt to learn it?

I found this after two minutes on Google:
https://www.youtube.com/watch?v=3safVjTaV8o

Coder

  • Swamp Rat
  • Posts: 798
Re: Repath Xref dwgs to specific folder path
« Reply #9 on: February 15, 2018, 01:18:38 AM »
Thank you John for your posted codes. Sorry, despite of that I changed the path, the codes did nothing.

Thank you Lee for your time and kind working on my thread. I watched that exact video yesterday but did not get it in that time but today with a few tries on drawings I learned how to change the saved paths so quickly and easily.

Many thanks for all of you kind guys.

reyas1123

  • Newt
  • Posts: 39
Re: Repath Xref dwgs to specific folder path
« Reply #10 on: February 15, 2018, 02:46:57 AM »
Command: REDIR

Current REDIRMODE: Styles,Xrefs,Images,Rtext
Find and replace directory names
Enter old directory (use '*' for all), or ? <options>: c:\test
Repace "C:\TEST" with: D:\TEST

Coder

  • Swamp Rat
  • Posts: 798
Re: Repath Xref dwgs to specific folder path
« Reply #11 on: February 15, 2018, 04:19:19 AM »
Command: REDIR

Current REDIRMODE: Styles,Xrefs,Images,Rtext
Find and replace directory names
Enter old directory (use '*' for all), or ? <options>: c:\test
Repace "C:\TEST" with: D:\TEST

Thank you.

That is new to me but it did not work for me.