Maybe if your dwg number [dwg#] is allways at the same location , you gan get it with a SSGET .
(setq dwg# (ssget (list xpt ypt)))
Also if your dwg# as a common prefix, and any other unique feature ,as the layer, linetype,textstyle or so, it can be also get by a SSGET
(setq dwg#( ssget "x" (list (cons 0 "METEXT" ) (CONS 62 "DWG#COLOR") (CONS 8 "DWG#LAYER) (CONS 1 "DWG#*) (CONS 10 "DWG#INSERTIONPOIT) )))
(CONS 1 "DWG#*) will get any MTEXT that beguin with DWG#, and as it is only one MTEX that beguin with such prefix, it will pick it
Hope it help