Jump to content

Recommended Posts

Posted

Greeting everyone,

 

Below is a layer color changing lisp that I use alot. I was wondering if someone could help me modify it to ignore locked layers. Any help would be greatly appreciated!

 

Thanks

 

(defun c:cdwg ()
    (command "chprop" "all" "" "c" "bylayer"  "")
    (command "-layer" "c" 8 "*" "c" 8 "0" "c" 8 "defpoints" "")
   (progn
      (setq tbl(tblnext "LAYER" T))
      (while (/= tbl nil)
        (setq layName(cdr(assoc 2 tbl)))
        (if(wcmatch layName "*wall*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*WALL*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*Wall*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*door*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*DOOR*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*Door*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*glaz*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*GLAZ*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*Glaz*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*glass*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*GLASS*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*Glass*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*window*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*WINDOW*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "*Window*")
          (command "-layer" "C" 4 layName "")
        )
        (if(wcmatch layName "0")
          (command "-layer" "C" 7 layName "")
        )
   )
   (command "layer" "s" 0 "")
   (command "purge" "a" "*" "n")
   (command "regen")
   (command "zoom" "e")

Posted (edited)

My two cents...

 

(defun c:CDWG (/ oldCmdecho layerTable layerName layerColor)
 (vl-load-com)
 (cond
   (*activeDoc*)
   ((setq *activeDoc* (vla-get-activedocument (vlax-get-acad-object)))))
 (vla-startundomark *activeDoc*)
 (vla-purgeall *activeDoc*)
 (if (/= 0 (setq oldCmdecho (getvar 'cmdecho)))
   (setvar 'cmdecho 0))
 (vl-cmdf "._chprop" "all" "" "color" "bylayer" "")
 (if (setq layerTable (vla-get-layers *activeDoc*))
   (vlax-for x  layerTable
 (if (and (setq layerName (strcase (vla-get-name x)))
          (= :vlax-false (vla-get-lock x)))
   (progn
     (cond
       ((vl-position
           layerName
           (list "*DOOR*" "*GLASS*" "*GLAZ*" "*WALL*" "*WINDOW*"))
        (setq layerColor 4))
       ((= "0" layerName) (setq layerColor 7))
       (T (setq layerColor ))
     (vla-put-color x layerColor)))))
 (vla-zoomextents (vla-get-application *activeDoc*))
 (setvar 'cmdecho oldCmdecho)
 (terpri)
 (prompt "\nLayer Settings Complete. ")
 (terpri)
 (vla-endundomark *activeDoc*)
 (princ)) ;_end defun

Edited by BlackBox
Posted

thanks Render.....it semi works. It changes everything to color 8 except for the locked layers, but it doesn't changes the list items to color 4. any suggestions?

Posted
thanks Render.....it semi works. It changes everything to color 8 except for the locked layers, but it doesn't changes the list items to color 4. any suggestions?

 

My mistake :oops: , let's try this revision:

 

(defun c:CDWG (/ oldCmdecho layerTable layerName layerColor)
 (vl-load-com)
 (cond
   (*activeDoc*)
   ((setq *activeDoc* (vla-get-activedocument (vlax-get-acad-object)))))
 (vla-startundomark *activeDoc*)
 (vla-purgeall *activeDoc*)
 (if (/= 0 (setq oldCmdecho (getvar 'cmdecho)))
   (setvar 'cmdecho 0))
 (vl-cmdf "._chprop" "all" "" "color" "bylayer" "")
 (if (setq layerTable (vla-get-layers *activeDoc*))
   (vlax-for x  layerTable
 (if (and (setq layerName (strcase (vla-get-name x)))
          (= :vlax-false (vla-get-lock x)))
   (progn
     (cond
       ([color=blue]([color=red]wcmatch[/color] layerName "*DOOR*,*GLASS*,*GLAZ*,*WALL*,*WINDOW*")[/color]
        (setq layerColor 4))
       ((= "0" layerName) (setq layerColor 7))
       (T (setq layerColor ))
     (vla-put-color x layerColor)))))
 (vla-zoomextents (vla-get-application *activeDoc*))
 (setvar 'cmdecho oldCmdecho)
 (terpri)
 (prompt "\nLayer Settings Complete. ")
 (terpri)
 (vla-endundomark *activeDoc*)
 (princ)) ;_end defun

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