Message 1 of 2
Layer renaming
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All
Below is some code that I got from this discussion group a while ago and it works 99% for me.
What it does is changes the case of your Layer names and I am specifically Changing from upper case to Title Case
But it also changes the prefix of Xrefs on me which I want to remain upper case
eg. the layer I start with is: 1000XGA3|STAMP-10
When I run the routine: 1000xga3|stamp-10
What I want is: 1000XGA3|Stamp-10
Any help greatly appreciated, have no idea where to start
Cheers
Grim
(defun c:layTcase ( / wcase)
(initget 1 "Upper Lower Opposite Sentence Title")
(setq wcase (getkword "\n Change layer names to Upper/Lower/Opposite/Sentence/Title:"))
(layTcase wcase F)
(princ)
)
;; wcase - expects a STRING
;; stealth - T/F, if T will not exit quietly
;; note, can be used transparently
(defun layTcase (wcase stealth / layname lastchar newlayname layelist)
(tblnext "layer" t)
(while (setq layname (tblnext "layer"))
(setq layname (cdr (assoc 2 layname))
layelist (entget (tblobjname "LAYER" layname))
lastchar " "
chrcnt 1
newlayname ""
)
(setq newlayname (change_case layname (read wcase))) ;use (read wcase) to convert to symbol
(entmod (subst (cons 2 newlayname) (cons 2 layname) layelist) )
)
(if (not stealth) (princ (strcat "\nAll Layer names have been converted to " wcase " case.")) )
(princ)
)
;; txt - string to convert
;; case - expects a SYMBOL if using stand alone try (change_case "sample string" 'upper)
(defun change_case (txt case / txt1)
(setq txt1 (cond
((= case 'UPPER) (strcase txt))
((= case 'LOWER) (strcase txt 1))
((= case 'SENTENCE)
(strcat (strcase (substr txt 1 1))
(strcase (substr txt 2) 1)
)
)
((or (= case 'OPPOSITE) (= case 'TITLE))
(setq txt1 "" nw nil n 1)
(repeat (strlen txt)
(setq l (substr txt n 1)
l1 (strcase l
(if (= case 'TITLE)
(if (and (> n 1) (not nw)) 1)
(if (< 64 (ascii l) 91) 1)
)
)
)
(setq txt1 (strcat txt1 l1) n (1+ n)
nw (if (and (= case 'TITLE) (= l " ")) 1)
)
)
(eval txt1)
)
)
)
);end defun change_case
(princ)
Below is some code that I got from this discussion group a while ago and it works 99% for me.
What it does is changes the case of your Layer names and I am specifically Changing from upper case to Title Case
But it also changes the prefix of Xrefs on me which I want to remain upper case
eg. the layer I start with is: 1000XGA3|STAMP-10
When I run the routine: 1000xga3|stamp-10
What I want is: 1000XGA3|Stamp-10
Any help greatly appreciated, have no idea where to start
Cheers
Grim
(defun c:layTcase ( / wcase)
(initget 1 "Upper Lower Opposite Sentence Title")
(setq wcase (getkword "\n Change layer names to Upper/Lower/Opposite/Sentence/Title:"))
(layTcase wcase F)
(princ)
)
;; wcase - expects a STRING
;; stealth - T/F, if T will not exit quietly
;; note, can be used transparently
(defun layTcase (wcase stealth / layname lastchar newlayname layelist)
(tblnext "layer" t)
(while (setq layname (tblnext "layer"))
(setq layname (cdr (assoc 2 layname))
layelist (entget (tblobjname "LAYER" layname))
lastchar " "
chrcnt 1
newlayname ""
)
(setq newlayname (change_case layname (read wcase))) ;use (read wcase) to convert to symbol
(entmod (subst (cons 2 newlayname) (cons 2 layname) layelist) )
)
(if (not stealth) (princ (strcat "\nAll Layer names have been converted to " wcase " case.")) )
(princ)
)
;; txt - string to convert
;; case - expects a SYMBOL if using stand alone try (change_case "sample string" 'upper)
(defun change_case (txt case / txt1)
(setq txt1 (cond
((= case 'UPPER) (strcase txt))
((= case 'LOWER) (strcase txt 1))
((= case 'SENTENCE)
(strcat (strcase (substr txt 1 1))
(strcase (substr txt 2) 1)
)
)
((or (= case 'OPPOSITE) (= case 'TITLE))
(setq txt1 "" nw nil n 1)
(repeat (strlen txt)
(setq l (substr txt n 1)
l1 (strcase l
(if (= case 'TITLE)
(if (and (> n 1) (not nw)) 1)
(if (< 64 (ascii l) 91) 1)
)
)
)
(setq txt1 (strcat txt1 l1) n (1+ n)
nw (if (and (= case 'TITLE) (= l " ")) 1)
)
)
(eval txt1)
)
)
)
);end defun change_case
(princ)