monk Posted July 19, 2014 Share Posted July 19, 2014 Is there a cleaner / quicker way of achieving this; (defun JHSETCOL1 ( / ) (if (not JHCOL1) (setq JHCOL1 "7") ) (command "-layer" "C" JHCOL1 "*inv*" "") (command "-layer" "C" JHCOL1 "*dim*" "") (command "-layer" "C" JHCOL1 "*alias*" "") (princ) ) Essentially I want to change the colour of a selection of layers using wildcards. I have a DCL box which you enter the colour "JHCOL1" More interested in the layer selection side of lisp using wildcards... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 19, 2014 Share Posted July 19, 2014 You can match multiple wildcard patterns by separating the patterns using commas, e.g.: (defun jhsetcol1 ( col ) (if (null col) (setq col 7)) (command "_.-layer" "_c" col "*inv*,*dim*,*alias*" "") (princ) ) (jhsetcol1 3) Alternatively, using Vanilla AutoLISP without using the -LAYER command: (defun jhsetcol2 ( col / def dxf enx lay ) (if (null col) (setq col 7)) (while (setq lay (tblnext "layer" (null lay))) (if (wcmatch (setq lay (cdr (assoc 2 lay))) "*inv*,*dim*,*alias*") (progn (setq enx (entget (tblobjname "layer" lay)) dxf (assoc 62 enx) ) (entmod (subst (cons 62 (if (minusp (cdr dxf)) (- col) col)) dxf enx)) ) ) ) (princ) ) (jhsetcol2 3) Or, using Visual LISP: (defun jhsetcol3 ( col ) (if (null col) (setq col 7)) (vlax-for lay (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (wcmatch (vla-get-name lay) "*inv*,*dim*,*alias*") (vla-put-color lay col) ) ) (princ) ) (vl-load-com) (princ) (jhsetcol3 3) Note that the use of wcmatch in the above examples is case-sensitive. Quote Link to comment Share on other sites More sharing options...
monk Posted July 19, 2014 Author Share Posted July 19, 2014 Wow, Lee that's about as in depth as you could want! Perfect! I think I vastly need to expand my code knowledge base! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 19, 2014 Share Posted July 19, 2014 You're welcome monk! - Ask if you have any questions about the code Quote Link to comment Share on other sites More sharing options...
monk Posted July 19, 2014 Author Share Posted July 19, 2014 I haven't digested it yet, going to have a look soon! I'll have to buy you a beer! Quote Link to comment Share on other sites More sharing options...
monk Posted July 20, 2014 Author Share Posted July 20, 2014 Tried your Visual lisp method, I now need to learn Visual lisp! Looks good! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 21, 2014 Share Posted July 21, 2014 Tried your Visual lisp method, I now need to learn Visual lisp! Looks good! The Visual LISP route may be more concise, but the Vanilla AutoLISP method will be faster - I would also suggest modifying the example VL code I've posted above to accept the VLA Document Object as an argument so that this object and the Application object needn't be repeatedly retrieved for multiple calls of the function. Quote Link to comment Share on other sites More sharing options...
monk Posted July 21, 2014 Author Share Posted July 21, 2014 I would also suggest modifying the example VL code I've posted above to accept the VLA Document Object as an argument so that this object and the Application object needn't be repeatedly retrieved for multiple calls of the function. After you replied at the weekend, I started looking up VL on afralisp, it started to make sense but I need to delve deeper when I have time away from my day job! 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.