odygaro Posted January 20, 2014 Posted January 20, 2014 Hi all, Very new at this forum. I need an AutoLISP that will help me auto numbering blocks or text. I am aware of "TCOUNT which is handy, however the command only gives you 3 choices in regards to how to number, X, Y and Select order. What I need is a program that will sort and number my blocks/text by distance from a point. Thank you so much for your help. Quote
Tharwat Posted January 20, 2014 Posted January 20, 2014 Welcome to CADTutor Try this code which should deal with Blocks and let me know how you'd get on with it . Note : if the text height is not suitable for you , you can change it from one to as indicated in the code . (defun c:Test (/ ss pt i sn p l lst n) (if (and (setq ss (ssget '((0 . "INSERT")))) (setq pt (getpoint "\n Specify Center point :")) ) (progn (repeat (setq i (sslength ss)) (setq sn (ssname ss (setq i (1- i))) p (cdr (assoc 10 (entget sn))) l (cons (list (distance pt p) p) l) ) ) (setq lst (vl-sort l (function (lambda (j k) (< (car j) (car k))))) n 0 ) (foreach x lst (entmakex (list '(0 . "TEXT") (cons 10 (cadr x)) (cons 11 (cadr x)) (cons 1 (itoa (setq n (1+ n)))) (cons 40 1.0) ; Text height ) ) ) ) ) (princ) ) Quote
odygaro Posted January 20, 2014 Author Posted January 20, 2014 Wow. it works amazing. Thank you so much Quote
Tharwat Posted January 20, 2014 Posted January 20, 2014 Wow. it works amazing. Thank you so much Great . You're welcome I am really happy to help . Quote
David Bethel Posted January 21, 2014 Posted January 21, 2014 I remember something about vl-sort dropping duplicate atoms : http://www.cadtutor.net/forum/archive/index.php/t-53600.html Is this still applicable? -David Quote
MSasu Posted January 21, 2014 Posted January 21, 2014 David, your observation is correct, except that Tharwat's code isn't sorting atoms, but lists, and those will be preserved after sorting, even if identical. 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.