ziele_o2k 发表于 2022-7-5 17:48:47

[Lisp] Request for help with l

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
页: [1]
查看完整版本: [Lisp] Request for help with l