PDA

View Full Version : changing xref layer colors


mtubbs
2007-06-19, 07:53 PM
I am looking for code to change the color of all xref dependant layers to color 251, without autocad turning "on" all xref layers.

T.Willey
2007-06-19, 10:05 PM
(defun c:xr-c(/ xr1 xr2 xr3 xr4 xr5 xr6 tx1 xclr ocmd llist temp1)
; Change all the layers of an xref to selected color.

(vl-load-com)
(setq ocmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(command "_.undo" "_end")
(command "_.undo" "_group")
(if (setq xr1 (entsel "\nSelect xref to change color of all layers: "))
(progn
(setq xr2 (entget (car xr1)))
(setq tx1 (cdr (assoc 0 xr2)))
(if
(and
(= tx1 "INSERT")
(setq xr3 (cdr (assoc 2 xr2)))
(setq xr4 (tblsearch "block" xr3))
(setq xr5 (cdr (assoc 1 xr4)))
)
(if (setq xclr (acad_colordlg 251))
(progn
(if (assoc 62 xr2)
(entmod (subst (cons 62 xclr) (assoc 62 xr2) xr2))
(entmod (append xr2 (list (cons 62 xclr))))
)
(setq xr6 (strcat xr3 "|"))
(setq llist (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for item llist
(if (vl-string-search xr6 (vlax-get item 'Name))
(progn
(setq temp1 (vlax-get item 'TrueColor))
(vlax-put temp1 'ColorIndex (rtos xclr 2 0))
(vlax-put item 'TrueColor temp1)
)
)
)
)
)
(prompt "\n No X-Ref selected.")
)
)
(prompt "\n Nothing selected")
)
(command "_.regenall")
(command "_.undo" "_end")
(setvar "cmdecho" ocmd)
(princ)
)

mtubbs
2007-06-19, 11:40 PM
This is great, but I need it to automatically select all xrefs (not prompt for a selection), and auto set the colors to 251 (no color dialog box). Thanks

FRAMEDNLV
2007-06-19, 11:49 PM
Script version:
-LAYER
C
251
*|*



Chris

mtubbs
2007-06-21, 03:30 PM
Script version:
-LAYER
C
251
*|*



Chris
I know how to change the layer colors. The problem occurs when I change the color of xref layers that are turned "off". Autocad turns all the xref layers "on" when the layer color is changed.

T.Willey
2007-06-21, 03:51 PM
(defun c:Test (/ ActDoc)

(vlax-for Lay (vla-get-Layers (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object))))
(if (vl-string-search "|" (vla-get-Name Lay))
(vla-put-Color Lay 251)
)
)
(vla-Regen ActDoc acActiveViewport)
(princ)
)

mtubbs
2007-06-21, 03:59 PM
(defun c:Test (/ ActDoc)

(vlax-for Lay (vla-get-Layers (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object))))
(if (vl-string-search "|" (vla-get-Name Lay))
(vla-put-Color Lay 251)
)
)
(vla-Regen ActDoc acActiveViewport)
(princ)
)

Perfect! Thank you

T.Willey
2007-06-21, 04:12 PM
You're welcome.