Wednesday, January 14, 2026

FREE LISP : Draw text on pick point

           In drafting work, sometimes users need to label the coordinates of multiple selected points at the same time. Normally, they have to use the text command and write the coordinates one point at a time.

Currently, AI can be used to help generate code to create a new command. We will try using AI to write a command that reads the coordinates of selected points and automatically labels the coordinates for multiple selected points simultaneously as follows.




Source code

(defun c:coords ( / pt oldos txtsize coll )
  (setq oldos (getvar "OSMODE"))
  (setvar "OSMODE" 0)

  (setq txtsize 0.075)
  (setq coll (getvar "cecolor"))   ;; current color


  (prompt "\nClick points to write coordinates. Press SPACE or ENTER to finish.\n")

  (while (setq pt (getpoint "\nSelect point: "))
(command "color" "4")   ;; set color as cyan
    (command "TEXT"
             pt
             txtsize
             0
             (strcat
               (rtos (car pt) 2 2)
               ","
               (rtos (cadr pt) 2 2)
             )
    )   (command "setvar" "cecolor" coll)   ;; return current color
  )

  (setvar "OSMODE" oldos)
  (princ)
)

FREE LISP : Draw text on pick point

           In drafting work, sometimes users need to label the coordinates of multiple selected points at the same time. Normally, they have...