Nikon Posted 2 hours ago Posted 2 hours ago (edited) Hello everyone Sorting by Y coordinate from bottom to top does not work. The numbers are not arranged in increasing order. How can this be fixed? (defun to3 (n) (setq str (rtos n 2 3)) (if (not (wcmatch str "*.*")) (setq str (strcat str ".000"))) (while (< (strlen (substr str (+ 2 (vl-string-search "." str)))) 3) (setq str (strcat str "0")) ) str ) (defun c:INCTEXT_Y (/ inc startval cnt sel txtlist sorted i ent edata yval newval strval) (setq inc 2.8) (setq startval 6.4) (setq cnt 1) (setq sel (ssget '((0 . "TEXT")))) (if sel (progn ;; Making a list: (entity, Y-coord) (setq txtlist nil) (setq i 0) (while (< i (sslength sel)) (setq ent (ssname sel i)) (setq edata (entget ent)) (setq yval (cadr (assoc 10 edata))) (setq txtlist (cons (list ent yval) txtlist)) (setq i (1+ i)) ) ;; Sorting by Y-coordinate from bottom to top ; (setq sorted (vl-sort txtlist '(lambda (a b) (> (cadr a) (cadr b))))) ; top to bottom? (setq sorted (vl-sort txtlist '(lambda (a b) (< (cadr a) (cadr b))))); bottom to top? ;; Changing values (foreach txt sorted (setq newval (+ startval (* cnt inc))) (setq strval (to3 newval)) (setq ent (car txt)) (setq edata (entget ent)) (setq edata (subst (cons 1 strval) (assoc 1 edata) edata)) (entmod edata) (setq cnt (1+ cnt)) ) (princ " The values of all selected texts are increased progressively.") ) (princ " Single texts are not selected.") ) (princ) ) Edited 2 hours ago by Nikon Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.