@aarong85 try this. I sometimes struggle with writing and reading to and from the registry.
;; https://www.cadtutor.net/forum/topic/37515-moving-text-block-to-adjacent-point/?do=findComment&comment=566551
;; Text 2 Point - Lee Mac 2012
;; Prompts for a selection of Text and Point entities and moves
;; each Text entity to the nearest (2D distance) Point entity in the set.
;;
;; Retains existing Text elevation.
;;
;; MODIFICATIONS BY 3DWANNAB
;; Link https://www.cadtutor.net/forum/topic/37515-moving-text-block-to-adjacent-point/?do=findComment&comment=605448
;;
;; Modified on 2022.11.18 by 3dwannab.
;; - Added INSERT along with POINT to the selection.
;; - Added undo handling.
;; - Prompt to pick fuzz value.
;; - Retain slection after the command.
;;
;; Modified on 2023.03.30 by 3dwannab.
;; - Added MTEXT and CIRCLES to the program.
;;
;; Modified on 2024.05.14 by 3dwannab.
;; - Added a while loop to the program to allow user to choose different fuzz distance values.
;; - Added selection of the modified objects after the code has finished. Handled in the error handler.
;;
;; Credit to Lee Mac for the original coede
;;
(vl-load-com)
(defun c:Text_2_Point_Or_Block (/ *error* acDoc _textinsertion _MergeSelectionSets dcd di1 di2 dxf ent entname inc ins lst pnt regFuzz ss1 txt ListOfSSs)
(defun *error* (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
(not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
(princ (strcat "\n<< Error: " errmsg " >>\n"))
)
(if ListOfSSs
(progn
(sssetfirst nil (_MergeSelectionSets ListOfSSs))
(command-s "_.REGEN")
)
)
)
(defun _textinsertion (elist)
(if
(or (= "MTEXT" (cdr (assoc 0 elist)))
(and
(zerop (cdr (assoc 72 elist)))
(zerop (cdr (assoc 73 elist)))
)
)
(assoc 10 elist)
(assoc 11 elist)
)
)
;; Credit: https://www.cadtutor.net/forum/profile/23626-grrr/
;; https://www.cadtutor.net/forum/topic/61683-adding-selection-set-items-to-one-set/?do=findComment&comment=509167
(defun _MergeSelectionSets (ListOfSSs / Lst nSS)
(if (apply 'and (mapcar '(lambda (x) (= 'PICKSET (type x))) ListOfSSs))
(progn
(setq nSS (ssadd))
(mapcar
(function
(lambda (x / i)
(repeat (setq i (sslength x))
(ssadd (ssname x (setq i (1- i))) nSS)
)
)
)
ListOfSSs
)
)
)
nSS
)
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))
(while
(progn
;; Get saved value from the registry or default to 1
(setq regFuzz (read (cond ((getenv "Text_2_Point_Or_Block_Fuzz_Value")) (1))))
(setq regFuzz (cond
((getdist
(strcat "\nPick or enter the gap tolerance to move the TEXT to POINTS or BLOCKS :\nCurrent value <"
(vl-princ-to-string (getenv "Text_2_Point_Or_Block_Fuzz_Value"))
">: "
)
)
)
(regFuzz)
)
)
;; Set the registry value to the variable
(setenv "Text_2_Point_Or_Block_Fuzz_Value" (vl-princ-to-string regFuzz))
(princ "\nSelect point and text objects...\n")
(if (setq ss1 (ssget "_:L" '((0 . "POINT,INSERT,CIRCLE,TEXT,MTEXT"))))
(progn
(repeat (setq inc (sslength ss1))
(setq ent (entget (setq entname (ssname ss1 (setq inc (1- inc))))))
(if
(or
(eq "POINT" (cdr (assoc 0 ent)))
(eq "CIRCLE" (cdr (assoc 0 ent)))
(eq "INSERT" (cdr (assoc 0 ent)))
)
(setq lst (cons (cdr (assoc 10 ent)) lst))
(setq txt (cons (cons (_textinsertion ent) ent) txt))
)
)
(foreach ent txt
(setq ins (list (cadar ent) (caddar ent)))
(if (setq pnt (vl-some '(lambda (pnt) (equal ins (list (car pnt) (cadr pnt)) 1e-8)) lst))
(setq lst (vl-remove pnt lst))
(progn
(setq di1 (distance ins (list (caar lst) (cadar lst)))
mpt (car lst)
)
(foreach pnt (cdr lst)
(if (< (setq di2 (distance ins (list (car pnt) (cadr pnt)))) di1)
(setq di1 di2
mpt pnt
)
)
)
(if (< di1 regFuzz)
(progn
(setq pnt (list (car mpt) (cadr mpt) (caddar ent))
dcd (caar ent)
dxf (cdr ent)
dxf (subst (cons dcd pnt) (assoc dcd dxf) dxf)
)
(entmod dxf)
(setq lst (vl-remove mpt lst))
)
)
) ;; progn
) ;; if pnt
) ;; foreach
) ;; progn
) ;; if selection
(setq ListOfSSs (cons ss1 ListOfSSs))
) ;; progn
) ;; while
(*error* nil)
(princ)
) ;; defun
; (c:Text_2_Point_Or_Block) ;; Use for testing only