Jump to content

Increment with a given prefix


lucky9

Recommended Posts

Need a code that can increment 1 number with a prefix.

 

For example

Enter prefix > J-

Enter number to start > 4

 

Now, with every click anywhere on a drawing it should make a text with prefix as following

 

J-4 , J-5 , J-6 .. etc

 

Thanks

Link to comment
Share on other sites

(defun C:test ( / pref suff i h p s )
 (setq pref (getstring "Enter prefix <continue>: "))
 (setq suff (getstring "Enter suffix <continue>: "))
 (setq i (1- (cond ((progn (initget 4) (getint "Enter number to start <0>: ")))(0))))
 (setq h (getvar 'textsize))
 (while (setq p (getpoint (strcat "\nSpecify " (setq s (strcat pref (itoa (setq i (1+ i))) suff)) " location <done>: ")))
   (entmakex (list '(0 . "TEXT") (cons 10 p) (cons 40 h) (cons 1 s)))
 )
 (princ)
); defun

Link to comment
Share on other sites

My $0.05 just expanded a bit on Grrr ideas added a dialouge entry.

 

; simple text increment labeller
; by Alan H june 2018

(defun C:test ( / pref suff i h p s )
(if (not ah:getval3)(load "getvals3"))
(ah:getval3 "Enter prefix" 5 4 "J-" "Enter start number" 5 4 "0" "Enter increment" 5 4 "1")
 (setq pref val1)
 (setq i (atoi val2))
 (setq inc (atoi val3))
 (setq h (getvar 'textsize))
 (while (setq p (getpoint "pick point enter for done"))
 (setq s (strcat pref (rtos (setq i (+ inc i)) 2 0) ))
 (entmakex (list '(0 . "TEXT") (cons 10 p) (cons 40 h) (cons 1 s)))
 )
 (princ "\n")
)

GETVALS3.lsp

ScreenShot126.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...