xadow 发表于 2022-7-5 23:03:03

Lisp: how to select all circle

I'd like to know a code in LISP for selecting all circles inside a polygon I made and center them in the centre of the same polygon.

Tharwat 发表于 2022-7-5 23:10:39

Try this and let me know .
 

(defun c:Test (/ s sn l i d lst p a b j k ss) ;;    Tharwat 15. may. 2014      ;; (princ "\n Select a 2Dpolyline ...") (if (setq s (ssget "_+.:S:E" '((0 . "LWPOLYLINE"))))   (progn (setq l (vlax-curve-getdistatparam (setq sn (ssname s 0)) (fix (vlax-curve-getendparam sn)))                i (/ l 1000.)                d i          )          (repeat 1000            (setq lst (cons (vlax-curve-getpointatdist sn i) lst)                  i   (+ i d)            )          )          (setq p (mapcar 'cdr (vl-remove-if-not '(lambda (x) (eq (car x) 10)) (entget sn)))                a (mapcar 'car p)                b (mapcar 'cadr p)                j (/ (apply '+ a) (length a))                k (/ (apply '+ b) (length b))          )          (if (setq ss (ssget "_CP" lst '((0 . "CIRCLE"))))            ((lambda (x / n e)               (while (setq n (ssname ss (setq x (1+ x))))               (if (vlax-write-enabled-p (vlax-ename->vla-object n))                   (entmod (subst (cons 10 (list j k 0.)) (assoc 10 (setq e (entget n))) e))               )               )             )            -1            )          )   ) ) (princ))(vl-load-com)

xadow 发表于 2022-7-5 23:16:04

works great thank you but can you write after each code line what you did there so i can understand it?

Tharwat 发表于 2022-7-5 23:17:41

You're welcome .
 
It is hard to explain everything in the routine but if you have any specific question , I can explain it for you .

xadow 发表于 2022-7-5 23:22:16

Well i cant really understand much, i was thinking to say like
 
: here you check if the centre of circle is in polygon
; here you move the centre to the centre of polygon ...
 
a few comentaries would make the understanding of the code way more easy

xadow 发表于 2022-7-5 23:27:29

also the meaning of each charater: s sn l i d lst p a b j k ss
What are they

Tharwat 发表于 2022-7-5 23:34:43

Okay ,
 
First we select a polyline then write the codes to make a list of point along the selected polyline so after that we can a selection set with the help with these point to select only circle as shown in the feed code for the ssget function , so if circles found we get the centeriod point of the polyline then update the center of each circle to that point .
 
That's it

Tharwat 发表于 2022-7-5 23:39:37

These called local variables .

xadow 发表于 2022-7-5 23:42:58

yeah i'd like to know which each local variable means....

Tharwat 发表于 2022-7-5 23:47:23

 
Read THIS about variables .
页: [1] 2
查看完整版本: Lisp: how to select all circle