Jump to content

Change layer description of multiple layers based on layer name


3dwannab

Recommended Posts

I have layers like so:

AN_text
AN_level-proposed
WS_foundation
WS_wall

 

Is it possible to change the description of the AN_* layers to Annotation and the WS_* layers to Wall Structure using LISP?

Link to comment
Share on other sites

;;----------------------------------------------------------------------;;
;; RENAME LAYERS
(defun C:RL (/ layers layer nlay SS )
  (vlax-for layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (setq layer (vla-get-name layers))
    (cond
      ((wcmatch layer "AN_*")                                                       ;process layers that start with AN_
        (if (tblsearch "layer" (setq nlay (strcat "Annotation_" (substr layer 4)))) ;search layer table for Annotation_"layer name"
          (progn                                                                    ;if found move all entitys from old layer to new layer
            (setq SS (ssget "X" (list (cons 8 layer))))
            (command "_Chprop" SS "" "LA" nlay "")
            (command "_Purge" "LA" layer "N")
          )
          (command "_-Rename" "LA" layer nlay)                                      ;if not found just rename old layer to new layer name
        )
        (prompt (strcat "\n" Layer " -> " nlay))                                    ;output to command prompt layer update
      )
      ((wcmatch layer "WS_*")                                                       ;same as above just looking for WS_
        (if (tblsearch "layer" (setq nlay (strcat "Wall Structure_" (substr layer 4))))
          (progn
            (setq SS (ssget "X" (list (cons 8 layer))))
            (command "_Chprop" SS "" "LA" nlay "")
            (command "_Purge" "LA" layer "N")
          )
          (command "_-Rename" "LA" layer nlay)
        )
        (prompt (strcat "\n" Layer " -> " nlay))
      )
    )
  )
  (princ)
)

 

Link to comment
Share on other sites

@mhupp, this is for renaming layers is it not? It's the description of the layer I was wanting to change based on the suffix of the layer name.

 

@Tharwat, these are layer names. The suffix is the main part. Helps break up each section of a building. WS is wall structure, WC is wall completion etc.

 

@tombu, thanks, I'll take a look at this and see.

Edited by 3dwannab
Link to comment
Share on other sites

7 minutes ago, 3dwannab said:

@Tharwat, these are layer names. The suffix is the main part. Helps break up each section of a building. WS is wall structure, WC is wall completion etc.

(defun c:Test ( / lyn)
  (vlax-for obj (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)))
    (or (wcmatch (setq lyn (vla-get-name obj)) "*|*")
        (and (wcmatch lyn "AN_*,WS_*")
             (vla-put-Description obj (if (wcmatch lyn "AN_*") "Annotation" "Wall Structure"))
             )
        )
    )
  (princ)
  ) (vl-load-com)
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Thanks @Tharwat, What is the meaning of the wcmatch with the "*|*" ?

 

Ended up with this which doesn't change any that don't have a description:

(defun c:Test (/ obj layName)
  (vlax-for obj (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)))

    (setq layName (vla-get-name obj))

    (if (wcmatch (vla-get-Description obj) "")

      (progn
        (if (wcmatch layName "AN_*") (vla-put-Description obj (strcat "Annotation Layer - " layName)))
        (if (wcmatch layName "CH_*") (vla-put-Description obj (strcat "Colour Hatch Layer - " layName)))
        (if (wcmatch layName "CL_*") (vla-put-Description obj (strcat "Ceiling Layer - " layName)))
        (if (wcmatch layName "DA_*") (vla-put-Description obj (strcat "Disablity Layer - " layName)))
        (if (wcmatch layName "DR_*") (vla-put-Description obj (strcat "Drainage Layer - " layName)))
        (if (wcmatch layName "EL_*") (vla-put-Description obj (strcat "Elevation Layer - " layName)))
        (if (wcmatch layName "FC_*") (vla-put-Description obj (strcat "Floor Completion Layer - " layName)))
        (if (wcmatch layName "FD_*") (vla-put-Description obj (strcat "Fire Denotation Layer - " layName)))
        (if (wcmatch layName "FS_*") (vla-put-Description obj (strcat "Floor Structure Layer - " layName)))
        (if (wcmatch layName "GN_*") (vla-put-Description obj (strcat "General Layer - " layName)))
        (if (wcmatch layName "RC_*") (vla-put-Description obj (strcat "Roof Completion Layer - " layName)))
        (if (wcmatch layName "RS_*") (vla-put-Description obj (strcat "Roof Structure Layer - " layName)))
        (if (wcmatch layName "SF_*") (vla-put-Description obj (strcat "Structural Frame Layer - " layName)))
        (if (wcmatch layName "ST_*") (vla-put-Description obj (strcat "Site Layer - " layName)))
        (if (wcmatch layName "TS_*") (vla-put-Description obj (strcat "Topographical Survey Layer - " layName)))
        (if (wcmatch layName "VT_*") (vla-put-Description obj (strcat "Vertical Transport Layer - " layName)))
        (if (wcmatch layName "WC_*") (vla-put-Description obj (strcat "Wall Completion Layer - " layName)))
        (if (wcmatch layName "WS_*") (vla-put-Description obj (strcat "Wall Structure Layer - " layName)))
      )
    )

    (princ)
  )
)
(vl-load-com)
(c:Test)

 

 

 

Edited by 3dwannab
Link to comment
Share on other sites

12 minutes ago, 3dwannab said:

Thanks @Tharwat, What is the meaning of the wcmatch with the "*|*" ?

 

That's to pass over external references' layers.

  

12 minutes ago, 3dwannab said:

Ended up with this which doesn't change any that don't have a description:

 

Why are you asking for something and you are doing something else ?

Anyway, just build the list as I did in the following program to make it working professionally.

 

(defun c:Test ( / lst lyn )
  (setq lst '(("AN_" "Annotation Layer - ")
              ("CH_" "Colour Hatch Layer - ")
              )
        )
  (vlax-for obj (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)))
    (or (wcmatch (setq lyn (vla-get-name obj)) "*|*")
        (and (setq fnd (assoc (substr lyn 1 3) lst))
             (vla-put-Description obj (strcat (cadr fnd) lyn))
             )
        )
    )
  (princ)
  ) (vl-load-com)

 

Edited by Tharwat
typo
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

4 minutes ago, Tharwat said:

Why are you asking for something and you are doing something else ?

 

Thanks for that. That is just a minor tweak to what I had asked as some descriptions had already been set.

Link to comment
Share on other sites

Beaten again by the questions and answers, below is taking MHUPPs idea and adding the layers as a list:

 

;;----------------------------------------------------------------------;;
;; RENAME LAYERS
(defun C:RL (/ layers layer nlay SS acount RenameNames)

  (setq RenameNames (list '("AN_" "Annotation_")
                          '( "WS_" "Wall Structure_")
  ))

  (vlax-for layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (setq layer (vla-get-name layers))
    (setq acount 0)
    (while ( < acount (length RenameNames))
      (setq searchterm (strcat (car (nth acount RenameNames)) "*"))
      (if (wcmatch layer searchterm)
        (progn
          (if (tblsearch "layer" (setq nlay (strcat (cdr (nth acount RenameNames)) (substr layer 4) )))
            (progn
              (setq SS (ssget "X" (list (cons 8 layer))))
              (command "_Chprop" SS "" "LA" nlay "")
              (command "_Purge" "LA" layer "N")
            ) ;end progn
            (command "_-Rename" "LA" layer nlay)
          ) ; end if
          (prompt (strcat "\n" Layer " -> " nlay))
          ) ; end progn
        ) ; end if
        (setq acount (+ acount 1))
    ) ; end while
  ) ; end vlax-for
  (princ)
)

 

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