TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Dave M on March 22, 2017, 03:06:23 PM

Title: Rename Reference name to match Xref file name
Post by: Dave M 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
Title: Re: Rename Reference name to match Xref file name
Post by: ronjonp 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)
Title: Re: Rename Reference name to match Xref file name
Post by: Grrr1337 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"))))
)

:)