Author Topic: Is it possible to change reference name for Xref?  (Read 3877 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Is it possible to change reference name for Xref?
« on: December 07, 2014, 09:20:53 AM »
Some Drafter re-path the Xref (in some cases the file name changed) and do not change the reference name.
For example See Attached.
So I am wondering if it possible to change the reference name using Lisp/VLisp?

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Is it possible to change reference name for Xref?
« Reply #1 on: December 08, 2014, 02:11:29 AM »
Stucked, How to extract filename from the path
Code: [Select]
  (defun selx  (/ blk name xrefs) ;LEE-mac.com
  (while (setq blk (tblnext "BLOCK" (not blk)))
    (if (> (logand 4 (cdr (assoc 70 blk))) 0)
      (progn
        (setq name  (cdr (assoc 2 blk))
              xrefs (if xrefs (strcat xrefs "," name) name)))))
  (ssget "X" (list '(0 . "INSERT") (cons 2 xrefs))))
(setq cntX 0)
      (if (sslength (setq ss (selx)))
   (progn
     (while
       (setq blk (ssname ss cntX ))
       (setq BlkEnt (tblnext "BLOCK" T))
       (setq blkpath (cdr (assoc 1 BlkEnt)))
       (setq XrefName                                                         ;Stucked
       (setq blk (vlax-ename->vla-object blk))
       (vla-put-Name blk XrefName)       
       (vla-update blk)
       (setq cntX (1+ cntX))
       )))

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Is it possible to change reference name for Xref?
« Reply #2 on: December 08, 2014, 03:38:05 AM »
You may need to re-open the drawing to see the changes .

Code: [Select]
(defun selx (/ blk name xrefs)          ;LEE-mac.com
  (while (setq blk (tblnext "BLOCK" (not blk)))
    (if (> (logand 4 (cdr (assoc 70 blk))) 0)
      (progn
        (setq name  (cdr (assoc 2 blk))
              xrefs (if xrefs
                      (strcat xrefs "," name)
                      name
                    )
        )
      )
    )
  )
  (ssget "X" (list '(0 . "INSERT") (cons 2 xrefs)))
)
(if (setq ss (selx))
  (progn
    (setq in  -1
          bks (vla-get-blocks
                (vla-get-activedocument
                  (vlax-get-acad-object)
                )
              )
    )
    (while (setq sn (ssname ss (setq in (1+ in))))
      (setq blk (vlax-ename->vla-object sn))
      (vla-put-Name
        (vla-item bks (vla-get-name blk))
        (vl-filename-base (vla-get-path blk))
      )
    )
  )
)

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Is it possible to change reference name for Xref?
« Reply #3 on: December 08, 2014, 06:50:24 AM »
Thanks Tharwat


ronjonp

  • Needs a day job
  • Posts: 7529
Re: Is it possible to change reference name for Xref?
« Reply #5 on: December 09, 2014, 10:32:27 AM »
Another:
Code - Auto/Visual Lisp: [Select]
  1. (defun _foo (/ b el n p)
  2.   (while (setq b (tblnext "block" (not b)))
  3.     (and (setq p (assoc 1 b))
  4.          (/= (cdr (assoc 2 b)) (setq n (vl-filename-base (cdr (assoc 1 b)))))
  5.          (setq el (cdr (assoc -2 b)))
  6.          (setq el (cdr (assoc 330 (entget el))))
  7.          (setq el (cdr (assoc 360 (entget el))))
  8.          (setq el (cdr (assoc 330 (entget el))))
  9.          (entmod (subst (cons 2 n) (assoc 2 (entget el)) (entget el)))
  10.     )
  11.   )
  12. )
  13. (_foo)


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Is it possible to change reference name for Xref?
« Reply #6 on: December 10, 2014, 01:37:43 AM »
Another:
Code - Auto/Visual Lisp: [Select]
  1. (defun _foo (/ b el n p)
  2.   (while (setq b (tblnext "block" (not b)))
  3.     (and (setq p (assoc 1 b))
  4.          (/= (cdr (assoc 2 b)) (setq n (vl-filename-base (cdr (assoc 1 b)))))
  5.          (setq el (cdr (assoc -2 b)))
  6.          (setq el (cdr (assoc 330 (entget el))))
  7.          (setq el (cdr (assoc 360 (entget el))))
  8.          (setq el (cdr (assoc 330 (entget el))))
  9.          (entmod (subst (cons 2 n) (assoc 2 (entget el)) (entget el)))
  10.     )
  11.   )
  12. )
  13. (_foo)
There is no thing happen
All var are EL

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Is it possible to change reference name for Xref?
« Reply #7 on: December 10, 2014, 02:02:00 AM »
Reference Manager allows me to change multiple drawings xrefs  / paths without opening the files... it was installed with Civil 3d. I don't know if it's installed with Autocad by itself.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Is it possible to change reference name for Xref?
« Reply #8 on: December 10, 2014, 02:20:35 AM »
Reference Manager allows me to change multiple drawings xrefs  / paths without opening the files... it was installed with Civil 3d. I don't know if it's installed with Autocad by itself.
Yes, It is. But Reference Manager not allow to change filename. Only the path

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Is it possible to change reference name for Xref?
« Reply #9 on: December 10, 2014, 02:31:57 AM »
Reference Manager allows me to change multiple drawings xrefs  / paths without opening the files... it was installed with Civil 3d. I don't know if it's installed with Autocad by itself.
Yes, It is. But Reference Manager not allow to change filename. Only the path

I am using Cad 2014 and that ability is available as what Alien 's said .

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Is it possible to change reference name for Xref?
« Reply #10 on: December 10, 2014, 05:13:17 AM »
Reference Manager allows me to change multiple drawings xrefs  / paths without opening the files... it was installed with Civil 3d. I don't know if it's installed with Autocad by itself.
Yes, It is. But Reference Manager not allow to change filename. Only the path

I am using Cad 2014 and that ability is available as what Alien 's said .
Reference Manager changes Xrefs paths for several files. Is there a new options in RM2014?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Is it possible to change reference name for Xref?
« Reply #11 on: December 10, 2014, 08:18:06 AM »
Another:
Code - Auto/Visual Lisp: [Select]
  1. (defun _foo (/ b el n p)
  2.   (while (setq b (tblnext "block" (not b)))
  3.     (and (setq p (assoc 1 b))
  4.          (/= (cdr (assoc 2 b)) (setq n (vl-filename-base (cdr (assoc 1 b)))))
  5.          (setq el (cdr (assoc -2 b)))
  6.          (setq el (cdr (assoc 330 (entget el))))
  7.          (setq el (cdr (assoc 360 (entget el))))
  8.          (setq el (cdr (assoc 330 (entget el))))
  9.          (entmod (subst (cons 2 n) (assoc 2 (entget el)) (entget el)))
  10.     )
  11.   )
  12. )
  13. (_foo)
There is no thing happen
All var are EL
Works here on AutoCAD 2015. Only works on xrefs without any nesting. You might have to reload the xrefs to see the change in the xref palette. Or Use CLASSICXREF to see the changes without reloading.

The reason for stepping through the variable 'EL' is ENTGET will break if you pass it a NIL value. Try it (entget nil).

This version seems to work:
Code - Auto/Visual Lisp: [Select]
  1. (defun _foo (/ b blks n o p)
  2.   (while (setq b (tblnext "block" (not b)))
  3.     (if (and (setq p (cdr (assoc 1 b)))
  4.              (setq o (vla-item blks (cdr (assoc 2 b))))
  5.              (/= (cdr (assoc 2 b)) (setq n (vl-filename-base p)))
  6.         )
  7.       (progn (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-name (list o n))) (vla-reload o))
  8.     )
  9.   )
  10. )
  11. (_foo)
« Last Edit: December 10, 2014, 08:43:25 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC