Jump to content

[Lisp] Request for help with lisp (sorting list)


ziele_o2k

Recommended Posts

Some time ago I wrote a lisp routine for circles numbering.

 

Now it's time to make some upgrades, but i need some help.

(vl-load-com)
;circle numbering
;author ziele_o2k
;2016-03-13
(defun c:numbering ( / points ptlist num wt rad)
  (setq 
     points (ssget '((0 . "CIRCLE"))) 
     i 0
  )
  (repeat (sslength points)
     (setq 
        c (trans (cdr (assoc 10 (entget (ssname points i)))) 0 1)
        i (1+ i)
     )
     (cond
        ((= ptlist nil) (setq ptlist (list c)))
        ((/= ptlist nil) (setq ptlist (cons c ptlist)))
     )
  )
  (setq ptlist 
     (vl-sort ptlist 
        '(lambda (x y)
           (cond
              ((= (cadr x)(cadr y))(< (car x)(car y)))
              ((> (cadr x)(cadr y)))
           )
        )
     )
  )
  (setq num (getint "\nStart number: "))
  (setq wt (getreal "\ntext height: "))
  (if (> wt 0)
     (mapcar 
        '(lambda (%)
           (cd:ENT_MakeText "Model" (rtos num) % wt 0)
           (setq num (1+ num))
        )
        ptlist
     )
     (princ "\nWrong text height.")
  )
  (princ)
)
;------------------
;Part from CAD Pack
;http://forum.cad.pl/cadpl-pack-v1-lsp-t78161.html
(defun cd:ENT_MakeText (Layout Str Pb Height Rot / zdir xang)
 (setq zdir (trans '(0 0 1) 1 0 T)
       xang (angle '(0 0 0) (trans (getvar "UCSXDIR") 0 zdir))
 )
 (entmakex
   (list
     (cons 0 "TEXT")
     (cons 1 Str)
     (cons 10 (trans Pb 1 zdir))
     (cons 40 Height)
     (cons 50 (+ Rot xang))
     (cons 210 zdir)
     (cons 410 Layout)
   )
 )
)

What I would like to achive:

 

1) Add the ability to determine the tolerance of coordinates with which circles are numbered (something simmilar to tolerance in overkill function), eg in the attached dwg last two columns are a bit "higher" and with my current sorting function for list with coordinates, number 1 is at the penultimate column.

I would like to detrmine the tolerance of y coordinate (ultimately also in the x direction) so that the number 1 would be the most to the left.

In the attached example it is exaggerated, but sometimes it happens that one of the numbered circles is shifted by 0.0001 and then the whole numbering is falling apart and I have to make changes in drawing (with hundreds of circles is a bit of a annoying).

 

2) Another problem to be solved is the case when two or more circles are drawn in the same position (see in the example file). In this case, I would like to achive that routine will add only one number and give a list with numbers and coordinates of duplicated circles.

It would be good if I could determine accuracy of checking the coordinates like in problem 1).

 

thank you in advance for any help

Example.dwg

Edited by ziele_o2k
Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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