Jump to content

LISP to change entity colour by layer name using wildcard?


ctrlaltdel

Recommended Posts

Found a lisp to change entity colour by layer name. But I require for it to work on wildcards for layer names.

 

Example:

 

Change colour for *ANO* layer names to green colour

 

This code works but not for wildcards

(defun c:Test (/ doc)
 (vlax-for block (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
   (vlax-for x block
     (if (eq (vla-get-layer x) "[color=red][b]*ANO*[/b][/color]")
       (vla-put-color x [color=red][b]3[/b][/color])
     )
   )
 )
 (vla-regen doc acActiveViewport)
 (princ)
)
(vl-load-com)

Link to comment
Share on other sites

([color="blue"]wcmatch [/color](vla-get-layer x) "*ANO*")

 

Tharwat sir, I get an error when load the lisp

 

Command: (LOAD "E:lsp/ChangeLayerColour.lsp")

Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).

Converting (command) calls to (command-s) is recommended.

Command: test

nil

 

After running the lisp all entities change colour instead of following wildcard

 

this is the lisp

(defun c:Test (/ doc)
 (vlax-for block (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
   (vlax-for x block
     [b][color="blue"](wcmatch (vla-get-layer x) "*ano*")[/color][/b]
       (vla-put-color x 3)
     )
   )
 )
 (vla-regen doc acActiveViewport)
 (princ)
)
(vl-load-com)

Edited by ctrlaltdel
Link to comment
Share on other sites

You should add 'if' function before the wildcard function as in your first post of this thread.

 

Thanks Tharwat. :P

 

(defun c:Test (/ doc)
 (vlax-for block (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
   (vlax-for x block
     (if (wcmatch (vla-get-layer x) "*ano*")
       (vla-put-color x 3)
     )
   )
 )
 (vla-regen doc acActiveViewport)
 (princ)
)
(vl-load-com)

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...