3dwannab Posted September 21, 2022 Posted September 21, 2022 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? Quote
mhupp Posted September 21, 2022 Posted September 21, 2022 ;;----------------------------------------------------------------------;; ;; 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) ) Quote
Tharwat Posted September 21, 2022 Posted September 21, 2022 2 hours ago, 3dwannab said: I have layers like so: AN_text AN_level-proposed WS_foundation WS_wall These are layer names or descriptions strings ? Quote
tombu Posted September 21, 2022 Posted September 21, 2022 Take a look at this thread adding layer descriptions while making layers in lisp if you're wanting to change the layer descriptions not the layer names. I'd leave the NCS layer names alone. Quote
3dwannab Posted September 21, 2022 Author Posted September 21, 2022 (edited) @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 September 21, 2022 by 3dwannab Quote
Tharwat Posted September 21, 2022 Posted September 21, 2022 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) 2 1 Quote
3dwannab Posted September 21, 2022 Author Posted September 21, 2022 (edited) 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 September 21, 2022 by 3dwannab Quote
Tharwat Posted September 21, 2022 Posted September 21, 2022 (edited) 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 September 21, 2022 by Tharwat typo 1 1 Quote
3dwannab Posted September 21, 2022 Author Posted September 21, 2022 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. Quote
Tharwat Posted September 21, 2022 Posted September 21, 2022 2 minutes ago, 3dwannab said: Thanks for that. That is just a minor tweak to what I had asked as some descriptions had already been set. Its okay, no worries. Quote
Steven P Posted September 21, 2022 Posted September 21, 2022 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) ) Quote
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.