PDA

View Full Version : Changing color of Xref layers based on color and layer name



tuerlinckx_peter862162
2013-02-12, 03:40 PM
Dear all,

I am trying to find a way to change the color of Xref layers. Based on the original color of the layer in the original drawing.
But this is giving me some troubles. At the moment i think i understand how i can cycle through the entire layer list. However i don't understand how the lisp can make the difference in layer colors and such...

Is there anyone who is willing to help me upgragde my code a bit?

So far i came up with:

(vl-load-com)
(defun C:TEBXFADE ()
(setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
(setq theLayers (vla-get-layers acadDocument))
(setq i 0)
(repeat (vla-get-count theLayers)
(setq aLayer (vla-item theLayers i))
(cond ((and (= vla-get-color 1) (= vla-get-name "*|*"))
(vla-put-color alayer 251))
((and (= vla-get-color 2) (= vla-get-name "*|*"))
(vla-put-color alayer 9))
((and (= vla-get-color 3) (= vla-get-name "*|*"))
(vla-put-color alayer 8))
((and (= vla-get-color 4) (= vla-get-name "*|*"))
(vla-put-color alayer 8))
((and (= vla-get-color 5) (= vla-get-name "*|*"))
(vla-put-color alayer 8))
((and (= vla-get-color 7) (= vla-get-name "*|*"))
(vla-put-color alayer 251))
((and (= vla-get-color 8) (= vla-get-name "*|*"))
(vla-put-color alayer 252))
((and (= vla-get-color 9) (= vla-get-name "*|*"))
(vla-put-color alayer 252))
((and (= vla-get-color 250) (= vla-get-name "*|*"))
(vla-put-color alayer 252))
((and (= vla-get-color 251) (= vla-get-name "*|*"))
(vla-put-color alayer 252))
((and (= vla-get-color 253) (= vla-get-name "*|*"))
(vla-put-color alayer 254))
(T (princ "\nNo Xref layers found"))
(setq i (1+ i))
);cond
);repeat
);defun

Tharwat
2013-02-12, 05:50 PM
Here is a good start to begin with .



(vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(cond ((and (= (vla-get-color layer) 1)(wcmatch (vla-get-name layer) "*|*"))
(vla-put-color layer 251))
((............;;; do the rest typical to the above two lines of code ....

BlackBox
2013-02-12, 09:29 PM
(vl-load-com)

(defun c:FOO (/ layerColor)

;; iterate the layer collection object
(vlax-for oLayer (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)

;; if an xref layer
(if (wcmatch (vla-get-name oLayer) "*|*")

;; conditionally check the existing layer color,
;; and change it if a match is found
(cond ((vl-position
(setq layerColor (vla-get-color oLayer))
'(1 7)
)
(vla-put-color oLayer 251)
)
((= 2 layerColor) (vla-put-color oLayer 9))
((vl-position layerColor '(3 4 5)) (vla-put-color oLayer 8))
((= 7 layerColor) (vla-put-color oLayer 251))
((vl-position layerColor '(8 9 250 251))
(vla-put-color oLayer 252)
)
((= 253 layerColor) (vla-put-color oLayer 254))
)
)
)
)

tuerlinckx_peter862162
2013-02-13, 08:14 AM
Both are great! :D

I am now using the one Render Man is posting and i'll try to update some new stuff in it like a selection set to decide which xref i want to change instead of all...

Either case can someone explain me what the ' means in the piece of code ((vl-position layerColor '(3 4 5)) (vla-put-color oLayer 8))

Thank you!

Tharwat
2013-02-13, 10:55 AM
Either case can someone explain me what the ' means in the piece of code ((vl-position layerColor '(3 4 5)) (vla-put-color oLayer 8))



The vl-position function would return a number indicating that the variable LAYERCOLOR is matching or is a member of the the list '(3 4 5) which means or give True sign to use the function
vla-put-color to change the color of the object that held by the variable oLayer .

Hope this help :)

tuerlinckx_peter862162
2013-02-13, 12:15 PM
so the '() means that everything between is a part of the list ...
meaning in this case '(1 2 3 7 8 9) if the value from layercolors is either of the numbers in the list it will give a True and thus triggering the condition.

It helps ;) for a new lisp writer like me everything is still such a confusing part ... :p

Tharwat
2013-02-13, 12:23 PM
......... it will give a True and thus triggering the condition.


Not exactly , but it will return an index , and that number ( index ) indicates to the position of that element ( symbol ) in the list .

BlackBox
2013-02-14, 06:46 PM
so the '() means that everything between is a part of the list ...
meaning in this case '(1 2 3 7 8 9) if the value from layercolors is either of the numbers in the list it will give a True and thus triggering the condition.


The QUOTE (http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6974.htm) function is used here to tell LISP 'do not evaluate this list'.

As the vl-Position statement serves as a test expression, within the COND statement, any non-Nil value returned (does not have to be True)... Which as Tharwat has already pointed out, is an integer representing the position the symbol is within the list... then the resultant expression (within that condition) is then evaluated.