Jump to content

Batch change xref names and repath dwgs


JeepMaster

Recommended Posts

I've found a way to rename xrefs with this script and it works fine. It basically changes the old xref to a new xref.

-rename
b
TBA0_old
TBA0_new
-xref
p
TBA0_new
"C:\NEW XREF\TBA0_new.dwg"

The problem is I have a lot of different xrefs thats changed and a lot of dwgs to repath. The floor plan of a 20 story building changed it's format. Level 0 changed from xxxFP00 to xxxFPP1, xxxFP01 to xxxFP00, xxxFP02 to xxxFP01... So basically everything is shifted one level, and I have a whole bunch of dwgs with different xrefs to fix. I could write a script to fix each level I guess, but it should be simple to make it into a lisp file, but I don't know how to go about this. Please help.

Link to comment
Share on other sites

  • Replies 43
  • Created
  • Last Reply

Top Posters In This Topic

  • JeepMaster

    12

  • ronjonp

    10

  • Lee Mac

    6

  • RyanGC

    5

Top Posters In This Topic

Posted Images

Here's a quickie that should do what you need. just add to the list of block names ("existname" . "newname")

 

(defun c:blkrenamer (/ b bcol)
 (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
 (foreach blk '(("xxxFP00" . "xxxFPP1") ("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01"))
   (if    (not (vl-catch-all-error-p
          (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk))))
        )
   )
     (vla-put-name b (cdr blk))
   )
 )
 (princ)
)

Link to comment
Share on other sites

Here's a quickie that should do what you need. just add to the list of block names ("existname" . "newname")

 

(defun c:blkrenamer (/ b bcol)
 (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
 (foreach blk '(("xxxFP00" . "xxxFPP1") ("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01"))
   (if    (not (vl-catch-all-error-p
          (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk))))
        )
   )
     (vla-put-name b (cdr blk))
   )
 )
 (princ)
)

Thanks Ron, this one works great, but I still can't get the repath lisp to work. I don't think it will do as it changes the xref path. For my purpose, my xref path is actually unchanged, but the actual xref drawing is.

Anyways, I've managed to modify your rename lisp and made it work for my purpose. But I need to make it as user friendly as possible so I can share it with my all my co-workers. How can I make the -xref command loop like the (foreach...) function? And some kind of error trap to move on to the next xref if this xref doesn't exist. Here's what I have so far.

(defun c:Xrefchanger (/ b bcol)
 (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
 (foreach blk '(
;******************************************************
;*******  Enter xref names below in this format  ******
;*******  ("OldXrefName" . "NewXrefName")        ******
;******************************************************

("oldxref1" . "newxref1")
("oldxref2" . "newxref2") 


;******************************************************
   )
   (if(not (vl-catch-all-error-p
      (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk))))
      )
   )
   (vla-put-name b (cdr blk))
   )
 )

;***********************************************************************
;*****  Enter new xerf name and full path below in this format *********
;****  "NewXrefName" "c:\\new path\\NewXrefName.dwg"           *********
;***********************************************************************


(command "-xref" "p" "newxref1" "c:\\new xref\\newxref1.dwg")  


;***********************************************************************

 (princ)
)

Link to comment
Share on other sites

Try this one to rename and change the name of the dwg in the path. I did not test it heavily...

 

It seems from doing this in the past that the results can only be viewed immediately using CLASSICXREF...when you reopen the drawing the changes should take effect.

 

(defun c:blkrenamer (/ b bcol path)
 (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
 (foreach blk '(("xxxFP00" . "xxxFPP1") ("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01"))
   (if
     (and 
      (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk))))))
      (= (vla-get-isxref b) :vlax-true)
     )
      (progn (vla-put-name b (cdr blk))
         (if (= (setq path (vl-filename-directory (vla-get-path b))) "")
       (vla-put-path b (strcat (cdr blk) ".dwg"))
       (vla-put-path b (strcat path "\\" (cdr blk) ".dwg"))
         )
      )
   )
 )
 (princ)
)

Link to comment
Share on other sites

Should be:

 

(defun c:blkrenamer (/ b bcol path)
 (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
 (foreach blk '(("xxxFP00" . "xxxFPP1") ("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01"))
   (if
     (and (= (vla-get-isxref [b][color=Red]blk[/color][/b]) :vlax-true)
      (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk))))))
     )
      (progn (vla-put-name b (cdr blk))
         (if (= (setq path (vl-filename-directory (vla-get-path b))) "")
       (vla-put-path b (strcat (cdr blk) ".dwg"))
       (vla-put-path b (strcat path "\\" (cdr blk) ".dwg"))
         )
      )
   )
 )
 (princ)
)

Me thinks :)

Link to comment
Share on other sites

Should be:

 

(defun c:blkrenamer (/ b bcol path)
 (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
 (foreach blk '(("xxxFP00" . "xxxFPP1") ("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01"))
   (if
     (and (= (vla-get-isxref [b][color=Red]blk[/color][/b]) :vlax-true)
      (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk))))))
     )
      (progn (vla-put-name b (cdr blk))
         (if (= (setq path (vl-filename-directory (vla-get-path b))) "")
       (vla-put-path b (strcat (cdr blk) ".dwg"))
       (vla-put-path b (strcat path "\\" (cdr blk) ".dwg"))
         )
      )
   )
 )
 (princ)
)

Me thinks :)

 

 

      (and 
      (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk))))))
      (= (vla-get-isxref b) :vlax-true)
     )

 

:P

Link to comment
Share on other sites

      (and 
      (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk))))))
      (= (vla-get-isxref b) :vlax-true)
     )

:P

 

Ahh, of course :oops: :oops: :oops:

Link to comment
Share on other sites

Thanks Ron,

It works now. I've added my other XRE.lsp on there so it will refresh all loaded xrefs right after it.:D

This is what I have now.

(defun c:blkrenamer (/ b bcol path)
 (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
 (foreach blk '(("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01")
   )
   (if
     (and 
      (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk))))))
      (= (vla-get-isxref b) :vlax-true)
     )
      (progn (vla-put-name b (cdr blk))
         (if (= (setq path (vl-filename-directory (vla-get-path b))) "")
       (vla-put-path b (strcat (cdr blk) ".dwg"))
       (vla-put-path b (strcat path "\\" (cdr blk) ".dwg"))
         )
      )
   )
 )
 (c:XRE)
 (princ)
)


(defun c:xre (/ cObj cName)
 
 (defun *error*(msg)
   (setvar "modemacro" ".")
   (setvar "cmdecho" 1)
   (princ "\n...Reload xref terminated!!!  ")
   (princ)
   ); end of *error*

 (setvar "modemacro" "Reloading loaded xrefs......please wait......")
 (setvar "cmdecho" 0)
 (setq cObj(tblnext "BLOCK" T))
 (while cObj
   (setq cName(cdr(assoc 2 cObj)))
   (if
     (and
    (=(logand(cdr(assoc 70 cObj))32)32)
    (=(logand(cdr(assoc 70 cObj))4)4)
    ); end and
     (progn
      (vl-cmdf "_.xref" "_unload" cName)
      (vl-cmdf "_.xref" "_reload" cName)
      ); end progn
     ); wnd if
 (setq cObj(tblnext "BLOCK"))
 ); end while
 (setvar "modemacro" ".")
 (setvar "cmdecho" 1)
 (prompt "\n--- Refreshed loaded Xrefs! ---")
 (princ)
 ); end of c:xre

Link to comment
Share on other sites

Thanks Ron,

It works now. I've added my other XRE.lsp on there so it will refresh all loaded xrefs right after it.:D

This is what I have now.

(defun c:blkrenamer (/ b bcol path)
 (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
 (foreach blk '(("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01")
   )
   (if
     (and 
      (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk))))))
      (= (vla-get-isxref b) :vlax-true)
     )
      (progn (vla-put-name b (cdr blk))
         (if (= (setq path (vl-filename-directory (vla-get-path b))) "")
       (vla-put-path b (strcat (cdr blk) ".dwg"))
       (vla-put-path b (strcat path "\\" (cdr blk) ".dwg"))
         )
      )
   )
 )
 (c:XRE)
 (princ)
)


(defun c:xre (/ cObj cName)
 
 (defun *error*(msg)
   (setvar "modemacro" ".")
   (setvar "cmdecho" 1)
   (princ "\n...Reload xref terminated!!!  ")
   (princ)
   ); end of *error*

 (setvar "modemacro" "Reloading loaded xrefs......please wait......")
 (setvar "cmdecho" 0)
 (setq cObj(tblnext "BLOCK" T))
 (while cObj
   (setq cName(cdr(assoc 2 cObj)))
   (if
     (and
    (=(logand(cdr(assoc 70 cObj))32)32)
    (=(logand(cdr(assoc 70 cObj))4)4)
    ); end and
     (progn
      (vl-cmdf "_.xref" "_unload" cName)
      (vl-cmdf "_.xref" "_reload" cName)
      ); end progn
     ); wnd if
 (setq cObj(tblnext "BLOCK"))
 ); end while
 (setvar "modemacro" ".")
 (setvar "cmdecho" 1)
 (prompt "\n--- Refreshed loaded Xrefs! ---")
 (princ)
 ); end of c:xre

 

You could add (vla-reload b) like so and it should reload without the need for the other lisp :D. Glad we got it sorted out....I'm gone fishing for the next 5 days so Lee will have to pick up from here :P

 

(defun c:blkrenamer (/ b bcol path)
 (setq bcol (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
 (foreach blk '(("xxxFP00" . "xxxFPP1") ("xxxFP01" . "xxxFP00") ("xxxFP02" . "xxxFP01"))
   (if
     (and (= (vla-get-isxref b) :vlax-true)
      (not (vl-catch-all-error-p (setq b (vl-catch-all-apply 'vla-item (list bcol (car blk))))))
     )
      (progn (vla-put-name b (cdr blk))
         (if (= (setq path (vl-filename-directory (vla-get-path b))) "")
       (vla-put-path b (strcat (cdr blk) ".dwg"))
       (vla-put-path b (strcat path "\\" (cdr blk) ".dwg"))
         )
         (vla-reload b)
      )
   )
 )
 (princ)
)

Link to comment
Share on other sites

Thanks so much Ron,

It works perfectly now. I know this will save a lot of people's time when some smarta$$ decides to change their floor plan name in the middle of the project. A few dwg is fine, but when you have over 80 dwgs to fix, then times that by 3 since it affects Mech, Elect, Struct....that's a lot of time wasted.:D

Link to comment
Share on other sites

Try this:

 

Start --> Programs --> Autodesk --> AutoCAD 20xx --> Reference Manager

 

I designed an application to cater for these needs and then discovered this Autodesk freebie so abandoned my plans.

 

Hope this helps.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...