Jump to content

Lisp: how to select all circles inside a polygon


xadow

Recommended Posts

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

i know about variables per general. I mean in my program what is "s"-> the polygon i select

and so on

 

the 's' variable holds the selection set of the polyline , so I could have wrote it like this : sel or myselect ... etc as best as the programmer wants .

Link to comment
Share on other sites

well exactly that i want to know, each and every variable:

s-> variable holds the selection set of the polyline

sn->

l ->

d->

lst->

p->

a->

b->

j->

k->

ss->

 

If you could tell me it would help me alot :D

Link to comment
Share on other sites

circles where drawn from a base point i suppose etc ect.

 

Now that must be the center of all of them i hope now a polyne was drawn from a point also so the center points must be moved over the next one along with in this case the circles.

 

I hope a lisp is not needed to have click on the mouse button and move things around if so i am anxious to see it and perhaps it should be built with a voice command imagine how operating cad on voice command would be but the op would be yapping all day long in front of the of the screen.

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