ekolman,
Here is something that works more or less in your case.
We find the bounding box of the bar text then send creates a fence selection
from the center of the bb to the left of it.
We sort the resulting selection set on distance from the bounding box.
However you managed to have some bar with distance to the right or on top
of each other. So please correct these before using.
Entity that cannot be matched are highlightred with a rectangle around them.
The matched entities are sent to a CSV file.
No amount of Lisp will replace a well drafted drawing. The way your annotations are done, makes it difficult even for a human to figure the dimension of the bars.
(defun c:test (/ dir dist en en2 ent ent2 fh fname f1 f2 foundl i j
mn mx nomatch p1 p2 searchlen ss ss2)
;; File is opened in Append Mode ;
(setq fname (strcat (getvar "dwgprefix") (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4 )) ".csv")
fh (open fname "a"))
(setq scrsize (getvar 'SCREENSIZE)
ratio (/ (car scrsize) (cadr scrsize))
searchlen (* (getvar 'VIEWSIZE) ratio) ; Length of Selection Fence ;
nomatch 0 ; Number of Items with no matched length ;
)
;; Selecting All Text with Character ASCII 131 ;
(if (setq ss (ssget "_X" '((0 . "TEXT") (1 . "#*`ƒ#*`/##"))))
(progn
(repeat (setq i (sslength ss))
(setq en (ssname ss (setq i (1- i)))
ent (entget en)
dir (cdr (assoc 50 ent))
)
(vla-getboundingbox (vlax-ename->vla-object en) 'mn 'mx)
(setq p1 (vlax-safearray->list mn)
p2 (vlax-safearray->list mx)
)
;; First point of fence is midpoint of Bar Description. ;
(setq f1 (list (/ (+ (car p2) (car p1)) 2.) (/ (+ (cadr p2) (cadr p1)) 2.))
f2 (polar f1 dir searchlen)
)
(if (setq ss2 (ssget "_F" (list f1 f2) '((0 . "TEXT") (1 . "L=#*"))))
(progn
(setq foundl nil)
(repeat (setq j (sslength ss2))
(setq en2 (ssname ss2 (setq j (1- j)))
ent2 (entget en2)
dist (distance f1 (cdr (assoc 10 ent2)))
foundl (cons (list dist (cdr (assoc 1 ent2))) foundl)
)
(setq foundl (vl-sort foundl (function (lambda (a b) (< (car a) (car b))))))
(write-line (strcat (cdr (assoc 1 ent)) ", " (cadr (car foundl))) fh)
)
)
;; If we did nod not find put a rectangle around the entity. ;
(progn
(vl-cmdf "_RECTANGLE" p1 p2)
(setq nomatch (1+ nomatch))
)
)
)
)
)
(princ (strcat "File: " fname " has been created."))
(close fh)
(if (> nomatch 0) (alert (strcat (itoa nomatch) " Bars could not be matched.")))
(princ)
)
ymg