xadow Posted May 15, 2014 Share Posted May 15, 2014 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. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 15, 2014 Share Posted May 15, 2014 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) Quote Link to comment Share on other sites More sharing options...
xadow Posted May 15, 2014 Author Share Posted May 15, 2014 works great thank you but can you write after each code line what you did there so i can understand it? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 15, 2014 Share Posted May 15, 2014 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 . Quote Link to comment Share on other sites More sharing options...
xadow Posted May 15, 2014 Author Share Posted May 15, 2014 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 Quote Link to comment Share on other sites More sharing options...
xadow Posted May 15, 2014 Author Share Posted May 15, 2014 also the meaning of each charater: s sn l i d lst p a b j k ss What are they Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 15, 2014 Share Posted May 15, 2014 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 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 15, 2014 Share Posted May 15, 2014 also the meaning of each charater: s sn l i d lst p a b j k ssWhat are they These called local variables . Quote Link to comment Share on other sites More sharing options...
xadow Posted May 15, 2014 Author Share Posted May 15, 2014 yeah i'd like to know which each local variable means.... Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 15, 2014 Share Posted May 15, 2014 yeah i'd like to know which each local variable means.... Read THIS about variables . Quote Link to comment Share on other sites More sharing options...
xadow Posted May 15, 2014 Author Share Posted May 15, 2014 i know about variables per general. I mean in my program what is "s"-> the polygon i select and so on Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 15, 2014 Share Posted May 15, 2014 i know about variables per general. I mean in my program what is "s"-> the polygon i selectand 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 . Quote Link to comment Share on other sites More sharing options...
xadow Posted May 15, 2014 Author Share Posted May 15, 2014 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 Quote Link to comment Share on other sites More sharing options...
ROBP Posted May 15, 2014 Share Posted May 15, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.