This version lets you choose the radius type.
(defun c:sq2circle ()
;;return: T if closed, nil otherwise
(defun ispolyclosed (elist)
(= 1 (logand 1 (cdr (assoc 70 (entget elist)))))
)
(defun get_vertex (elist)
(mapcar 'cdr
(vl-remove-if-not
'(lambda (x) (= (car x) 10)) elist))
)
;; ============== START ==================
(initget "Endpoint, Closest, Farthest, Area")
(setq rflag
(getkword
"\nSelect radius type. [Endpoint, <Closest side>, Farthest side, Area]"))
(if (null rflag)
(setq rFlag 1)
(setq rFlag (vl-position rFlag '("Endpoint" "Closest" "Farthest" "Area")))
)
(if (and (setq sq (entsel "\nSelect square to convert to a circle."))
(= (cdr (assoc 0 (setq entlst (entget (setq ent (car sq))))))
"LWPOLYLINE")
(= (length (setq clst (get_vertex entlst))) 4)
(ispolyclosed ent)
)
(progn
;;========================================================
(cond
((= rflag 0); Radius is endpoint of rectangle
(setq rad (/ (distance (nth 0 clst) (nth 2 clst)) 2))
)
((= rflag 1); radius is closest side
(setq rad (/ (min (distance (nth 0 clst) (nth 1 clst))
(distance (nth 1 clst) (nth 2 clst)))2))
)
((= rflag 2); radius is farthest side
(setq rad (/ (max (distance (nth 0 clst) (nth 1 clst))
(distance (nth 1 clst) (nth 2 clst)))2))
)
((= rflag 3); match area of rectangle
(setq rad (/(sqrt(/( * (distance (nth 0 clst) (nth 1 clst))
(distance (nth 1 clst) (nth 2 clst)))
(/ pi 4))) 2))
)
)
;;========================================================
(setq cen (polar (nth 0 clst)
(angle (nth 0 clst) (nth 2 clst))
(/ (distance (nth 0 clst) (nth 2 clst)) 2))
)
(setq opts (list (cons 0 "CIRCLE")
(cons 8 (cdr (assoc 8 entlst))))
)
(if (setq lntyp (assoc 6 entlst))
(setq opts (append opts (list (cons 6 (cdr lntyp)))))
)
(if (setq color (assoc 62 entlst))
(setq opts (append opts (list (cons 62 (cdr color)))))
)
(setq opts (append opts (list(cons 10 cen) (cons 40 rad))))
(if (entmake opts)
(progn
(entdel ent)
(prompt (strcat "\n*-* Radius bases on "
(nth rflag
'("endpoints of rectangle" "closest side"
"farthest side" "area of rectangle")
) " *-*"
)
)
)
(prompt "\nError creating circle.")
)
)
(prompt "\nError, object is not a closed rectangle.")
)
(princ)
)