Automatically labeling attributed to a fixed maximum repeating

Automatically labeling attributed to a fixed maximum repeating

DanieljL9MXY
Observer Observer
518 Views
3 Replies
Message 1 of 4

Automatically labeling attributed to a fixed maximum repeating

DanieljL9MXY
Observer
Observer

Hi there

 

Im currently looking to edit a lsp script im using to allow me insert blocks which will include an increasing attribute for each copy of the block up to a maximum value before resetting to the initial value and beginning the count again,

 

The current script im using updates the attribute for each copy but does not reset at a maximum instead counting on to infinity, how would i be able to edit this script to reset at a chosen value

 

https://www.lee-mac.com/autolabelattributes.html

0 Likes
519 Views
3 Replies
Replies (3)
Message 2 of 4

Sea-Haven
Mentor
Mentor

Are you using Lee's lisp ? If so which one.

 

There is plenty of insert block and increment lisps out there, for me I add look for last number used 1st if none then number is 1, re reset number should be a simple (If (> num 100)(setq num 1)) in the code. 

 

Post a dwg with your block.

0 Likes
Message 3 of 4

DanieljL9MXY
Observer
Observer

Thanks Sea Haven

 

Ive since spoken to Lee himself directly and have been able to revise the code to include a counting modulus to act in the way youve described below 🙂

0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

.... should be a simple (If (> num 100)(setq num 1)) ....


If starting at 1 and if it should be reset to 1 after reaching the maximum value, here's another approach.  It does not involve an (if) function that needs to run a test every time, overtly comparing the current value to the maximum to decide whether it's time to reset.

 

(setq maxint (getint "\nMaximum value: "))

(setq val 0); initial pre-first-value

 

Then, each time the incremented number is called for, do this:

(setq val (1+ (rem val maxint)))

to return the next integer up, or back to 1 when the maximum has been reached.

 

If I set the maximum to 5, then:

(setq val (1+ (rem val maxint)))
1

(setq val (1+ (rem val maxint))) ; ... same again
2

(setq val (1+ (rem val maxint)))
3

(setq val (1+ (rem val maxint)))
4

(setq val (1+ (rem val maxint)))
5

(setq val (1+ (rem val maxint)))
1

(setq val (1+ (rem val maxint)))
2

... etc. ...

Kent Cooper, AIA
0 Likes