Help with auto number with lisp

Help with auto number with lisp

tencome
Contributor Contributor
462 Views
4 Replies
Message 1 of 5

Help with auto number with lisp

tencome
Contributor
Contributor

I am a new incomer just study lisp, ask for help.

 

1. First enter a total quantity a   (up to 9 numbers  (1,2,3^^^ 8,9) + 26 letters = up to 35) to automatically produce all numbers.

For example,

if  input a=5, you will output 1,2,3,4,5,

if input  a=12, output 1,2,3,4,5,6,7,8,9, A, B, C

 

2. The starting point coordinate is (0 0), and the spacing between each number and number is 100mm in X direction and 200mm in Y direction.

 

 

 

I didn't know how to modify below lisp to meet requirements.

(defun C:xh()
(setq a (getint "\ total quantity a"))
(setq n 1)
(setq x 100)

(while 1
(setq p '(0 0))
(command "text" "J""M" p 100 0 n)
(setq n (+ n 1))
)
)

 

0 Likes
Accepted solutions (2)
463 Views
4 Replies
Replies (4)
Message 2 of 5

hak_vz
Advisor
Advisor
Accepted solution
(defun C:xh(/ )
(initget 7)
(setq a (getint "\ total quantity a"))
(setq maxval 35 i -1)
(setq p '(0 0))
(setq s '("1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"))
(cond 
((<= a maxval)
(while (< (setq i (1+ i)) a)
	(command "_.text"  p 10 0 (nth i s) "")
	(setq p (mapcar '+ p '(100 200)))
))
)
(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 3 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

Here's a way to do it without spelling out a long list of 35 characters:

 

(defun C:TEST (/ a p asc)
  (while (or (not a) (> a 35))
    (initget 7); no Enter, no zero, no negative
    (setq a (getint "\nTotal quantity a {1 to 35}: "))
  ); while
  (setq
    p '(-100 -200)
    asc 48
  ); setq
  (repeat a
    (command "_.text"
      "_m" (setq p (mapcar '+ p '(100 200))) 100 0
      (chr (setq asc (+ asc (if (= asc 57) 8 1))))
    ); command
  ); repeat
  (princ)
); defun

 

It requires that the current Text Style does not have a fixed height.  You could build in the setting of the appropriate Style to ensure that, and if you want, make that a fixed-height Style and omit the 100 for the height in the Text command.

 

It asks again if you give it a number less than 1 or larger than 35.

Kent Cooper, AIA
Message 4 of 5

tencome
Contributor
Contributor
Thank you very much.
0 Likes
Message 5 of 5

tencome
Contributor
Contributor
Thank you very much, I need study it.