JovanG Posted February 26, 2021 Share Posted February 26, 2021 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 Quote Link to comment Share on other sites More sharing options...
pkenewell Posted February 26, 2021 Share Posted February 26, 2021 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) ) 2 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted February 26, 2021 Share Posted February 26, 2021 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) ) 1 1 Quote Link to comment Share on other sites More sharing options...
pkenewell Posted February 26, 2021 Share Posted February 26, 2021 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. Quote Link to comment Share on other sites More sharing options...
JovanG Posted February 26, 2021 Author Share Posted February 26, 2021 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. 1 Quote Link to comment Share on other sites More sharing options...
pkenewell Posted February 26, 2021 Share Posted February 26, 2021 (edited) 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 February 26, 2021 by pkenewell 1 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 27, 2021 Share Posted February 27, 2021 For what it's worth, here's an existing program to handle elliptical arcs too. 4 Quote Link to comment Share on other sites More sharing options...
JovanG Posted March 1, 2021 Author Share Posted March 1, 2021 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. 1 Quote Link to comment Share on other sites More sharing options...
buzzerknocker Posted August 1, 2022 Share Posted August 1, 2022 These are great, and Lee's arc version too.. Keep up the great work guys 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.