Lisp to change properties of entire layers exception of item(s)

Lisp to change properties of entire layers exception of item(s)

Anonymous
Not applicable
2,998 Views
7 Replies
Message 1 of 8

Lisp to change properties of entire layers exception of item(s)

Anonymous
Not applicable

I've searched through few forums and on-line tutorial to find my answer but could not find any solution.

 

I am looking for a lisp routine to change properties of all layers in a drawing except one(or a list of layer) .

I want to have that exceptional layer(s) name to be art of my lisp and not by command line input. i.e., all layers except layer "ABC" or "ABC" and "DEF".

 

Thanks and happy weekend

0 Likes
Accepted solutions (1)
2,999 Views
7 Replies
Replies (7)
Message 2 of 8

hmsilva
Mentor
Mentor

@Anonymous wrote:

I've searched through few forums and on-line tutorial to find my answer but could not find any solution.

 

I am looking for a lisp routine to change properties of all layers in a drawing except one(or a list of layer) .

I want to have that exceptional layer(s) name to be art of my lisp and not by command line input. i.e., all layers except layer "ABC" or "ABC" and "DEF".

 


Hi Sam_RG,

something like this, perhaps

 

(vl-load-com)
(defun myfunctionname (lst)
    (vlax-for lay (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
        (if (not (vl-position (vla-get-Name lay) lst))
            (progn
             ;; do the changes here...
            )
        )
    )
)

; usage
; (myfunctionname '( "ABC" "DEF"))

 

Hope this helps,
Henrique

EESignature

Message 3 of 8

Anonymous
Not applicable

thanks for quick answer but not clear to mate.

 

let say I want change color of  all layers  to "6". How it will be now?

 

0 Likes
Message 4 of 8

hmsilva
Mentor
Mentor

@Anonymous wrote:

thanks for quick answer but not clear to mate.

 

let say I want change color of  all layers  to "6". How it will be now?

 


You're welcome, Sam_RG

 

But as you have said:

'I want to have that exceptional layer(s) name to be art of my lisp and not by command line input'

I thought you had already written that piece of code...

 

(vla-put-color lay 6)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 5 of 8

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....I am looking for a lisp routine to change properties of all layers in a drawing except one(or a list of layer) ....

and

.... let say I want change color of  all layers  to "6". How it will be now?


To change the color of all Layers to 6 except a single Layer, you can do just this, with a tilde ~ to negate the one Layer name:

(command "_.layer" "_color" 6 "~ABC" "")

 

But I haven't found a way to omit more than one Layer name in that approach.  Neither "~ABC,DEF" nor "~ABC,~DEF" works.

 

If you really mean all Layers in the question quoted above, and not all but one or two as in the original request, use an asterisk *:

 

(command "_.layer" "_color" 6 "*" "")

 

Kent Cooper, AIA
0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... 

I am looking for a lisp routine to change properties of all layers in a drawing except one(or a list of layer) .

I want to have that exceptional layer(s) name to be [p]art of my lisp and not by command line input. i.e., all layers except layer "ABC" or "ABC" and "DEF".

....


Another approach:

(defun C:TEST (/ lay)

  (while (setq lay (cdr (assoc 2 (tblnext "layer" (not lay)))))

    (if (not (wcmatch lay "ABC,DEF"))

      (command "_.layer" "_color" 6 lay "")

    )

  )

)

 

In the case of a single Layer name, you can replace

    (if (not (wcmatch lay "ABC,DEF"))

with

    (if (/= lay "ABC")

 

If such Layer names might have been made without the same upper/lower-case combination, such a Layer "Abc", replace

    (if (not (wcmatch lay "ABC,DEF"))

with

    (if (not (wcmatch (strcase lay) "ABC,DEF"))

 

Kent Cooper, AIA
Message 7 of 8

Anonymous
Not applicable

Thanks Kent and Henrique for your reply. This is exactly what I want Smiley Happy

0 Likes
Message 8 of 8

alaafarhat
Enthusiast
Enthusiast

hello

i was following this issue , since i need also to change all the color of the existing layers in Autocad to the same color with exceptions of one or more layers,

yet i have tried to do so with the existence of blocks and dimensions , i didn't get the needed result ,

How can i convert all the layers that i have into the same color with some exceptions

 Any HELP please ,....

thank you

0 Likes