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

Auto Increment Letter

23 REPLIES 23
Reply
Message 1 of 24
Anonymous
6096 Views, 23 Replies

Auto Increment Letter

I am having trouble creating text that auto increments letters. A, B, C,
D...etc.


(defun c:alt ()

(setq rot (getint "Enter Rotation:"))(terpri)
(setq h (getVAR "TEXTSIZE"))
(setq x 1)
(while x
(setq lt (chr 65))
(command "text" "j" "mc" pause h rot lt)
(setq lt (1+ (ascii lt)))
)
)

I'm not sure how to add 1 to the letter A (chr 65 + 1).
I would eventually like to go from Z to AA, BB, CC...etc, and pick the mid
point (mtp) of an object.
Any thoughts?

Thanks
23 REPLIES 23
Message 2 of 24
Anonymous
in reply to: Anonymous

See if the variation below has the behaviour you seek for the first 26 letters. If so, then we could address the 'Z' 'AA' 'BB', etc.


(defun c:alt ()
(c:setup)
(setq rot (getint "Enter Rotation:"))(terpri)
(setq h (getVAR "TEXTSIZE"))
(setq x 1)
(while (setq p (getpoint " pick point "))
(command "text" "j" "mc" p h rot *lt*)
(setq *lt* (chr (1+ (ascii *lt*))))
)
)
(defun c:setup ()(setq *lt* (chr 65)))
Message 3 of 24
Anonymous
in reply to: Anonymous

That is exactley what I was looking for. Thank you.


wrote in message news:6010507@discussion.autodesk.com...
See if the variation below has the behaviour you seek for the first 26
letters. If so, then we could address the 'Z' 'AA' 'BB', etc.


(defun c:alt ()
(c:setup)
(setq rot (getint "Enter Rotation:"))(terpri)
(setq h (getVAR "TEXTSIZE"))
(setq x 1)
(while (setq p (getpoint " pick point "))
(command "text" "j" "mc" p h rot *lt*)
(setq *lt* (chr (1+ (ascii *lt*))))
)
)
(defun c:setup ()(setq *lt* (chr 65)))
Message 4 of 24
Anonymous
in reply to: Anonymous

You're welcome.
Code below handles "Z" -> "AA" -> "BB" . Its c:setup asks for a starting letter (or pair of letters).

(defun c:alt ()
(c:setup)
(setq rot (getint "\nEnter Rotation: "))
(setq h (getVAR "TEXTSIZE"))
(while (setq p (getpoint " pick point "))
(command "text" "j" "mc" p h rot *lt*)
(setq *lt* (stringincrement *lt*))
)
)

(defun c:setup ()(setq *lt* (getstring "\nEnter starting letter (or pair of letters)")))

(defun stringincrement (string)
(cond
((= "Z" string) "AA")
((= 1 (strlen string))(chr (1+ (ascii string))))
((= 2 (strlen string))
(strcat (chr (1+ (ascii (substr string 1 1)))) (chr (1+ (ascii (substr string 2 1)))))
)
(t (princ "\nwarning: unhandled string passed to function stringincrement")(princ) nil)
)
)
Message 5 of 24
JamaL9722060
in reply to: Anonymous

 

Could you please have a look on my thread:

 

 http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/How-to-have-serial-letters/td-p/33562...

 

Is there a way to give the existence text a “serial letters”?

 

 

---------------------------
Jamal Numan
Message 6 of 24
Hallex
in reply to: JamaL9722060

"Serial numbers"

What is it?

Show us an example, say

like this:

A-1

A-1

A-3

 

I don't understand

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 7 of 24

I use this for alphanumeric

(defun inc_txt (Txt / Boucle Decalage Val_Txt)
  (setq Boucle 1 Val_txt "")
  (while (<= Boucle (strlen Txt))
    (setq Ascii_Txt (vl-string-elt Txt (- (strlen Txt) Boucle)))
    (if (not Decalage)
      (setq Ascii_Txt (1+ Ascii_Txt))
    )
    (if (or (= Ascii_Txt 58) (= Ascii_Txt 91) (= Ascii_Txt 123))
      (setq
        Ascii_Txt
         (cond
           ((= Ascii_Txt 58) 48)
           ((= Ascii_Txt 91) 65)
           ((= Ascii_Txt 123) 97)
         )
        Decalage nil
      )
      (setq Decalage T)
    )
    (setq Val_Txt (strcat (chr Ascii_Txt) Val_Txt))
    (setq Boucle (1+ Boucle))
  )
  (if (not Decalage)
    (setq Val_Txt
      (strcat
        (cond ((< Ascii_Txt 58) "0")
          ((< Ascii_Txt 91) "A")
          ((< Ascii_Txt 123) "a")
        )
        Val_Txt
      )
    )
  )
  Val_Txt
)

 Exemple:

(inc_txt "A") "B"

(inc_txt "Z") "AA"

(inc_txt "09") "10"

(inc_txt "9") "00"

(inc_txt "Z9") "AA0"

(inc_txt "AZ9") "BA0"

(inc_txt "a1z8") "a1z9"

(inc_txt "a1z9") "a2a0"

etc...

 

Joint complete routine for insert a block with incremented attribut

Message 8 of 24

 

Thank you CADaStroumph.

 

The lsp code that you have provided seems not to work.

 

Is there something missing in the code? i comapred it with another lsp file to see what might be missing.

 

What might be the problem?

 

Best

 

Jamal

 

Clip_413.jpg

 

Clip_414.jpg

---------------------------
Jamal Numan
Message 9 of 24
JamaL9722060
in reply to: Hallex

 

Thanks Hallex,

 

For example, in the first screenshot below, I wanted to automatically switch the “A” texts to be as in the screenshot 2

 

We can do the same thing if we have numbers using the “auto number” command (screenshot 4 and 5)

 

Best

 

Jamal

 

Clip_415.jpg

 

Clip_416.jpg

 

Clip_396.jpg

 

Clip_397.jpg

 

---------------------------
Jamal Numan
Message 10 of 24
Hallex
in reply to: JamaL9722060

Give this a shot

{code}

;;  fixo () 2012 * all rights released
;;  3/5/12
;;  renumbering selected texts
(defun C:REAN(/ alist en enlst ent got)
  
;;local function based on code by Tom Brabant (tom.brabant)
(defun inc-str	(string)
  (cond
    ((= "Z" string) "AA")
    ((= 1 (strlen string)) (chr (1+ (ascii string))))
    ((= 2 (strlen string))
     (strcat (substr string 1 1)
	     (chr (1+ (ascii (substr string 2 1)))))
     )
    (t
     (princ
       "\nwarning: unhandled string passed to function inc-str")
     (princ)
     nil)
    )
  )
  
  ;;				main part			;;
  
  (command "_undo" "_begin")
  
  (while (setq ent (entsel "\nSelect text or Enter to Exit: "))
    (setq en (car ent))
    (redraw en 3)
    (setq enlst (cons en enlst)))
  (setq enlst (reverse enlst))
  
  (setq *st* (cdr (assoc 1 (entget (car enlst)))))
  
 (if (vl-string-position (ascii *st*) "0123456789")
   (progn(setq got T)(setq *st* (itoa (1- (atoi *st*)))))
   (progn(setq got nil)(setq *st* (chr (1- (ascii *st*)))))
   )
  
(foreach en enlst
  (setq alist (entget en))
  (setq alist (subst (cons 1 (if got
			       (setq *st* (itoa (1+ (atoi *st*))))
			       (setq *st* (inc-str *st*)))
			   )
		     (assoc 1 alist)
		     alist)
	)
	 (entmod alist)
  (entupd en)
  )
  (redraw)
  (command "_undo" "_end")
 (princ)
  )

(princ "\nType REAN to execute...")
(princ)

 

{code}

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 11 of 24
CADaSchtroumpf
in reply to: Anonymous

Why i don't see the "/" (slash) in your notepad ?

The fonction inc_str required an argument; arg:Txt (must be a string) and local variable: Boucle Decalage Val_Txt

 

Your image:

(defun inc_txt (Txt  Boucle Decalage Val_Txt)

My code:

(defun inc_txt (Txt / Boucle Decalage Val_Txt)

 

 

Message 12 of 24
JamaL9722060
in reply to: Hallex

Many thanks Hallex. This code is working very well.

 

Could this be developed to allow the window selection instead of selecting the letters one by one exactly the same way “auto number” command is working?

 

Best

 

Jamal

 

Clip_435.jpg

 

Clip_436.jpg

 

---------------------------
Jamal Numan
Message 13 of 24

Thanks CADaStroumph.

 

still the code is not working. please, have a look on the screenshot below?

 

best

 

jamal

 

Clip_437.jpg

 

---------------------------
Jamal Numan
Message 14 of 24
Kent1Cooper
in reply to: JamaL9722060

I think you need to read more about the syntax of the (defun) function.

 

When it's used like this:

 

(defun C:MarilynMonroe (/ mickey mouse)

 

with the C: at the beginning, and with nothing between the ( and the /, then what is defined is a COMMAND [that's what the C stands for], and can be used by typing simply the Command name:

 

MarilynMonroe

or, if called from inside another Lisp function, with both the C: and surrounding parentheses:

(C:MarilynMonroe)

 

It's not allowed to have anything [other than spaces if you want them] between the ( and the /, that is, it's not allowed to have "arguments".  The mickey and mouse are localized variables that will be used within the operation of the Command; such definitions do not always include localized variables, and if they don't, they can have the () without the / inside, but they still must have the ().

 

When it's used like this:

 

(defun OrsonWelles (gold silver bronze / up down sideways)

 

without the C: at the beginning, and with or without arguments listed between the ( and the /, then what is defined is a [people use different words] FUNCTION or ROUTINE or SUB-ROUTINE.  It is allowed to have arguments [the gold and silver and bronze], though it is not required to.  [It may or may not also have localized variables after the /, and if it has no arguments or localized variables, it still must have the (), with or without a / inside.]  Such a function must be used with parentheses around the function name, and if any arguments are listed, values for all of them must also be supplied inside the parentheses:

 

(OrsonWelles 12.5 "hello" T)

 

Your

 

(defun C:inc_txt (Txt / Boucle .....

 

is a violation of the distinction between Command and Function definitions.  If it has the C:, it may not have the Txt argument before the /; if it has the Txt argument, it may not have the C:.

Kent Cooper, AIA
Message 15 of 24
Hallex
in reply to: JamaL9722060

Try edited version attached

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 16 of 24
JamaL9722060
in reply to: Hallex

Perfect Hallex. You are a star.

 

this is what i've been looking for long time ago.

 

that's really brilliant.

 

many thanks

 

Jamal

 

 

---------------------------
Jamal Numan
Message 17 of 24
JamaL9722060
in reply to: Hallex

Sorry Hallex.

 

sounds the the lisp file doesn't work properly. please, have a look on the screeshot below

 

what might cause this error?

 

best

 

Jamal

 

Clip_454.jpg

 

Clip_455.jpg

---------------------------
Jamal Numan
Message 18 of 24
JamaL9722060
in reply to: Kent1Cooper

Many thanks Kent for the elaboration. appreciated.

 

best

 

Jamal

---------------------------
Jamal Numan
Message 19 of 24
JamaL9722060
in reply to: Hallex

Hi Hallex,

 

I'm not sure if your time permits to develop the code a bit more to be the same the way the "Automatic Text Numbering" works with all its options.

 

Why the message "impossible to sort selected texts" is generated?

 

Many thanks

 

best

 

Jamal

 

Clip_599.jpg

 

Clip_600.jpg

 

Clip_601.jpg

 

 

 

 

---------------------------
Jamal Numan
Message 20 of 24
Hallex
in reply to: JamaL9722060

Hi Jamal

You wrote:

>> Why the message "impossible to sort selected texts" is generated?

All text must have equal X or Y coordinates you can ssee it within sort function

Try to change fuzz factor instead of 0.001 set  to 0.1 for example

 

best

 

~'J'~

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

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

Post to forums  

Autodesk Design & Make Report

”Boost