Jump to content

Change VP Layer Colour


Earlzii

Recommended Posts

Hi,

 

I need some help I need to create a selection of layers that have a certain keyword in the layername. For the example it is looking for the word TEST.

 

It should then run the command VPLAYER and change the colour in all viewports for layers that contain the word TEST.

 

The lisp routine runs fine but does not seem to select anything. I have probably done something wrong in the ssget part but I cannot figure out what I have done.

 

(defun C:test ( / layerlist)

(setq layerlist (ssget "x" (list (cons 0 "TEST"))))

(command "vplayer" "c" "253" layerlist "")
)

 

If any of you guys could help that would be great.

 

Thanks

Link to comment
Share on other sites

Probably need some WCMATCH and an IF statement to do one thing or the other.

 

But don't ask me how to implement that.

 

(defun C:test ( / layerlist)
(if (wcmatch (strcase (vla-get-name layer)) "*TEST*")
(command "vplayer" "c" "253" layerlist "")
() ; do nothing if layer exist that contains TEST
)
)

 

Above code should do the trick (or get's you going in the right way).. but it might nog work at all :P.

Link to comment
Share on other sites

thanks for the reply.

 

I've tried the code that you have there and I couldn't get it to work.

 

I'm going to actually look into the WCMATCH that you suggested and try and figure it out. Thanks for giving me an idea into what to look at.

Link to comment
Share on other sites

How about something like this?

 

(defun GetMatchingLayers (keyword / lays li )
 (setq lays (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'Layers))
 (vlax-for lay lays
   (if (wcmatch (strcase (vlax-get-property lay 'Name)) (strcat "*" keyword "*"))
     (setq li (append li (list lay)))
     )
   )
 li
 )

Link to comment
Share on other sites

Thanks for the reply Hippe. I have a very basic knowledge of lisp and I have no idea what the vlax parts are doing but I've tried running this and I get an error saying too few arguments.

 

I've tried to add in an else part to the if statement to show an alert saying there are no layers containing the keyword but this didn't solve it. I think the error is in relation to vlax part.

 

(defun GetMatchingLayers (keyword / lays li )
 (setq lays (vlax-get-property (vlax-get-property (vlax-get-acad-object) 'ActiveDocument) 'Layers))
 (vlax-for lay lays
   (if (wcmatch (strcase (vlax-get-property lay 'Name)) (strcat "*" TEST "*"))
     (setq li (append li (list lay)))
(ALERT
"There are no layers containing TEST"
)
     )
   )
 )

(defun C:vptest (li)
(GetMatchingLayers)
(command "vplayer" "c" "253" li "c" "")
)

Link to comment
Share on other sites

If you just want to change layer colors, I'd go with something like this:

 

[b][color=BLACK]([/color][/b]defun c:layclr [b][color=FUCHSIA]([/color][/b]/ sc td ln ll[b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]setq sc [b][color=NAVY]([/color][/b]strcase [b][color=MAROON]([/color][/b]getstring [color=#2f4f4f]"\nLAyer Search Phrase:  <TEST>:   "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]= sc [color=#2f4f4f]""[/color][b][color=NAVY])[/color][/b]
     [b][color=NAVY]([/color][/b]setq sc [color=#2f4f4f]"TEST"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq td [b][color=MAROON]([/color][/b]tblnext [color=#2f4f4f]"LAYER"[/color] [b][color=GREEN]([/color][/b]not td[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq ln [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 2 td[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]wcmatch ln [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"*"[/color] sc [color=#2f4f4f]"*"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b]setq ll [b][color=GREEN]([/color][/b]cons ln ll[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]"_.LAYER"[/color][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]foreach l ll
    [b][color=NAVY]([/color][/b]command [color=#2f4f4f]"_Color"[/color] 253 l[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]""[/color][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

I don't know anything about VPLAYER color command. It hasn't been around very long.

Link to comment
Share on other sites

Thanks David I have managed to figure out how to change the layers colour with this.

(defun c:LAYTEST ( )
   (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
       (if (wcmatch (strcase (vla-get-name layer)) "*TEST*")
           (vl-catch-all-apply 'vla-put-color (list layer 253))
       )
   )
   (princ)
)
(vl-load-com) (princ)

It is basically Lee Macs code in another forum post and I just changed it from changing the layer name to the colour.

 

The drawings that I do we split depending on each discipline Civil Mechanical etc. The drawings however contain all the information from each discipline to give the drawing some context but for the Civil drawings the civil information will be in its original colour and everything else is set to colour 253.

All of the information is controlled through xrefs and we have strict rules about changing colours etc. that basically say you have to do it through a Viewport which is where the VPLAYER command comes in.

 

We usually just bring up the layer manager when in an active viewport and change the colour there for each individual viewport. But this is a bit tiresome and everytime something changes in the design we have to go back through this so I just wanted a Lisp to automatically set the layer colours to save some time as there can be hundreds of drawings some times.

 

Also forgot to say each layer will have a prefix i.e. CIV for Civil MEC for Mechanical etc. this is what I want the lisp to do search for layers that contain CIV and change the viewport colour to 253 not the actual layer colour.

Link to comment
Share on other sites

I think I've cracked it.

 

(defun c:TEST ( )
   (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
       (if (wcmatch (setq laylist (strcase (vla-get-name layer))) "*TEST*")
(command "vplayer" "c" "253" laylist "a" "")
       )
   )
   (princ)
)
(vl-load-com) (princ)

 

I'm not sure if it's the most efficient way or if there will be any errors in the future after multiple uses etc. but it seems to do the job.

 

Thanks for the help chaps.

Link to comment
Share on other sites

Here's a working version of David's code, modified to step through VPLAYER- I noticed your version is case sensitive, and I like the prompt in David's for other layers

(defun c:layclr (/ sc td ln ll)

 (setq sc (strcase (getstring "\nLAyer Search Phrase:  <TEST>:   ")))
 (if (= sc "")
     (setq sc "TEST"))

 (while (setq td (tblnext "LAYER" (not td)))
        (setq ln (cdr (assoc 2 td)))
        (if (wcmatch ln (strcat "*" sc "*"))
            (setq ll (cons ln ll))))

 (foreach l ll
    (command "vplayer" "c" 253 l "all" ""))

(prin1))

Link to comment
Share on other sites

It is a good idea especially if anyone else is going to use this, but for what I need it for it is going to be a bit redundant as we only use specific layers which I will factor into the routine now that I have a working example.

 

Thanks for your help guys.

Link to comment
Share on other sites

Did you look at the code of COLORXLAY?

Could be a nice to make this suitable for these kinds of operations

 

 

add ..

 

 

(checkbox) VPlayers (when tilemode =0 in modelspace)

(checkbock) layers : * (sc)

 

 

This code..

 

 

http://www.cadtutor.net/forum/showthread.php?533-Lisp-colour-change-for-all-layers-and-blocks&p=669945&viewfull=1#post669945

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...