hildevasco_br Posted 9 hours ago Posted 9 hours ago Hello I created these functions, but neither of them can change the layer names to uppercase or lowercase. The strange thing is that this routine has been used for a long time. FlagCaixa= 0 (abcde.....) FlagCaixa= 1 (ABCDE.....) ;sample 01 (defun AlteraCaixaNomesLayers ( FlagCaixa / CollLayDwg ObjVlaLay TxtNomLay LstLayDwgNew ) (setq CollLayDwg (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))) (vlax-for ObjVlaLay CollLayDwg (setq TxtNomLay (vla-get-name ObjVlaLay)) (if (and (/= TxtNomLay "0") (/= TxtNomLay "Defpoints")) (progn (if (= FlagCaixa 0) (progn (vla-put-name ObjVlaLay (strcase TxtNomLay)) ) (progn (vla-put-name ObjVlaLay (strcase TxtNomLay T)) ) ) ) ) ) ) ;sample 02 (defun AlteraCaixaNomesLayers ( FlagCaixa / TxtNomLay LstLayDwgNew NomObjLayDwg LstNomObjLayDwg ) (setq LstNomLayersDwg (GeraListaNomeLayersDoDesenho)) (foreach TxtNomLay LstNomLayersDwg (if (= FlagCaixa 0) (progn (vl-cmdf "rename" "la" TxtNomLay (strcase TxtNomLay)) ) (progn (vl-cmdf "rename" "la" TxtNomLay (strcase TxtNomLay T)) ) ) ) (vl-cmdf "regen") ) (defun GeraListaNomeLayersDoDesenho ( / for-item LstNomeLayers Layer_name ) (vlax-for for-item (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (if (and (vlax-property-available-p for-item 'Name) (/= (vla-get-Name for-item) "0") (vlax-property-available-p for-item 'Freeze) (= (vla-get-freeze for-item) :vlax-false) (vlax-property-available-p for-item 'LayerOn) (= (vla-get-layerOn for-item) :vlax-true) (vlax-property-available-p for-item 'Lock) (= (vla-get-lock for-item) :vlax-false) (not (member (setq Layer_name (vla-get-Name for-item)) LstNomeLayers)) ) (progn (setq LstNomeLayers (cons Layer_name LstNomeLayers)) ) ) ) (vl-sort LstNomeLayers '<) ) Thank you if anyone can help me. Quote
BIGAL Posted 4 hours ago Posted 4 hours ago I think that the only way to do reliably is to look at every character in the string, so A-Z = 65-90 and a-z =97-122 so using (chr x) can rebuild string. ; https://www.cadtutor.net/forum/topic/98847-problem-renaming-layers/ ; Convert layers to upper or lower case-insensitive ; By AlanH Nov 2025 (defun AlteraCaixaNomesLayers ( FlagCaixa / CollLayDwg ObjVlaLay TxtNomLay char nchar str) (setq CollLayDwg (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))) (vlax-for ObjVlaLay CollLayDwg (setq TxtNomLay (vla-get-name ObjVlaLay)) (if (or (= TxtNomLay "0") (= TxtNomLay "Defpoints")) (princ) (progn (if (= FlagCaixa 1) (vla-put-name ObjVlaLay (strcase TxtNomLay)) (progn (setq x 1) (setq str "") (repeat (strlen TxtNomLay) (setq char (ascii (substr txtnomlay x 1))) (cond ((and (> char 64)(< char 91)) (progn (setq nchar (chr (+ char 32))) (setq str (strcat str nchar)) ) ) ((or (< char 65)(> char 90)) (progn (setq nchar (chr char)) (setq str (strcat str nchar)) ) ) ) (setq x (1+ x)) ) (vla-put-name ObjVlaLay str) ) ) ) ) ) (princ) ) (AlteraCaixaNomesLayers 0) Quote
mhupp Posted 31 minutes ago Posted 31 minutes ago Use code tags when posing. The stuff you posted works for me have you upgraded recently? are the layers locked from an xref? maybe (vl-load-com) hasn't been called yet and you seeing any errors when the code runs? Or might just be a typo in your function name? (AlteraCaixaNomesLayers 0) FlagCaixa= 0 (abcde.....) FlagCaixa= anything else (ABCDE.....) renamed to use an a so its "Names" (defun AlteraCaixaNamesLayers (FlagCaixa / doc layers lay old new) (vl-load-com) (setq layers (vla-get-Layers (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))))) (vla-startundomark doc) (vlax-for lay layers (setq old (vla-get-Name lay)) (if (not (member old '("0" "DEFPOINTS"))) (progn (if (= FlagCaixa 0) ;dont need progn if you only have two lines of code. (vla-put-name lay (strcase old)) ;if true run this line (vla-put-name lay (strcase old T)) ;if false run this line ) ) ) ) (vla-EndUndoMark doc) (princ) ) if you only want 0 or 1 as the only two options use cond. also allows you to have more options in the future if you want. (defun AlteraCaixaNamesLayers (FlagCaixa / doc layers lay old new) (vl-load-com) (setq layers (vla-get-Layers (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))))) (vla-startundomark doc) (vlax-for lay layers (setq old (vla-get-Name lay)) (if (not (member old '("0" "DEFPOINTS"))) (cond ((= FlagCaixa 0) (vla-put-name lay (strcase old))) ((= FlagCaixa 1) (vla-put-name lay (strcase old T))) ) ) ) (vla-EndUndoMark doc) (princ) ) nice tutorial on cond here also cond's don't need (progn if they have multiple lines of code. 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.