sunil_b_v Posted May 7, 2012 Posted May 7, 2012 I would like to let you all know what i want to do is. I have a drawing file with almost 200 layers. I need to rename these layers in a manner that a numbering system gets applied to my list of layers. Numbering can be prefixed with the current layer name. The example is shown below that i require to be done. Current Layer name New layer name abc 01 abc def 02 def ghi 03 ghi jkl 04 jkl mno 05 mno pqr 06 pqr stu 07 stu vwx 08 vwx yz 09 yz Can anybody help me with my requirement. It would be lot helpful. Any medium i.e. VBA, LISP, etc.to get this job done would appreciate . Sunil Quote
pBe Posted May 7, 2012 Posted May 7, 2012 (setq cnt 0) (while (setq a (tblnext "LAYER" (null a))) (if (not (member (setq lyn (cdr (assoc 2 a))) '("DEFPOINTS" "0"))) (progn (setq Layer (entget (tblobjname "LAYER" lyn))) (entmod (subst (cons 2 (strcat (itoa (setq cnt (1+ cnt))) "-" lyn)) (assoc 2 Layer) Layer)))) ) Not sure about the prefix , change it here (strcat (itoa (setq cnt (1+ cnt))) [b][color=blue]"-"[/color][/b] lyn) Quote
Tharwat Posted May 7, 2012 Posted May 7, 2012 Maybe this ... (defun c:TesT (/ i n l name e) ;;; Tharwat 07. May. 2012 ;;; (setq i 0 n 1 ) (while (setq l (tblnext "LAYER" (null l))) (setq name (cdr (assoc 2 l))) (setq e (entget (tblobjname "LAYER" name))) (if (not (member name '("Defpoints" "0"))) (if (<= n 9) (progn (entmod (subst (cons 2 (strcat name " " (itoa i) (itoa n) " " name)) (assoc 2 e) e ) ) (setq n (1+ n)) ) (progn (entmod (subst (cons 2 (strcat name " " (itoa n) " " name)) (assoc 2 e) e ) ) (setq n (1+ n)) ) ) ) ) (princ) ) Quote
pBe Posted May 7, 2012 Posted May 7, 2012 (edited) (defun c:PreLayer (/ cnt a layer str lyn) (setq cnt 0) (while (setq a (tblnext "LAYER" (null a))) (if [b][color=blue](and [/color][/b](not (member (setq lyn (cdr (assoc 2 a))) '("DEFPOINTS" "0"))) [b][color=blue](not (wcmatch(substr lyn 1 1) "#"))) [/color][/b] (progn (setq Layer (entget (tblobjname "LAYER" lyn))) (setq str (itoa (setq cnt (1+ cnt)))) (entmod (subst (cons 2 (strcat (strcat (nth (strlen str) [color=blue] '(nil "00" "0" "")) [/color] str) " " lyn)) (assoc 2 Layer) Layer)))) ) (princ) ) "G-ANNO-TEXT" --> "001 G-ANNO-TEXT" "G-ANNO-TTLB" --> "002 G-ANNO-TTLB" Again. i'm not sure . the new layer name is not clearly describe by the OP What are the basis for what prefix goes to what layer name? Tharwat. Check the way i add "0" on the number prefix EDIT: double "00" prefix for single digit number Edited May 8, 2012 by pBe Quote
Tharwat Posted May 7, 2012 Posted May 7, 2012 [color=blue][b](strcat[/b][/color][color=blue][b] (nth (strlen str)[/b][/color][color=blue][b] '(nil "0" ""))[/b][/color][color=blue][b] str)[/b][/color] Very clever way I like it . Thank you Quote
sunil_b_v Posted May 8, 2012 Author Posted May 8, 2012 PBE Oh brother, You know you are a genuis, Your code works perfectly brother. Can you modify the code such that i can add 3 numbers as text in prefix. Result required 001 abc 002 def 003 ghi Thanks in advance. Quote
pBe Posted May 8, 2012 Posted May 8, 2012 You sure you want space rather than hypen for the Layer name? 001 BANANA 001-BANANA See UPDATED CODE Quote
sunil_b_v Posted May 8, 2012 Author Posted May 8, 2012 Got it Sir. I am done. Thanks a tonne. Is there any possibility to apply a criteria on basis of which the layers are prefixed one by one? Sunil. Quote
pBe Posted May 8, 2012 Posted May 8, 2012 Got it Sir. I am done. Thanks a tonne. Good for you. Is there any possibility to apply a criteria on basis of which the layers are prefixed one by one? Sunil. Yes, its possible. 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.