How to change a layer name? for example, change an existing layer's name from "Text" to "Message".
Thanks in advance.
Sorry, I meaned that using DXF method. for example, it allows users to modify the linetype, color while changing the layer name.
Thanks.
Try this .
(if (and (setq e (entget (tblobjname "LAYER" "Text"))) (not (tblsearch "LAYER" "Message")) ) (entmod (subst '(2 . "Message") (assoc 2 e) e)) )
Thanks a lot. It works.
What is the best way to change a layer name, for example from "TEXT" to "Text"?
@BeKirra wrote:Thanks a lot. It works.
What is the best way to change a layer name, for example from "TEXT" to "Text"?
The same but you need to remove the table search function because it is not case-sensitive in this case .
eg.
(if (setq e (entget (tblobjname "LAYER" "TEXT"))) (entmod (subst '(2 . "Text") (assoc 2 e) e)) )
Thanks for your help again.
Is it possible to make the table search function case-sensitive so if no layer name found as "TEXT" the routine will do nothing?
@BeKirra wrote:Thanks for your help again.
Is it possible to make the table search function case-sensitive so if no layer name found as "TEXT" the routine will do nothing?
You can do that without the use of the tblsearch function via collecting all layer names and check each name separately if it is matchs any name you would like .
You can do that without the use of the tblsearch function via collecting all layer names and check each name separately if it is matchs any name you would like .
Thanks. How to make it works by "collecting all layer names".
@BeKirra wrote:
Thanks. How to make it works by "collecting all layer names".
Try .
(defun _table:layers (/ l nm lst) (while (setq l (tblnext "LAYER" (not l))) (if (not (wcmatch (setq nm (cdr (assoc 2 l))) "*|*")) (setq lst (cons nm lst)) ) ) (reverse lst) )
(defun _table:layers (/ l nm lst) (while (setq l (tblnext "LAYER" (not l))) (if (not (wcmatch (setq nm (cdr (assoc 2 l))) "*|*")) (setq lst (cons nm lst)) ) ) (reverse lst) )
Thanks again. From your code it returns a list of layer names.
How do I get the layer name (e.g. "Text") from the list?
Sorry I do not know much about list and dxf functions.
@BeKirra wrote:
Thanks again. From your code it returns a list of layer names.How do I get the layer name (e.g. "Text") from the list?
Sorry I do not know much about list and dxf functions.
One way.
(member "Text" (_table:layers))
Another .
(vl-some '(lambda (x) (eq "Text" x)) (_table:layers))
(member "Text" (_table:layers)) (vl-some '(lambda (x) (eq "Text" x)) (_table:layers))
Thanks. Now I noticed that both of 2 codes above are case sensitive.
Here is another question. Based on your posts earlier, I am going to modify my another code. I want to change a layer name but it does not work. Here is my code:
(if (setq GetLayerName (cdr (assoc 2 (entget (tblobjname "LAYER" "Existing Machine"))))) (progn (setq ChangeLayerName (strcat "\"" "Removed Machine" "\"")) (entmod (subst '(2 . ChangeLayerName) (assoc 2 GetLayerName) GetLayerName)) ) )
What is wrong?
First the variable GetLayerName represent layer name and not the dxf list .
Second the layer name must not have any kind of symbols , so it would fail .
What I'm now trying to achieve is the following:
1) manually enter a new layer name (e.g. Removed Machine), perheps use "getstring".
2) then replace the an existing layer name. e.g. "Existing Machine".
How to make it to work? Thanks.
@BeKirra wrote:What I'm now trying to achieve is the following:
1) manually enter a new layer name (e.g. Removed Machine), perheps use "getstring".
2) then replace the an existing layer name. e.g. "Existing Machine".
How to make it to work? Thanks.
If you are trying to change the same layer name but with Capital or Small letters , this should NOT work but only with COMPLETELY new VALID layer name.
(defun c:test (/ old-layer-name new-layer-name elist) ;; Tharwat 18.09.2014 ;; (if (and (/= (setq old-layer-name (getstring t "\n Specify existed layer name :")) "") (if (not (tblsearch "LAYER" old-layer-name)) (progn (alert (strcat "Layer Name : < " old-layer-name " > is not found !!")) nil) t ) (/= (setq new-layer-name (getstring t "\n Specify New layer name :")) "") (if (or (tblsearch "LAYER" new-layer-name) (not (snvalid new-layer-name))) (progn (alert (strcat "Layer Name : < " new-layer-name " > is already existed or not valid new name !!")) nil ) t ) ) (entmod (subst (cons 2 new-layer-name) (assoc 2 (setq elist (entget (tblobjname "LAYER" old-layer-name)))) elist ) ) ) (princ) )
If you are trying to change the same layer name but with Capital or Small letters , this should NOT work but only with COMPLETELY new VALID layer name.
You give me no hope...
But thanks so much for your time and helps anyway. Cheers.
If you are trying to change the same layer name but with Capital or Small letters ,
Is that all you are wanting to do? or if theres an existing layer name you wanted it to look as you typed on getstring prompt?