Rename Button Macro

Rename Button Macro

PedroMSilva22
Participant Participant
954 Views
10 Replies
Message 1 of 11

Rename Button Macro

PedroMSilva22
Participant
Participant

Hi Guys,

I’m working on a macro, simple Rename a name of a Layer.

EX:

NX91NE$0$L_101_TEXT and Rename to Z-Zz_20_10_90-M_Land.Text

The difficulty I’m having is I just want to put on the macro part of the name to be change. I’m working with coordinates and the first part of the name is the coordinate.

Instead of putting all name of the layer:

NX91NE$0$L_101_TEXT

Just put part of the layer name :

 L_101_TEXT (C^C_-rename;LA;L_101_TEXT;Z-Zz_20_10_90-M_Land.Text;^C^C)

Is there a way to only put on a macro part of the name to be change?

Any help would be greatly appreciated.

0 Likes
Accepted solutions (2)
955 Views
10 Replies
Replies (10)
Message 2 of 11

Kent1Cooper
Consultant
Consultant

Not, it seems in a RENAME command in a command macro.  The RENAME dialog box would let you do that with a * wildcard:

Kent1Cooper_0-1669210525734.png

which results in the Layer name that matches [BC between anything else] being changed:

Kent1Cooper_1-1669210611011.png

BUT unfortunately, the command-line version of RENAME such as would be used in a command macro won't accept the wildcard.

 

It could be done easily enough with an AutoLisp routine, if you are not using LT.

 

Kent Cooper, AIA
Message 3 of 11

PedroMSilva22
Participant
Participant

Hi Ken, thank you for the help,

The thing is : 

I had to divide the macro command in 2:

 

1-First part:

  • ^C^C_xref;bind;*;^C^C_Purge;a;*;N;;;^C^C-layer _E;*;;^C^C_xplode;_all;;^C^C_xplode;_all;;;^C^C_'_zoom _e;

2-Second part:

  • ^C^C_-LAYMRG;N;L_105_WATER_P;;N;L_104_WATER;Y;;^C^C_-rename;LA;L_103_TOPO;Z-En_32_10_40-M_Land;^C^C_-rename;LA;L_102_BUILDING;Z-En_32_10_39-M_Buildings;^C^C_-rename;LA;L_101_TEXT;Z-Zz_20_10_90-M_Land.Text;^C^C_-rename;LA;L_104_WATER;Z-Co_32_65_72-M_Rivers;^C^C-layer;_color 253;Z-En_32_10_40-M_Land;^C^C-layer;_color 6;Z-En_32_10_39-M_Buildings;^C^C-layer;_color 9;Z-Zz_20_10_90-M_Land.Text;^C^C-layer;_color 140;Z-Co_32_65_72-M_Rivers;;^C^C_SETBYLAYER;all;;Yes;Yes;^C^C_copybase;0,0,0;_all;;^C^C_erase;all;;^C^C_pasteblock;0,0,0;;^C^C_-layer;n;Z-Zz_30_30-M_CadExternalReferences;;^C^C_-layer;_color 253;Z-Zz_30_30-M_CadExternalReferences;^C^C_chprop;_all;;_p;_la;Z-Zz_30_30-M_CadExternalReferences;; ;;^C^C_-layer;LO;Z-Zz_30_30-M_CadExternalReferences;; ^C^C_Purge;a;*;N;;;

Everything is working and doing what I want. Actually I want to put more stuff in this macro.

 

It should be only one button, But like I said, the first part of the layer name:

 NX91NE$0$L_101_TEXT .

 NX91NE$0$ I have to remove by hand.

 

If I can use only L_101_TEXT, that would be great.

Because all the GIS coordinates started NX91NE$0$ or SD84SW0$ or NY10NW$0$. Etc.

 

Thank you once again Ken 👍

0 Likes
Message 4 of 11

PedroMSilva22
Participant
Participant

Hi Ken, thank you for the help,

The thing is : 

I had to divide the macro command in 2:

 

1-First part:

  • ^C^C_xref;bind;*;^C^C_Purge;a;*;N;;;^C^C-layer _E;*;;^C^C_xplode;_all;;^C^C_xplode;_all;;;^C^C_'_zoom _e;

2-Second part:

  • ^C^C_-LAYMRG;N;L_105_WATER_P;;N;L_104_WATER;Y;;^C^C_-rename;LA;L_103_TOPO;Z-En_32_10_40-M_Land;^C^C_-rename;LA;L_102_BUILDING;Z-En_32_10_39-M_Buildings;^C^C_-rename;LA;L_101_TEXT;Z-Zz_20_10_90-M_Land.Text;^C^C_-rename;LA;L_104_WATER;Z-Co_32_65_72-M_Rivers;^C^C-layer;_color 253;Z-En_32_10_40-M_Land;^C^C-layer;_color 6;Z-En_32_10_39-M_Buildings;^C^C-layer;_color 9;Z-Zz_20_10_90-M_Land.Text;^C^C-layer;_color 140;Z-Co_32_65_72-M_Rivers;;^C^C_SETBYLAYER;all;;Yes;Yes;^C^C_copybase;0,0,0;_all;;^C^C_erase;all;;^C^C_pasteblock;0,0,0;;^C^C_-layer;n;Z-Zz_30_30-M_CadExternalReferences;;^C^C_-layer;_color 253;Z-Zz_30_30-M_CadExternalReferences;^C^C_chprop;_all;;_p;_la;Z-Zz_30_30-M_CadExternalReferences;; ;;^C^C_-layer;LO;Z-Zz_30_30-M_CadExternalReferences;; ^C^C_Purge;a;*;N;;;

Everything is working and doing what I want. Actually I want to put more stuff in this macro.

 

It should be only one button, But like I said, the first part of the layer name:

 NX91NE$0$L_101_TEXT .

 NX91NE$0$ I have to remove by hand.

 

If I can use only L_101_TEXT, that would be great.

Because all the GIS coordinates started NX91NE$0$ or SD84SW0$ or NY10NW$0$. Etc.

0 Likes
Message 5 of 11

Sea-Haven
Mentor
Mentor

Have you looked at using a lisp ?

 

You could write a lisp with a few defuns in it that accept a list of values like oldname newname, new layer, rename layer, layer lock, chprops and so on then it could be used in other code you write. 

 

I have a does layer exist that I use often it makes the layer, sets color and linetype as an example.

 

Reading the button macro takes a bit of thought. 

Message 6 of 11

PedroMSilva22
Participant
Participant

Hi Sea-Haven, 

 

Its a big macro, it has lots of steps to do.

Using a lisp? Actually no, I'm still not confortable to doing a Lisp.

But, If u said that is possible. 

I try to see on it.

But mean time, let's see if someone can crack the code!😁

 

Thank you 

0 Likes
Message 7 of 11

Moshe-A
Mentor
Mentor
Accepted solution

@PedroMSilva22  hi,

 

1-First part:

  • ^C^C_xref;bind;*;^C^C_Purge;a;*;N;;;^C^C-layer _E;*;;^C^C_xplode;_all;;^C^C_xplode;_all;;;^C^C_'_zoom _e;

Sorry to say this but you on your own hands damaging your drawings and than looking for solutions to fix.

it is wrong to bind all xrefs + exploding all blocks. instead of spending time disassembling all, learn how to handle them.

 

Are you aware that binding all xrefs is the cause of this?!

 

 NX91NE$0$L_101_TEXT

 

this does not ends on layers name but creating damage to other AutoCAD tables (text styles, dimension styles, linetypes and blocks name)

 

here's an FLN command to fix drawing layers that has been damaged. if the result still leaves $0$ layers, that means that it can not be renamed (cause a layer by that name is already exist).

 

enjoy

Moshe

 

; Fix Layer Name
; this command will remove dependent xref name from layers
(defun c:fln (/ flag tbl p Lname Cname elist)
 (setq flag t) 
 (while flag
  (mapcar 'set '(flag tbl) '(nil nil))
  (while (setq tbl (tblnext "layer" (not tbl)))
   (if (and
	 (/= (logand (cdr (assoc '70 tbl)) 16)) ; not xref dependent
	 (setq p (vl-string-position (ascii "$") (setq Lname (cdr (assoc '2 tbl)))))
	 (wcmatch (substr Lname (1+ p) 3) "$[0-9]$")
         (null (tblsearch "layer" (setq Cname (substr Lname (+ p 4))))) ; can layer be rename?
         (setq elist (entget (tblobjname "layer" Lname)))
       )
    (setq flag (entmod (subst (cons '2 Cname) (assoc '2 elist) elist)))
   ); if
  ); while
 ); while

 (princ "\nDone.") 
 (princ)
); c:fln

 

 

 

 

 

 

 

 

 

 

 

Message 8 of 11

PedroMSilva22
Participant
Participant

Hi Moshe,

Thank you for the comment. Much apreciated.

Actually, I didn't know! 😬

Doing the Xref and then Bind into the drawing, was the cause of the NX91NE$0$L_101_TEXT.

It has me all along.

I always try to rename the layers, cus they have all the information like u said.

Now I see things diferents. Honest I didnt know. (that's why we have some very good help from the Forum)

But one question, Why create a block in a block and sometimes in another block?

 

Thank you for the FLN comand and the help!

0 Likes
Message 9 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

@PedroMSilva22 wrote:

 

....

Doing the Xref and then Bind into the drawing, was the cause of the NX91NE$0$L_101_TEXT.

....


If you don't want that result, always use the Bind Type "Insert" option, not the "Bind" option, in Xref-binding:

Kent1Cooper_0-1669641032410.png

Kent Cooper, AIA
0 Likes
Message 10 of 11

Moshe-A
Mentor
Mentor

@PedroMSilva22 

 


@PedroMSilva22 wrote:

Hi Moshe,

Thank you for the comment. Much apreciated.

Actually, I didn't know! 😬

Doing the Xref and then Bind into the drawing, was the cause of the NX91NE$0$L_101_TEXT.

It has me all along.

I always try to rename the layers, cus they have all the information like u said.

Now I see things diferents. Honest I didnt know. (that's why we have some very good help from the Forum)

But one question, Why create a block in a block and sometimes in another block?

 

Thank you for the FLN comand and the help!


Well, i assume users may do this by mistake unaware of what the results.  there is a PASTEBLOCK command that let folks copy and paste as block with nonsense name. also you can see users creates blocks with nonsense name knowingly 🤔

 

Moshe

 

Message 11 of 11

Gbalcom
Participant
Participant
I just ran into exactly this. I have pre-populated model space views (for use in SSM). They are designated with "X_" as a placeholder for the eventual room number for each drawing. I want a lisp that I could type in the right room number and have it do a find and replace on the model view name. You say it can be done easily enough. I'm new to Lisp, but trying to learn.

Here is what I had, up until I read your post.

(defun C:rv (/ RmName)
(Setq RmNbr (getstring "\n Room Number: "))
(Command "-Rename" "View" "101_*" "RmNbr_*")

)

Now I realize this can't work. What should I be calling instead of rename?
0 Likes