Jump to content
odygaro

Need Auto numbering LISP sorting by distance

Recommended Posts

odygaro

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.

A.jpg

Share this post


Link to post
Share on other sites
Tharwat

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)
)

Share this post


Link to post
Share on other sites
odygaro

Wow. it works amazing. Thank you so much

Share this post


Link to post
Share on other sites
Tharwat
Wow. it works amazing. Thank you so much

Great . You're welcome :)

 

I am really happy to help .

Share this post


Link to post
Share on other sites
MSasu

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.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...