How to show a random selected entity’s AutoCad Handle

I am a little tired of looking for this so I thought I would copy it here. Here is the source.

[lisp]

(defun c:ShowHandle (/ en ed newtxt)
(if (setq en (entsel “Pick object: “)) ;Ask user to select object
(progn
(setq ed (entget (car en))) ;Get data of object

;; Create new text object’s data
(setq newtxt (list ‘(0 . “TEXT”)
(assoc 10 ed) ;Insert point on the same os the object’s 1st point
(cons 1 (cdr (assoc 5 ed)))
;Text value as per object’s handle
(cons 40 (getvar “TEXTSIZE”))
;Text height as per default
) ;_ end of list
) ;_ end of setq

(alert
(strcat
“The object’s handle [”
(cdr (assoc 5 ed))
“] is now copied to a text object.\nUse last to select it.”
) ;_ end of strcat
) ;_ end of alert

) ;_ end of progn
(princ “Canceled”)
) ;_ end of if
(princ)
) ;_ end of defun

 

Decimal
String
Range

[/lisp]