Draw 2 Circles with a 4 way divider

Draw 2 Circles with a 4 way divider

rpajounia
Advocate Advocate
872 Views
9 Replies
Message 1 of 10

Draw 2 Circles with a 4 way divider

rpajounia
Advocate
Advocate

Can someone help me with a autolisp code that will be

 

//Make it return Ent ID

defun DoubleCircle ( FirstCircle SecondCircle / )

(

 

    entID

)

 

and pretty much what im trying to do is draw a bigger circle which is circle 1 and draw a smaller circle in the middle of circle 1 and then cut the bigger circle into 4 sections without cutting into circle 2. example is in the photo

0 Likes
873 Views
9 Replies
Replies (9)
Message 2 of 10

marko_ribar
Advisor
Advisor

Here is my code :

 

(defun c:doublecirc-4sectors ( / bp rad1 rad2 ci1 ci2 li1 li2 li3 li4 )
  (initget 1)
  (setq bp (getpoint "\nPick or specify base point : "))
  (initget 7)
  (setq rad1 (getdist bp "\nPick or specify radius of bigger circle : "))
  (setq rad2 1e+99)
  (while (> rad2 rad1)
    (initget 7)
    (setq rad2 (getdist bp "\nPick or specify radius of smaller circle : "))
  )
  (setq ci1 (entmakex (list (cons 0 "CIRCLE") (cons 10 bp) (cons 40 rad1))))
  (setq ci2 (entmakex (list (cons 0 "CIRCLE") (cons 10 bp) (cons 40 rad2))))
  (setq li1 (entmakex (list (cons 0 "LINE") (cons 10 (polar bp 0.0 rad2)) (cons 11 (polar bp 0.0 rad1)))))
  (setq li2 (entmakex (list (cons 0 "LINE") (cons 10 (polar bp (* 0.5 pi) rad2)) (cons 11 (polar bp (* 0.5 pi) rad1)))))
  (setq li3 (entmakex (list (cons 0 "LINE") (cons 10 (polar bp pi rad2)) (cons 11 (polar bp pi rad1)))))
  (setq li4 (entmakex (list (cons 0 "LINE") (cons 10 (polar bp (* 1.5 pi) rad2)) (cons 11 (polar bp (* 1.5 pi) rad1)))))
  (princ)
)

 

HTH.

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 3 of 10

rpajounia
Advocate
Advocate

i figured it out with chatgpt

 

(defun DoubleCircle ( p1 p2 / Circle1 Circle2 top1 top2 bottom1 bottom2 left1 left2 right1 right2)
  ;; Function to calculate top point of a circle
  (defun GetTopPoint (center radius)
    (list (car center) (+ (cadr center) radius) (caddr center))
  )
  
  ;; Function to calculate bottom point of a circle
  (defun GetBottomPoint (center radius)
    (list (car center) (- (cadr center) radius) (caddr center))
  )
  
  ;; Function to calculate left point of a circle
  (defun GetLeftPoint (center radius)
    (list (- (car center) radius) (cadr center) (caddr center))
  )
  
  ;; Function to calculate right point of a circle
  (defun GetRightPoint (center radius)
    (list (+ (car center) radius) (cadr center) (caddr center))
  )
  
  ;; Create circles
  (setq Circle1 (_circl p1))
  (setq Circle2 (_circl p2))
  
  ;; Get the center points and radii of the circles
  (setq center1 (cdr (assoc 10 (entget Circle1))))
  (setq radius1 (cdr (assoc 40 (entget Circle1))))
  
  (setq center2 (cdr (assoc 10 (entget Circle2))))
  (setq radius2 (cdr (assoc 40 (entget Circle2))))
  
  ;; Calculate the top, bottom, left, and right points
  (setq top1 (GetTopPoint center1 radius1))
  (setq top2 (GetTopPoint center2 radius2))
  
  (setq bottom1 (GetBottomPoint center1 radius1))
  (setq bottom2 (GetBottomPoint center2 radius2))
  
  (setq left1 (GetLeftPoint center1 radius1))
  (setq left2 (GetLeftPoint center2 radius2))
  
  (setq right1 (GetRightPoint center1 radius1))
  (setq right2 (GetRightPoint center2 radius2))
  
  ;; Draw lines between corresponding points
  (command "LINE" top1 top2 "")
  (command "LINE" bottom1 bottom2 "")
  (command "LINE" left1 left2 "")
  (command "LINE" right1 right2 "")
  
  (princ)
)

 

not sure how to mark this as done

0 Likes
Message 4 of 10

marko_ribar
Advisor
Advisor

Give someone that you think posted the best answer you asked question mark "mark as solution" button... That may be applied and to your answer...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 5 of 10

marko_ribar
Advisor
Advisor

You are missing (_circl) sub function in your code...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 6 of 10

Kent1Cooper
Consultant
Consultant

Wow....so complicated!  [And even more so when you supply the missing sub-routine definition.]  It can be something as simple as this:

 

(defun C:2C4QL (/ ctr c1); = 2 Circles, 4 Quadrants by Lines
  (command
    "_.circle" pause pause
    "_.circle" "_non" (setq ctr (getpropertyvalue (setq c1 (entlast)) "Center")) pause
    "_.line"
      "_non" (vlax-curve-getStartPoint c1)
      "_non" (vlax-curve-getStartPoint (entlast))
      ""
    "_.array" (entlast) "" "_polar" "_non" ctr 4 "360" "_yes"
  ); command
  (prin1)
)

 

It does not need to find all the quadrant points on both Circles, nor care about their radii, nor about the endpoints of the Lines other than the first one.  You can specify the radii of the Circles either by screen pick or typing in numbers, and you can draw either the bigger or the smaller one first.

Kent Cooper, AIA
Message 7 of 10

komondormrex
Mentor
Mentor

and another one

(defun c:2_circles_4_lines ( / circle_1 points_list)
	(command "_circle" (setq center (getpoint "\nPick circles center point: ")) pause)
	(setq circle_1 (entlast))
	(command "_circle" center pause)
	(setq points_list (mapcar '(lambda (circle) (mapcar '(lambda (distance) (vlax-curve-getpointatdist circle distance))
							     (list 0 (* 0.25 pi (getpropertyvalue circle "diameter"))
								     (* 0.5 pi (getpropertyvalue circle "diameter"))
								     (* 0.75 pi (getpropertyvalue circle "diameter"))
							     )
					  	    )
				   )
				   (list circle_1 (entlast))
			  )
	)
	(mapcar '(lambda (point_1 point_2) (vla-addline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
			  	   			(vlax-3d-point point_1) (vlax-3d-point point_2)
					   )
		 )
		 (car points_list) (cadr points_list)
	)
  	(princ)
)
0 Likes
Message 8 of 10

john.uhden
Mentor
Mentor

@Kent1Cooper ,

I like that variation because you demonstrate the use of (from my point of view) a little used command (which function we know you love to use).

I was thinking of drawing two lines then trimming the inside of the smaller circle.  But all the answers are good.

Looks like a life saver from the Titanic.

John F. Uhden

0 Likes
Message 9 of 10

calderg1000
Mentor
Mentor

Regards @rpajounia 

Try this codes...

 

;;;___
(defun c:AddC1 (/ p r1 r2 n p1 p2 p3 p4 lp1 lp2 lp3 lp4)
  (setq
    spm (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
  )
  (setq p  (getpoint "\nPick Point Circles Center...:")
        r1 (getreal "\nEnter Radius Circle Minor...:")
        r2 (getreal "\nEnter Radius Circle Major...:")
  )
  (foreach n (list r1 r2)
    (vla-addcircle spm (vlax-3d-point p) n)
    (setq p1  (mapcar '+ p (mapcar '(lambda (j) (* n j)) '(1 0)))
          lp1 (cons p1 lp1)
          p2  (mapcar '+ p (mapcar '(lambda (j) (* n j)) '(0 1)))
          lp2 (cons p2 lp2)
          p3  (mapcar '+ p (mapcar '(lambda (j) (* n j)) '(-1 0)))
          lp3 (cons p3 lp3)
          p4  (mapcar '+ p (mapcar '(lambda (j) (* n j)) '(0 -1)))
          lp4 (cons p4 lp4)
    )
  )
  (foreach o (list lp1 lp2 lp3 lp4)
    (vla-addline spm (vlax-3d-point (car o)) (vlax-3d-point (cadr o)))
  )
)
;;;___
(defun c:AddC2 (/ p r1 r2 i c ln k)
  (setq p  (getpoint "\nPick Point Circles Center...:")
        r1 (getreal "\nEnter Radius Circle Minor...:")
        r2 (getreal "\nEnter Radius Circle Major...:")
  )
  (foreach i (list r1 r2)
    (setq c  (entmakex (list '(0 . "circle")
                             (cons 10 p)
                             (cons 40 i)
                       )
             )
          ln (cons c ln)
    )
  )
  (foreach k (list 0 (/ pi 2) pi (* 1.5 pi))
    (command "_line"
             (vlax-curve-getpointatparam (car ln) k)
             (vlax-curve-getpointatparam (cadr ln) k)
             ""
    )
  )
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 10 of 10

Kent1Cooper
Consultant
Consultant

@rpajounia wrote:

....

(defun DoubleCircle ( p1 p2 / Circle1 Circle2 ....
....
  ;; Create circles
  (setq Circle1 (_circl p1))
  (setq Circle2 (_circl p2))
  
  ;; Get the center points and radii of the circles
....

And another thing....  Does that routine really work?

 

The p1 and p2 arguments would presumably be points, though we can't tell [nor can we try it out] without seeing the definition of the (_circl) function.  It uses only one argument, so it's hard to imagine how it can draw a Circle -- it would need at least two, for center and radius.  Does (_circl) ask for the one that is not supplied as an argument, requesting User input?

 

The p1 and p2 variables presumably must be different from each other, but what you're drawing needs their centers to be at the same place, so it seems p1 and p2 cannot be their center points.  Are p1 and p2 their radii instead, the one thing about them that differs?  But there's nothing to establish their common center point.  If that's left to User input having (_circl) ask for the center, it's asking unnecessarily for the center for each of them, when it should be re-using the first center for the second Circle.

 

And there should be no "Get the center points and radii" [part of line 7 above] -- the centers are the same for both anyway, and they and the radii must already be known by then, either as p1 and p2 or as requested from the User in the (_circl) function.

Kent Cooper, AIA
0 Likes