AutoLISP Pt 4 - Dynamic Text Placement Tutorial

In this deep dive, we explore the fascinating world of dynamic text placement in AutoCAD. * Updated with Bug Fix! *

AUTOCADAUTOLISP

My post content

Greetings, fellow coding enthusiasts! We’re excited to bring you the latest installment in our AutoLISP Programming Series. In this deep dive, we explore the fascinating world of dynamic text placement in AutoCAD. Whether you’re a seasoned coder or just starting, there’s something for everyone in “Mastering AutoLISP Programming | Part 4.”

This tutorial takes you through the powerful ‘while’ loops, ‘getpoint,’ ‘getint,’ and ‘rtos’ functions. These tools are the building blocks of AutoLISP mastery, and we dissect their applications for dynamic text placement. Prepare to enhance your AutoCAD customization skills with precision and efficiency.

This includes a bug fix covered in the next video in this series!

Want to learn more about AutoCAD? Check out our AutoCAD class options!

Below you will find the code that was shown in the video.

To run it, copy the code below and paste it into a text file called AutoCount.lsp
To load it into AutoCAD, use the APPLOAD command,

Start the command by typing AUTOCOUNT

;
;
; AutoCount.LISP
;
; Davin Atkins 2023 – youtube.com/@atccad
;
; This LISP routine, asks the user for a starting number
; then a count interval. Then for each click, a new text
; object is placed with the next number in line
;
;
;————————————————————-
;————————————————————-

(defun c:AUTOCOUNT ()

; Check to see if the Text Style has a height defined - This will return 0.0 if NOT defined
(setq STYLEHEIGHT (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))))

(if (= STARTNUM nil)(setq STARTNUM 1))
(setq TMPSTARTNUM (getint (strcat "nCounting from <" (rtos STARTNUM 2 0) ">: ")))
(if TMPSTARTNUM (setq STARTNUM TMPSTARTNUM))

(if (= COUNTBY nil)(setq COUNTBY 1))
(setq TMPCOUNTBY (getint (strcat "nCounting interval <" (rtos COUNTBY 2 0) ">: ")))
(if TMPCOUNTBY (setq COUNTBY TMPCOUNTBY))

(while (setq INSPOINT (getpoint "nClick the location of the next text element"))
(if (= STYLEHEIGHT 0.0)
(command "text" INSPOINT 6 0 STARTNUM)
(command "text" INSPOINT 0 STARTNUM)
)
(setq STARTNUM (+ STARTNUM COUNTBY))
)

(princ
)