Earlzii Posted January 17, 2017 Share Posted January 17, 2017 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 Quote Link to comment Share on other sites More sharing options...
OMEGA-ThundeR Posted January 17, 2017 Share Posted January 17, 2017 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 . Quote Link to comment Share on other sites More sharing options...
Earlzii Posted January 19, 2017 Author Share Posted January 19, 2017 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. Quote Link to comment Share on other sites More sharing options...
Hippe013 Posted January 19, 2017 Share Posted January 19, 2017 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 ) Quote Link to comment Share on other sites More sharing options...
Earlzii Posted January 20, 2017 Author Share Posted January 20, 2017 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" "") ) Quote Link to comment Share on other sites More sharing options...
David Bethel Posted January 20, 2017 Share Posted January 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
Earlzii Posted January 20, 2017 Author Share Posted January 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
Earlzii Posted January 20, 2017 Author Share Posted January 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
jweber Posted January 21, 2017 Share Posted January 21, 2017 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)) Quote Link to comment Share on other sites More sharing options...
Earlzii Posted January 23, 2017 Author Share Posted January 23, 2017 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. Quote Link to comment Share on other sites More sharing options...
halam Posted January 23, 2017 Share Posted January 23, 2017 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 Quote Link to comment Share on other sites More sharing options...
Earlzii Posted January 23, 2017 Author Share Posted January 23, 2017 Thanks halam that's a good routine I'll look at incorporating them when I get some time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.