I see, good catch! Thanks. It was my bad.
The thing is that once we found the closest line (by min mid-mid dist) we put DIMALG from mid of first one to the CLOSEST point of the second line, so we can perpendicularly dim a diameter. Which was good...
...if I haven't used this mid-closestpoint dist for the limit condition. It should be mid-mid dist.
I guess it would solve both issues.
(vl-load-com)
(defun c:DimBeamWidth ( / s l e m)
(if (and (setq s (ssget '((0 . "LINE")))) ; select LINEs
(setq m (getint "\nMax diameter limit: "))
(setq l (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))) ; list of lines
(setq l (mapcar '(lambda (e) (list e (mapcar '/ (mapcar '+ (cdr (assoc 10 (entget e))) (cdr (assoc 11 (entget e)))) '(2 2)))) l)) ; list of '(line (mid-point))
)
(while (and (setq e (car l)) ; foreach line
(setq l (cdr l))) ; remove line from the rest of list
(setq l (vl-sort l '(lambda (e1 e2) (< (distance (cadr e) (cadr e1)) (distance (cadr e) (cadr e2)))))) ; sort the rest by min dist between mid-points
(if (< (distance (cadr e) (cadar l)) m)
(progn
(command "_.dimaligned" "_non" (trans (cadr e) 0 1) "_non" (trans (vlax-curve-getclosestpointto (caar l) (cadr e)) 0 1) "_non" "@") ; dimali line to the closest point of closest line
(setq l (cdr l)))))) ; remove closest one from list
(princ)
)
Edit: Thinking of it a little more... not sure if I have done the right thing. If the drawing is without flaws, IMHO the original code would work better. See the case from msg 2. When lines are shifted, the max limit is not "diameter" but mid-mid distance. So it was just thinking...
In general, don't like the idea to build the code robust enough to eat up all the flaws unless it's necessary.
BTW the order depends on the way it was selected. You can select it one-be-one or with fence option, that way it follows this order. With any type of window/crossing selection, it follows the order of creation.