View Full Version : Adding Suffix to All Layers
ReachAndre
2007-03-05, 08:46 PM
Hello all,
I am trying to write a LSP that will add a sufix to all my layer names. (Obviously not 0)
For this post lets use the one I am currently working on. I Am trying to add "-EXST" does anyone have any ideas on how to begin this lisp?
Thank you all in advance,
Andre
Hello all,
I am trying to write a LSP that will add a sufix to all my layer names. (Obviously not 0)
For this post lets use the one I am currently working on. I Am trying to add "-EXST" does anyone have any ideas on how to begin this lisp?
Thank you all in advance,
Andre
Maybe this for a start:
(defun c:layers-exst ( / layers_col nam)
(vl-load-com)
(or *acaddoc* (setq *acaddoc* (vla-get-activedocument (vlax-get-acad-object))))
(setq layers_col (vla-get-layers *acaddoc*))
(vlax-for item layers_col
(setq nam (vlax-get-property item 'Name))
(if (and (/= nam "0")(/= nam "Defpoints"))
(vlax-put-property item 'Name (strcat nam "-EXST"))
)
)
(princ)
)
Hello all,
I am trying to write a LSP that will add a sufix to all my layer names. (Obviously not 0)
For this post lets use the one I am currently working on. I Am trying to add "-EXST" does anyone have any ideas on how to begin this lisp?
Thank you all in advance,
AndreI know this isn't a lisp routine, but did you consider the "rename" command with wild-cards?
Use the rename command and select layers,
in the old name box you would put A-* (or what ever your common layer situation is)
In the Rename to box you would put A-*-EXST and hit ok. It will rename all of them instantly!
Not a lisp but it works great.
ReachAndre
2007-03-06, 02:52 PM
Tim,
Thanks a bunch, I think I owe you something, you've been very hellpful on several of my posts.
What I am trying to do now is to add the option to work on certain layers,
Below is what I have but it doesnt seem to work.
I am unfamiliar so far with VL commands, nut I do want to learn
(defun c:layers-exst ( / layers_col nam)
(vl-load-com)
(or *acaddoc* (setq *acaddoc* (vla-get-activedocument (vlax-get-acad-object))))
(setq layers_col (vla-get-layers *acaddoc*))
(vlax-for item layers_col
(setq nam (vlax-get-property item 'Name))
(if (and (/= nam "0")(/= nam "Defpoints")(= (strcat discipline "-*")))
(vlax-put-property item 'Name (strcat nam "-EXST"))
)
)
(princ)
)(defun c:lsuf (/ odiscipline)
(if (not discipline) (setq discipline "M"))
(setq odiscipline discipline)
(if
(=
(setq discipline
(getstring (strcat"What discipline are you working in? (Mechanical,Plumbing,Fireprotection, or Electrical <" odiscipline ">: "))
)
"")
(setq discipline odiscipline)
)
(c:layers-exst)
(princ)
)Thanks again all,
Andre
[ Moderator Action = ON ] What are [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]
Tim,
Thanks a bunch, I think I owe you something, you've been very hellpful on several of my posts.
What I am trying to do now is to add the option to work on certain layers,
Below is what I have but it doesnt seem to work.
No problem Andre.
First, have a look at this:
(defun c:test (/ dis) ;dis is local
(or *dis* (setq *dis* "Mechanical")) ;leave *dis* global
(initget "Mechanical,M Plumbing,P Fireprotection,F Electrical,E");initget the keywords
(setq dis (getkword
(strcat
"\nWhat discipline are you working in? <M>ech.,<P>lumbing,<F>irePro or <E>lect:"
"<" *dis* ">"
);strcat
);getkword
);setq
(if (not dis)(setq dis *dis*)(setq *dis* dis))
);defun
and digest it a little bit. I'll help more when I have time later.
Hi Andre,
Give this a try:
(defun c:test (/ dis ans) ;dis is local - no, i'm not dis'n you :)
(or *dis* (setq *dis* "Mechanical")) ;leave *dis* global
(initget "Mechanical,M Plumbing,P FireProtection,F Electrical,E");initget the keywords
(setq ans (getkword
(strcat
"\nWhat discipline are you working in? <M>ech.,<P>lumbing,<F>irePro or <E>lect:"
"<" *dis* ">"
);strcat
);getkword
);setq
(cond ((= ans "Mechanical")(setq dis "Mech")(setq *dis* "Mechanical"))
((= ans "Plumbing")(setq dis "Plum")(setq *dis* "Plumbing"))
((= ans "FireProtection")(setq dis "Fire")(setq *dis* "FireProtection"))
((= ans "Electrical")(setq dis "Elec")(setq *dis* "Electrical"))
(T (cond ((= *dis* "Mechanical")(setq dis "Mech"))
((= *dis* "Plumbing")(setq dis "Plum"))
((= *dis* "FireProtection")(setq dis "Fire"))
((= *dis* "Electrical")(setq dis "Elec"))
)
)
)
(layers-exst dis)
(princ (strcat *dis* "layers renamed"))
(princ)
);defun
(defun layers-exst (dis_match / layers_col nam)
(vl-load-com)
(or *acaddoc* (setq *acaddoc* (vla-get-activedocument (vlax-get-acad-object))))
;get the acad document
(setq layers_col (vla-get-layers *acaddoc*))
;get the layers collection from the acad document
(vlax-for item layers_col;walk through the layers collection
(if
(and
(wcmatch (strcase (vlax-get-property item 'Name))(strcase (strcat dis_match "*")))
;if the characters match
(not (wcmatch (strcase (vlax-get-property item 'Name)) "*-EXST"))
;and hasn't already been changed (cheers Chris)
)
(vlax-put-property item 'Name (strcat (vlax-get-property item 'Name) "-EXST"))
;rename the layer
)
)
(princ)
)
With slight modifications, c:layers-exst becomes layers-exst, a function that will process the layers based on the argument dis_match. dis_match needs to be a string that reflects the first letters that are common with the discipline depending on your layer naming scheme. In this example, I used Mech, Plum, Fire and Elec, thinking that your layer scheme may look something like:
Mech-Ductwork
Mech-Annotation
Plum-Fittings
Elec-Conduit
Etc.
Etc.
Change the values in the cond section (in red) to reflect your actual situation. Don't worry about the stuff in the prompt, and you can even spell out the disciplines, like changing FirePro to Fire Protection - I just ran out of room in the post editor.
Let us know if you need more help.
gab.83408
2007-03-08, 03:31 PM
Sorry I will post this somewhere else
Sorry I will post this somewhere else
Where'd you go, gab? :?: I don't see another post.
Adesu
2007-03-09, 02:20 AM
Hello all,
I am trying to write a LSP that will add a sufix to all my layer names. (Obviously not 0)
For this post lets use the one I am currently working on. I Am trying to add "-EXST" does anyone have any ideas on how to begin this lisp?
Thank you all in advance,
Andre
Hi Andre,
How about this code
(defun table (s / d r) ; Michael Puckett
(while
(setq d (tblnext s (null d)))
(setq r (cons (cdr (assoc 2 d)) r))
)
)
(defun c:test (/ add leng lst)
(setq add "-EXST")
(setq lst (cdr (reverse (table "layer"))))
(if (= lst nil)(alert "\nThis layer only 0 layer"))
(setq leng (length lst))
(if
(> leng 1)
(progn
(foreach x lst
(command "_rename" "layer" x (strcat add x))
) ; foreach
) ; progn
(progn
(alert (strcat "\nThis layer only " (car lst) " layer"))
) ; progn
) ; if
(princ)
) ; defun
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.