AutoNumbering

AutoNumbering

Anonymous
Not applicable
2,765 Views
15 Replies
Message 1 of 16

AutoNumbering

Anonymous
Not applicable

Hello All, 

 

I am trying to create a macro that will allow me to increase the number of an mtext by 1 per every insertion. I am hoping to somehow attach this "auto-numbering" feature with a block. A few notes:

 

1) I am aware a tcount command exists, but I am using AutoCAD LT 2013. From my understanding, this is only available in 2014 and up. 

 

2) As of now, I am struggling with the following macro.

 

     *^C^C_- insert;label;\;;$M=$(getvar,A#0);A#0;$M=$(+,$(getvar,A#0),1);

 

     For some reason when I activate the command, AutoCAD cannot respond and shuts down. I am hoping to create the following chain:

         

          A#0, A#1, A#2, etc. Any thoughts? 

 

Any help would be great!

 

Thanks!

 

Philip

 

     

0 Likes
Accepted solutions (2)
2,766 Views
15 Replies
Replies (15)
Message 2 of 16

cadwomen
Collaborator
Collaborator
No lisp in LT so this way don't work for you
If my post answers your question, please mark it as an Accepted Solution, so that others can find answers quickly!
0 Likes
Message 3 of 16

ВeekeeCZ
Consultant
Consultant
Accepted solution
0 Likes
Message 4 of 16

Anonymous
Not applicable

Hello, 

 

Thanks for the thread link! Have you used this before?

 

I have been playing with it, but I cannot quite get the text to incrementally increase. The suggested macro is the following:

 

     *^c^c_text;\;;$M=$(+,$(getvar,USERR1),$(getvar,USERR2));setvar;USERR1;$M=$(+,$(getvar,USERR1),$(getvar,USERR2));

or

 

     *^c^c_text;\;$M=$(+,$(getvar,USERR1),$(getvar,USERR2));setvar;USERR1;$M=$(+,$(getvar,USERR1),$(getvar,USERR2));

 

If I wanted to start at 0 and increase 1 every time, how would this look, with exact inputs? 

 

Thanks for your help?

0 Likes
Message 5 of 16

Anonymous
Not applicable

Thanks for your help! *

 

- Philip

0 Likes
Message 6 of 16

ВeekeeCZ
Consultant
Consultant

Type in the command line:

userr1

0 (as start number decreased by the increment)

userr2

1 (as incerement)

 

Then the first value you'll get is 1. Then 2, 3 and so on.

 

You've welcome? Yeah, you're welcome! 🙂

 

0 Likes
Message 7 of 16

Kent1Cooper
Consultant
Consultant

[I sould suggest you use the USERI1 and USERI2 System Variables instead, i.e. the Integer rather than Real-number versions.]

Kent Cooper, AIA
0 Likes
Message 8 of 16

Anonymous
Not applicable

Thanks!

 

I you could not tell, I am fairly new to macros! Please bare with me.

 

Let me tell you whats happening...

     I will set userr1 and userr2 to 0" and 1" (Also have set USERI1 and USERI2 to 0 and 1 - Thanks for your input!)

     When using the macro, the text "setvar" will appear and will rotate 1 degree clockwise per click. 

     When resetting setvar, same thing occurs. 

 

I have tried to modify macro to my understanding - nothing works

 

Any thoughts?

 

Again, thanks for you help. Really appreciated!

 

Philip

 

 

 

 

0 Likes
Message 9 of 16

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

....

     When using the macro, the text "setvar" will appear and will rotate 1 degree clockwise per click. 

.... 


That macro was written assuming that the current Text Style has a fixed height.  So the Text command doesn't ask for one, and if your current Style doesn't have a fixed height, that is throwing off the inputs, making parts of the macro into answers to the wrong prompts.  If you don't have it set a Style for you, you need to make sure the Style you want is the current one before you pick on the menu item.  If that Style does not have a fixed height, you will need to add into the macro a response to the height prompt:

 

*^c^c_text;\YourDesiredHeight;;$M=....

 

Consider also forcing it to use 0 rotation, if that might not be the current rotation.  In older versions, 0 is always the default, so that semicolon [= Enter] just before the $M puts the rotation at 0, but in newer versions it remembers the latest rotation, which is what you'll get by accepting the default, so you may want to force it to 0:

 

*^c^c_text;\YourDesiredHeight;0;$M=....

Kent Cooper, AIA
0 Likes
Message 10 of 16

Anonymous
Not applicable

Awesome! This worked. I will just set text height within macro each time.

 

Thank you guys!

 

Is it possible to attach this feature to a block?

 

Philip

0 Likes
Message 11 of 16

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

Is it possible to attach this feature to a block?

....


If I understand what you mean by that, you could make a Block with an Attribute, and use an INSERT command instead of TEXT, having the Diesel expressions supply and increment the value for the Attribute.  That way, the Style and height and rotation of the text part would be part of the Block definition, and you wouldn't need to deal with them in the macro.

 

As with the question of whether the Text Style has a fixed height, if you do it with a Block with Attribute, you would have to be careful about whether the Block is defined for uniform scaling, and supply the right number of answers to scale factor prompts, etc.  So how it would be written exactly depends on the way the Block is defined [or whether it's always a Block in the drawing or might be an external drawing file], whether it has more than one Attribute, etc.

Kent Cooper, AIA
0 Likes
Message 12 of 16

SeeMSixty7
Advisor
Advisor

I agree with Kent1Cooper. the USERI# variables are better suited for integer counting, but also keep in mind these variables may already be being used by someone else. They may also contain values from previous use as a result. Something you can do is create an initializer in the USERS# variable that tells your macro which one to use, and can also signify if it is setup for your system or not. You would have to make use of the Diesel conditional functions, but you could make it work.

 

Good luck

0 Likes
Message 13 of 16

Kent1Cooper
Consultant
Consultant

@SeeMSixty7 wrote:

.... also keep in mind these variables may already be being used by someone else. They may also contain values from previous use as a result. Something you can do is create an initializer in the USERS# variable that tells your macro which one to use....


I also thought of the fact that they might be used by other routines.  If you find things don't work as expected, or something else doesn't work right after you've used this macro, and if that could be the reason, you could try using USERI4 and USERI5 instead of 1 and 2, on the assumption that the lower numbers are likely to be more "popular" and therefore more likely to be called for in other routines.

 

BUT if you are thinking of using the String ones USERS1-USERS5, bear in mind  that while the Real-number ones and the Integer ones are saved in the drawing, for some unknown reason the String ones are not!   If you use USERIx System Variables, you can close a drawing, and open it again later and carry on using the same macro and have it increment continuing from where you were before.  But you can't save some kind of initializer or indicator in a USERSx one and have it "survive" into a subsequent editing session.  One way to get around that could be to use Environment Variables, but I don't know whether they're a possibility in LT.

Kent Cooper, AIA
0 Likes
Message 14 of 16

SeeMSixty7
Advisor
Advisor

Kent1Cooper - I completely forgot about the fact that AutoCAD STILL doesn't save the USERS#'s variables. Good catch! I think that drove me Crazy in the late 80's.

 

Thanks!

0 Likes
Message 15 of 16

Anonymous
Not applicable

One more question!

   

      Since USERI1-5 consists of integers, how can I put a prefix in my text. For example, A#0, A#1, A#2, etc.

 

Thanks!

 

Philip

 

 

0 Likes
Message 16 of 16

ВeekeeCZ
Consultant
Consultant
That should not have be a problem. Put it before the macro starting with ...A#$M...
0 Likes