This was kind of fun...
What you need to keep in mind is that, in your drawing, it appears that your '1' is below '2&6' and your '9' is below your '8' so the order in which my program will sort will take hat into account and it wont look right as it sorts from upper left to lower right. I'm sure you can take it and mess around with it to fit your needs though
- (defun c:ArrangeText ( / textSS textList sortedTextList sortedPointList) (vl-load-com) (if (setq textSS (ssget "x" (list (cons 0 "TEXT")(cons 410 "Model")))) (progn (setq textList (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex textSS))))) (setq sortedTextList (vl-sort textList '(lambda (x y) (< (atoi (vla-get-Textstring x)) (atoi (vla-get-Textstring y)))))) (setq sortedPointList (SortPoints (mapcar '(lambda (x) (vlax-get x "InsertionPoint")) textlist))) (mapcar '(lambda (x y) (vlax-put x "InsertionPoint" y)) sortedTextList sortedPointList) )) )(defun SortPoints ( l ) (setq l (vl-sort l '(lambda (x y) (cond ((= (cadr x)(cadr y)) (< (car x)(car y))) ((> (cadr x)(cadr y))) ) ) )) )
|