Author Topic: Update Code to accept nested Xref  (Read 1113 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Update Code to accept nested Xref
« on: May 10, 2018, 06:43:49 AM »
HI all
I want to Change color and LWeight for layers of Xrefs which in Model only. It is working good. but one or more of xrefs has nested Xref.
So, How to do the same for nested Xrefs.
Code - Auto/Visual Lisp: [Select]
  1. (if (Setq ss (ssget "_x" (list (cons 0 "INSERT") (cons 410 (if (eq 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model")))))
  2.     (repeat (setq i (sslength ss))
  3.       (setq s (ssname ss (setq i (1- i))))
  4.       (setq ent (entget s))
  5.       (setq xrn (cdr (assoc 2 ent)))
  6.       (setq xrn (strcat xrn "|*"))
  7.       (progn
  8.         (vlax-for i (vla-get-Layers Doc)
  9.           (if (wcmatch (vla-get-Name i) xrn)
  10.             (progn
  11.               (vla-put-Color i Clr)
  12.               (vla-put-lineweight i acLnWt009)
  13.               )))
  14.         (vla-Regen Doc acActiveViewport)
  15.         )))
« Last Edit: May 13, 2018, 04:31:49 AM by HasanCAD »

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Update Code to accept nested Xref
« Reply #1 on: May 13, 2018, 11:22:39 AM »
This is what I ended to
comments will be valuable
Code - Auto/Visual Lisp: [Select]
  1. (defun c:XrefLayerColor ( / adoc ACTLAY CLR DOC ENAMES I LAYOUTS PLOT SS XR XREN XRN XRNB XRS XRSS)
  2.   (defun *error* ( msg )
  3.   (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  4.     (princ (strcat "\nError: " msg))
  5.     )
  6.   (princ)
  7.   )
  8. (setq clr 252)
  9.  
  10.   (if (Setq ss (ssget "_x" (list (cons 0 "INSERT") (cons 410 (if (eq 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model")))))
  11.     (repeat (setq i (sslength ss))
  12.       (setq s (ssname ss (setq i (1- i))))
  13.       (setq ent (entget s))
  14.       (setq xrnn (cdr (assoc 2 ent)))
  15.       (setq xrn (strcat xrnn "|*"))
  16.       (vlax-for i (vla-get-Layers Doc)
  17.         (if (wcmatch (vla-get-Name i) xrn)
  18.           (progn
  19.             (vla-put-Color i Clr)
  20.             (vla-put-lineweight i acLnWt009)
  21.             )))
  22.       (if (setq ent (tblobjname "block" xrnn))
  23.         (while (setq ent (entnext ent))
  24.           (if (and             
  25.                 (eq "INSERT" (cdr (assoc 0 (entget ent))))
  26.                 (setq entnm  (cdr (assoc 2 (entget ent))))
  27.                 (= (vla-get-IsXRef (vla-item (vla-get-blocks doc) entnm) ) :vlax-true)
  28.                 )
  29.             (progn           
  30.               (setq xrn (strcat entnm "|*"))
  31.               (vlax-for i (vla-get-Layers Doc)
  32.                 (if (wcmatch (vla-get-Name i) xrn)
  33.                   (progn
  34.                     (vla-put-Color i Clr)
  35.                     (vla-put-lineweight i acLnWt009)
  36.                     )))))))))
  37.   (vla-Regen doc acActiveViewport)
  38.   (princ)
  39.   )
  40.