Nikon Posted August 27 Posted August 27 (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 August 27 by Nikon Quote
GLAVCVS Posted August 28 Posted August 28 Is the coordinate order set to Y, X, Z? This could be the error. Try changing cadr to caddr in the line '(setq yval (cadr (assoc 10 edata)))' 1 1 Quote
Saxlle Posted August 28 Posted August 28 Agree with @GLAVCVS, with cadr you're getting the X coordinate, not Y coordinate. 1 1 Quote
Nikon Posted August 28 Author Posted August 28 59 minutes ago, GLAVCVS said: Try changing cadr to caddr in the line '(setq yval (cadr (assoc 10 edata)))' Thanks, I replaced cadr with caddr, everything is fine. 1 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.