Message 1 of 10

Not applicable
05-22-2019
02:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I have spent a long time trying to dissect this code and add or change what it need to do what i want.
This code prompts the user to select a polyline and then creates circles in that polyline also centering them in an offset pattern.
I have been trying to get the code to draw the circles in a parallel pattern and center them. I got as far as getting it to draw them in a parallel pattern but I cant figure out the math or code behind getting it to center it.
Heres the code...
(defun c:MPC (/ circle grx gry grd dia pll pur mid nll pnt oy ox iy iy) (defun circle (cen rad) (entmakex (list (cons 0 "CIRCLE") (cons 10 cen) (cons 40 rad)))) (setq grx (cvunit 32 "mm" "inch") ; grid x distance gry (cvunit 32 "mm" "inch") ; grid y distance dia 0.315 ; circle diameter grd (list grx gry) ; grid '(x y) ) ;(setvar "clayer" "_Perforations") (if (setq ss (ssget '((0 . "LWPOLYLINE")))) ; multiple polyline selection (repeat (setq i (sslength ss)) ;repeats the number of objects selccted (setq en (ssname ss (setq i (1- i)))) ; polyline's ename (if (and (not (vla-getboundingbox (vlax-ename->vla-object en) 'minpt 'maxpt)) ; get polyline's bounding box (setq pll (vlax-safearray->list minpt)) ; polyline's lower-left point (setq pur (vlax-safearray->list maxpt)) ; polyline's upper-right point (setq mid (mapcar '/ (mapcar '+ pll pur) '(2 2))) ; polyline's center point (setq nll (mapcar 'fix (mapcar '/ (mapcar '- mid pll) grd))) ; number of cells fit to lower-left quadrand in both directions '(n m) (setq pnt (mapcar '+ (mapcar '- mid (mapcar '* nll grd)) (mapcar '/ grd '(2. 2.)))) ; get lower-left point from number of cells. (setq o (if (= (rem (car nll) 2) ;returns the remainder of the first point /2 ; if number of cells in x and y direction are both odd or both even (rem (cadr nll) 2));returns the remainder of the second point /2 ; set inition on/off state of circle existence 1 ; 0 - no circle in cell 0)) ; 1 - a circle to draw (setq iy 0) ) (repeat (* 2 (cadr nll)) ; repeat to move in y direction (setq o (- 1 o);change 1 to 0 to get parallel but when this is done they are no longer centered ix 0) (repeat (* 2 (car nll)) ; repeat to move in x direction (if (= 1 (setq o (- 1 o))) ; each cell change 0/1/0 and if it's equal to 1 (circle (mapcar '+ pnt (list (* ix grx) (* iy gry))) (/ dia 2.))) ; ... then draw a circle (setq ix (1+ ix))) ; counter to move in x-dir by 1 cell (setq iy (1+ iy) ) ) ) ) ) ; counter to move in y-dir by 1 cell (princ) )
Can someone tell me what I need to change or add to get it to do what I want???
Thanks to all!!!!
Solved! Go to Solution.