Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to change layer name

17 REPLIES 17
Reply
Message 1 of 18
BeKirra
865 Views, 17 Replies

How to change layer name

How to change a layer name? for example, change an existing layer's name from "Text" to "Message".

Thanks in advance.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
17 REPLIES 17
Message 2 of 18
3wood
in reply to: BeKirra

Use command RENAME

Message 3 of 18
BeKirra
in reply to: 3wood

Sorry, I meaned that using DXF method. for example, it allows users to modify the linetype, color while changing the layer name.

Thanks.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
Message 4 of 18
_Tharwat
in reply to: BeKirra

Try this .

 

(if (and (setq e (entget (tblobjname "LAYER" "Text")))
         (not (tblsearch "LAYER" "Message"))
    )
  (entmod (subst '(2 . "Message") (assoc 2 e) e))
)

 

Message 5 of 18
BeKirra
in reply to: _Tharwat

Thanks a lot. It works.

What is the best way to change a layer name, for example from "TEXT" to "Text"?

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
Message 6 of 18
_Tharwat
in reply to: BeKirra


@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))
)

 

Message 7 of 18
BeKirra
in reply to: _Tharwat

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?

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
Message 8 of 18
_Tharwat
in reply to: BeKirra


@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 .

Message 9 of 18
BeKirra
in reply to: _Tharwat

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".

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
Message 10 of 18
_Tharwat
in reply to: BeKirra


@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)
)

 

Message 11 of 18
BeKirra
in reply to: _Tharwat

(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.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
Message 12 of 18
_Tharwat
in reply to: BeKirra


@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))

 

Message 13 of 18
BeKirra
in reply to: _Tharwat

(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?

 

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
Message 14 of 18
_Tharwat
in reply to: BeKirra

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 .

Message 15 of 18
BeKirra
in reply to: _Tharwat

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.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
Message 16 of 18
_Tharwat
in reply to: BeKirra


@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)
)

 

Message 17 of 18
BeKirra
in reply to: _Tharwat

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... Smiley Sad

But thanks so much for your time and helps anyway. Cheers.

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
Message 18 of 18
pbejse
in reply to: BeKirra



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?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost