Author Topic: XREFs code  (Read 2657 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
XREFs code
« on: September 13, 2013, 11:08:09 AM »
In need of simple code to check the existence of any XREF's in current drawing and if any found LOCK the layer they are inserted on.

Thanks,
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: XREFs code
« Reply #1 on: September 13, 2013, 11:47:26 AM »
Try this quick draft:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:lxr ( / a b e i l s x )
  2.     (while (setq a (tblnext "block" (null a)))
  3.         (if (= 4 (logand 4 (cdr (assoc 70 a))))
  4.             (setq b (vl-list* "," (cdr (assoc 2 a)) b))
  5.         )
  6.     )
  7.     (if (and b (setq s (ssget "_X" (list '(0 . "INSERT") (cons 2 (apply 'strcat (cdr b)))))))
  8.         (repeat (setq i (sslength s))
  9.             (if (not (member (setq x (cdr (assoc 8 (entget (ssname s (setq i (1- i))))))) l))
  10.                 (setq l (cons x l))
  11.             )
  12.         )
  13.     )
  14.     (foreach x l
  15.         (setq e (entget (tblobjname "layer" x))
  16.               a (assoc 70 e)
  17.         )
  18.         (entmod (subst (cons 70 (logior 4 (cdr a))) a e))
  19.     )
  20.     (princ)
  21. )

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: XREFs code
« Reply #2 on: September 13, 2013, 12:01:55 PM »
Maybe REGEN would be needed after locking layers.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: XREFs code
« Reply #3 on: September 13, 2013, 01:20:24 PM »
Quote
Lee Mac

Thank you sir for your generous support. That procedure worked perfectly.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: XREFs code
« Reply #4 on: September 13, 2013, 05:00:27 PM »
Thank you sir for your generous support. That procedure worked perfectly.

You're very welcome V-Man  :-)

tedg

  • Swamp Rat
  • Posts: 811
Re: XREFs code
« Reply #5 on: September 16, 2013, 02:17:00 PM »
In need of simple code to check the existence of any XREF's in current drawing and if any found LOCK the layer they are inserted on.

Thanks,
Instead of locking whatever layer  they are inserted on, why wouldn't you want to put your xrefs on an appropriate layer and then lock it?
 
Such as G-ANNO-REFR (or what ever your desired standard is)?
 
Just a thought.
 
That way if someone put an xref on the wrong layer such as a text layer, you're not locking that one.
Windows 10 Pro 64bit, AutoCAD 2023, REVIT 2023

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: XREFs code
« Reply #6 on: September 16, 2013, 08:02:59 PM »

I agree Ted. One option is to name the layer to match the xref name ... 'standards' allowing :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.