Jump to content

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


JovanG

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

Link to comment
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
               (command "._circle" "_non" cen mad)
               (entdel en)
            )
         )
      )
   )
   (princ)
)

 

  • Like 2
Link to comment
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
               (command "._circle" "_non" cen mad)
               (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)
		 (list (cons 40 mad))
	       )
	     )
	     (entdel en)
	)
      )
    )
  )
  (princ)
)

 

  • Like 1
  • Thanks 1
Link to comment
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.

Link to comment
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)

instead of this:

(if (= (cdr (assoc 40 ent)) 1.0)
Edited by pkenewell
  • Like 1
Link to comment
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.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...