Author Topic: Rename Reference name to match Xref file name  (Read 1600 times)

0 Members and 1 Guest are viewing this topic.

Dave M

  • Newt
  • Posts: 196
Rename Reference name to match Xref file name
« on: March 22, 2017, 03:06:23 PM »
I have a bunch of files that have xrefs attached.  The xref filenames have changed.  We use Projectwise, so I don't have to do any re-mapping, but the reference names don't match the file names.


Does anyone have a routine that will rename the references to match the file names?


Thanks in advance
Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Rename Reference name to match Xref file name
« Reply #1 on: March 22, 2017, 03:17:32 PM »
Old one from the library :)

Code - Auto/Visual Lisp: [Select]
  1. (defun _matchxrnametofilename (/ b blks n o p)
  2.   (while (setq b (tblnext "block" (not b)))
  3.     (if (and (setq p (cdr (assoc 1 b))) (setq o (vla-item blks (cdr (assoc 2 b)))))
  4.       (progn (if (/= (cdr (assoc 2 b)) (setq n (vl-filename-base p)))
  5.                (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-name (list o n)))
  6.              )
  7.       )
  8.     )
  9.   )
  10. )
  11. ;; (_matchxrnametofilename)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Rename Reference name to match Xref file name
« Reply #2 on: March 22, 2017, 04:00:08 PM »
Another (I've tried to write reversive way of Ron's) :
Code - Auto/Visual Lisp: [Select]
  1. (defun _matchxrnametofilename ( / p nx nb enx )
  2.     (and
  3.       (eq :vlax-true (vla-get-IsXRef b))
  4.       (setq p (vla-get-path b))
  5.       (/= (setq nx (cadr (fnsplitl p))) (setq nb (vla-get-Name o)) )
  6.       (not (tblsearch "BLOCK" nx))
  7.       (vl-catch-all-apply 'vla-put-name (list b nx))
  8.     )
  9.   )
  10. )

However this entmod part didn't worked, so thats why there are similarities between both codes :
Code: [Select]
(setq enx (entget (tblobjname "BLOCK" nb)))
(or
  (entmod (subst (cons 2 nx) (assoc 2 enx) enx))
  (entmod (append enx (list (cons 2 "asd"))))
)

:)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg