# Is it possible to convert an ellipse to a circle with autolisp

## Recommended Posts

Hello everyone.

I wonder if there is a way to convert an ellipse to a circle with the help of autolisp. I have a DWG that contains some circles and ellipses in coordinate representation. But I have noticed that even when the minor radius is equal to the major radius (apparently a circle), the center coordinate that appears in the properties is not the same that I have inserted. So, I believe that if I change the ellipse to circle problem will be solved.

Thank you in advance for your time and help. Have a nice day

##### Share on other sites

Here is a function to do it. Note - this only works if the Major to Minor radius ratio is 1 (in other words - looks like a circle). If you want it different then let me know.

```(defun C:EL2CIR (/ cen cnt en ent maj mad)
(if (setq ss (ssget '((0 . "ELLIPSE"))))
(repeat (setq cnt (sslength ss))
(setq ent (entget (setq en (ssname ss (setq cnt (1- cnt)))))
cen (cdr (assoc 10 ent))
maj (cdr (assoc 11 ent))
mad (distance '(0.0 0.0 0.0) maj)
)
(if (= (cdr (assoc 40 ent)) 1.0)
(progn
(entdel en)
)
)
)
)
(princ)
)```

##### Share on other sites
18 minutes ago, pkenewell said:

Here is a function to do it. Note - this only works if the Major to Minor radius ratio is 1 (in other words - looks like a circle). If you want it different then let me know.

```
(defun C:EL2CIR (/ cen cnt en ent maj mad)
(if (setq ss (ssget '((0 . "ELLIPSE"))))
(repeat (setq cnt (sslength ss))
(setq ent (entget (setq en (ssname ss (setq cnt (1- cnt)))))
cen (cdr (assoc 10 ent))
maj (cdr (assoc 11 ent))
mad (distance '(0.0 0.0 0.0) maj)
)
(if (= (cdr (assoc 40 ent)) 1.0)
(progn
(entdel en)
)
)
)
)
(princ)
)```

Nice  .. FWIW if you create the circle like so it will retain all by object properties too:

```(defun c:el2cir	(/ cen cnt en ent maj mad)
(if (setq ss (ssget '((0 . "ELLIPSE"))))
(repeat (setq cnt (sslength ss))
(setq ent	(entget (setq en (ssname ss (setq cnt (1- cnt)))) '("*"))
cen	(cdr (assoc 10 ent))
maj	(cdr (assoc 11 ent))
mad	(distance '(0.0 0.0 0.0) maj)
)
(if (= (cdr (assoc 40 ent)) 1.0)
;; (progn (command "._circle" "_non" cen mad) (entdel en))
(and (entmake
(append
'((0 . "CIRCLE"))
(vl-remove-if '(lambda (x) (vl-position (car x) '(-1 0 100 330 5 11 40 41 42))) ent)
)
)
(entdel en)
)
)
)
)
(princ)
)```

• 1
• 1

##### Share on other sites
20 minutes ago, ronjonp said:

Nice  .. FWIW if you create the circle like so it will retain all by object properties too:

Very Nice @ronjonp! Very efficient way to retain the original layer, linetype, color, etc.

##### Share on other sites

It works like a charm! I really thank you @pkenewell and @ronjonp.

Just in some cases it didn`t works but it was because Major to minor radius ratio was apparently diffetent of 1, so I just deleted the conditional and it works great.

##### Share on other sites
54 minutes ago, JovanG said:

so I just deleted the conditional and it works great.

FWIW rather than deleting the conditional, you could use the "equal" function with a fuzz factor, if the ellipses are only off by a small amount. depends on whether you need to prevent changing an ellipse that is supposed to be an ellipse.

I.e. this:

```(setq fuz 0.005) ;; Set error fuzz value
(if (equal (cdr (assoc 40 ent)) 1.0 fuz)```

`(if (= (cdr (assoc 40 ent)) 1.0)`
Edited by pkenewell

##### Share on other sites

For what it's worth, here's an existing program to handle elliptical arcs too.

##### Share on other sites
On 2/26/2021 at 4:43 PM, pkenewell said:

rather than deleting the conditional, you could use the "equal" function with a fuzz factor

That`s a great idea @pkenewell, thank you a lot for your help.

## 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.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.