code to draw a circle

code to draw a circle

andi.lad2909
Explorer Explorer
468 Views
7 Replies
Message 1 of 8

code to draw a circle

andi.lad2909
Explorer
Explorer

I am trying to write a code which helps me to draw a circle at specific point. Can some one help. Attached is the AutoCAD file. Thanks in advance.

0 Likes
469 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant

I could do that but try this first...

 

circle

.y (type this in)

pick the midpoint of lower line

pick the midpoint of top line

radius

 

or the other way around (as you wanted)

circle .x midpt of top line, then lower.

 

This variant coded:

 

(defun c:Cixy nil (command "_.circle" ".x" "_mid" pause "_mid" pause pause) (princ))

 

 

 

 

Message 3 of 8

andi.lad2909
Explorer
Explorer

Actually I am looking a code for this task. Your help will be highly appreciated.

0 Likes
Message 4 of 8

CodeDing
Advisor
Advisor

@andi.lad2909 ,

 

Welcome to the forums! Thank you for providing such a detailed dwg about what you need.

I will provide my solution since it was typed out, but the method @ВeekeeCZ is recommending is probably more practical. My method relies on the assumption that you will ONLY be selecting LINES (no polylines) since polylines present an entirely new dimension to this request.

 

(defun c:CSP ( / e1 eg1 p10 p11 mp e2 eg2 p20 p21 pt)
  ;; Circle @ Specific Point
  (if (and (setq e1 (car (entsel "\nSelect Line for Midpoint: ")))
           (setq eg1 (entget e1))
           (setq p10 (cdr (assoc 10 eg1)) p11 (cdr (assoc 11 eg1)))
           (setq mp (mapcar '* (mapcar '+ p10 p11) '(0.5 0.5 05)))
           (setq e2 (car (entsel "\nSelect line where Circle will reside: ")))
           (setq eg2 (entget e2))
           (setq p20 (cdr (assoc 10 eg2)) p21 (cdr (assoc 11 eg2)))
           (setq pt (inters mp (mapcar '- mp '(0 1 0)) p20 p21 nil))
      );and
    (command "_.CIRCLE" "_non" pt pause)
  );if
  (princ)
);defun

 

Best,

~DD

Message 5 of 8

andi.lad2909
Explorer
Explorer

Thanks for quick help. Both codes are working perfectly. I can use either.

0 Likes
Message 6 of 8

calderg1000
Mentor
Mentor

Regards @andi.lad2909 

Try this code

(defun c:test1( / l1 l2 Xm Ym pc)
  (setq om(getvar 'orthomode))
  (if (= (getvar 'orthomode) 1)
    (setvar 'orthomode 0)
    )
  (setq l1(car(entsel"\nSelect Line 1: "))
        l2(car(entsel"\nSelect Line 2: "))
        Xm (car(mapcar '* (mapcar '+ (cdr (assoc 10 (entget l1))) (cdr (assoc 11 (entget l1)))) '(0.5 0.5 0.)))
        Ym (cadr(cdr (assoc 10 (entget l2))))
        pc(list Xm Ym)
        )
  (vl-cmdf "_circle" "non" pc (getdist pc "\nSpecify Radius: "))
  (setvar 'orthomode om)
  )

 


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 7 of 8

calderg1000
Mentor
Mentor

Here another one with vlax-curve

(defun c:test2 (/ l1 l2 pm px)
  (setq om (getvar 'orthomode))
  (if (= (getvar 'orthomode) 1)
    (setvar 'orthomode 0)
  )
  (setq l1 (vlax-ename->vla-object (car (entsel "\nSelect Line 1: ")))
        l2 (vlax-ename->vla-object (car (entsel "\nSelect Line 2: ")))
  )
  (setq pm (vlax-curve-getpointatparam l1 (/ (vlax-curve-getendparam l1) 2)))
  (setq px (vlax-curve-getclosestpointto l2 pm))
  (entmake (list '(0 . "circle")
                 (cons 10 px)
                 (cons 40 (getdist px "\nSpecify radius:"))
           )
  )
  (setvar 'orthomode om)
)

 


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 8 of 8

andi.lad2909
Explorer
Explorer

@calderg1000 Thank you! Its working.

0 Likes