Jump to content

Convert Ellipse to Arcs


jammie

Recommended Posts

Hi all,

 

I am currently working on a drawing that has been done using ellipses instead of arcs. I need to create a polyline so I can take off an area

 

The major and minor radii of the ellipses are equal.

 

I was hoping to be able to extact the relvant properties from an ellipse and produce an arc at its location. Here is a routine I have been working on but it does not work correctly.

 

It inserts an arc with the correct radius but there seems to be a problem with the start and end angles

 

 

(defun ellipse->arc ();/ SS LI_ENAME ACADOBJ acaddoc acadms PASS FAIL radius OBJ StartAngle EndAngle Center)


 (if
   (and
     (setq ss (ssget '((0 . "ellipse"))))
     (setq li_enames (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
     )

   (progn
 ;Load ActiveX Support


 (vl-load-com)
 (setq acadobj  (vlax-get-acad-object)
acaddoc	 (vla-get-activeDocument acadobj )
acadms 	 (vla-get-modelspace acaddoc)
pass  0
fail  0
)

 (FOREACH N li_enames
   (setq obj (vlax-ename->vla-object n))

      
   (if
     (equal
(vla-get-RadiusRatio obj) 1 0.0001)

     (progn

(setq  radius     (vla-get-MajorRadius obj )
       StartAngle (vla-get-StartAngle OBJ)
       EndAngle   (vla-get-EndAngle obj)
       Center     (vla-get-Center obj)
       )

(vla-addarc acadms Center radius StartAngle EndAngle  )
(entdel n)
(setq pass (1+ pass))
)

     (setq fail (1+ fail))
     )
   )

 (alert (strcat "\n<" (rtos pass 2 0) "> Ellipse objects converted to Arcs" )
 (strcat "\n<" (rtos fail 2 0) "> Ellipse objects failed to be converted" ))
 )
   (alert "\No Ellipses selected")
   )
  )

 

Any help would be greatly appreciated

 

Thanks

 

Jammie

Link to comment
Share on other sites

Could you be a little more detailed in what you want to accomplish.

If drawing an ellipse set the AutoCAD system variable pellipse to 1 so when you draw an ellipse it is made with a polyline.

If an ellipse is in the drawing you can save it down to the lowest DXF like R12 then open it back up and the ellipse will be converted to a polyline.

There are many methods that can be used to make an ellipse. I believe the math AutoCAD uses will use about 8 – 10 different arcs to make an ellipse.

Link to comment
Share on other sites

Thanks John,

 

I didn't create the drawing myself. I just need to do an area check. The particular boundary that I needed was drawn using lines and ellipses

 

 

If an ellipse is in the drawing you can save it down to the lowest DXF like R12 then open it back up and the ellipse will be converted to a polyline.

 

That worked fine for finding the area I required,

 

Thanks

 

-Jammie

Link to comment
Share on other sites

I don’t know exactly what you are doing but you might want to check out the boundary command. If an area is closed you can create a boundary the list the area and perimeter

Type –boundary (hyphen boundary) then pick a point inside the closed area and it will create a polyline outline of the area then you can use list last to get info or have lisp do it for you.

Note: if the area contains a ellipse you will be asked to create a region and then you can get info

Link to comment
Share on other sites

I don’t know exactly what you are doing

 

Hah I spend most of the day wondering that myself...

 

Note: if the area contains a ellipse you will be asked to create a region and then you can get info

 

Creating a region works very well.

 

Interestingly AutoCAD seems to convert the ellipses to arcs when creating the region. (I am positive they are ellipses though)

 

When I explode the region, it creates a series of ARCs and lines

 

-Jammie

Link to comment
Share on other sites

Jammie

Click this link, maybe you can find something usefull on that page:

http://www.cadtutor.net/forum/showthread.php?t=1639&

 

fuccaro,

 

That is an interesting thread and very nice work on the routine to convert an ellipse to a pline.

 

That also explains why offsetting an ellipse creates a spline

 

Thanks for your help

 

Jammie

Link to comment
Share on other sites

I think you look for like this code

(defun c:e2a (/ acaddoc acadms acadobj center endangle obj radius ss ssn startangle)
 (vl-load-com)
 (if 
   (setq ss (ssget '((0 . "ellipse"))))
   (progn      
     (setq acadobj (vlax-get-acad-object))
     (setq acaddoc (vla-get-activeDocument acadobj))
     (setq acadms (vla-get-modelspace acaddoc))
     (setq ssn (ssname ss 0))
     (setq obj (vlax-ename->vla-object ssn))
     (if
obj ;(equal (vla-get-RadiusRatio obj) 1 0.0001)
(progn
  (setq radius (vla-get-MajorRadius obj))
  (setq StartAngle (vla-get-StartAngle OBJ))
  (setq EndAngle (vla-get-EndAngle obj))
  (setq Center (vlax-get obj 'center))
  (entdel ssn)
  (vla-addarc acadms (vlax-3d-point Center) radius StartAngle EndAngle)
  ) ; progn
(alert "> Ellipse objects failed to be converted")
)   ; if
     )     ; progn
   )       ; if
 (princ)
 )       ; defun

 

Hi all,

 

I am currently working on a drawing that has been done using ellipses instead of arcs. I need to create a polyline so I can take off an area

 

The major and minor radii of the ellipses are equal.

 

I was hoping to be able to extact the relvant properties from an ellipse and produce an arc at its location. Here is a routine I have been working on but it does not work correctly.

 

It inserts an arc with the correct radius but there seems to be a problem with the start and end angles

 

 

(defun ellipse->arc ();/ SS LI_ENAME ACADOBJ acaddoc acadms PASS FAIL radius OBJ StartAngle EndAngle Center)


 (if
   (and
     (setq ss (ssget '((0 . "ellipse"))))
     (setq li_enames (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
     )

   (progn
 ;Load ActiveX Support


 (vl-load-com)
 (setq acadobj  (vlax-get-acad-object)
acaddoc	 (vla-get-activeDocument acadobj )
acadms 	 (vla-get-modelspace acaddoc)
pass  0
fail  0
)

 (FOREACH N li_enames
   (setq obj (vlax-ename->vla-object n))

      
   (if
     (equal
(vla-get-RadiusRatio obj) 1 0.0001)

     (progn

(setq  radius     (vla-get-MajorRadius obj )
       StartAngle (vla-get-StartAngle OBJ)
       EndAngle   (vla-get-EndAngle obj)
       Center     (vla-get-Center obj)
       )

(vla-addarc acadms Center radius StartAngle EndAngle  )
(entdel n)
(setq pass (1+ pass))
)

     (setq fail (1+ fail))
     )
   )

 (alert (strcat "\n<" (rtos pass 2 0) "> Ellipse objects converted to Arcs" )
 (strcat "\n<" (rtos fail 2 0) "> Ellipse objects failed to be converted" ))
 )
   (alert "\No Ellipses selected")
   )
  )

 

Any help would be greatly appreciated

 

Thanks

 

Jammie

Link to comment
Share on other sites

I think you look for like this code

Code:

 

(defun c:e2a (/ acaddoc acadms acadobj center endangle obj radius ss ssn startangle)

(vl-load-com)

(if

(setq ss (ssget '((0 . "ellipse"))))

(progn

(setq acadobj (vlax-get-acad-object))

(setq acaddoc (vla-get-activeDocument acadobj))

(setq acadms (vla-get-modelspace acaddoc))

(setq ssn (ssname ss 0))

(setq obj (vlax-ename->vla-object ssn))

(if

obj ;(equal (vla-get-RadiusRatio obj) 1 0.0001)

(progn

(setq radius (vla-get-MajorRadius obj))

(setq StartAngle (vla-get-StartAngle OBJ))

(setq EndAngle (vla-get-EndAngle obj))

(setq Center (vlax-get obj 'center))

(entdel ssn)

(vla-addarc acadms (vlax-3d-point Center) radius StartAngle EndAngle)

) ; progn

(alert "> Ellipse objects failed to be converted")

) ; if

) ; progn

) ; if

(princ)

) ; defun

 

 

Adesu,

 

I have just tested your code and it works very well. It converts the ellipses to arcs which is exactly what I was hoping for.

 

Thank you for you help

 

Regards,

 

Jammie

Link to comment
Share on other sites

Ahh....I very glad can help one.

 

Adesu,

 

I have just tested your code and it works very well. It converts the ellipses to arcs which is exactly what I was hoping for.

 

Thank you for you help

 

Regards,

 

Jammie

Link to comment
Share on other sites

  • 7 months later...

If I'm not asking to much, could You convert that to vba?

 

Thank You

I think you look for like this code

(defun c:e2a (/ acaddoc acadms acadobj center endangle obj radius ss ssn startangle)
 (vl-load-com)
 (if 
   (setq ss (ssget '((0 . "ellipse"))))
   (progn      
     (setq acadobj (vlax-get-acad-object))
     (setq acaddoc (vla-get-activeDocument acadobj))
     (setq acadms (vla-get-modelspace acaddoc))
     (setq ssn (ssname ss 0))
     (setq obj (vlax-ename->vla-object ssn))
     (if
   obj ;(equal (vla-get-RadiusRatio obj) 1 0.0001)
   (progn
     (setq radius (vla-get-MajorRadius obj))
     (setq StartAngle (vla-get-StartAngle OBJ))
     (setq EndAngle (vla-get-EndAngle obj))
     (setq Center (vlax-get obj 'center))
     (entdel ssn)
     (vla-addarc acadms (vlax-3d-point Center) radius StartAngle EndAngle)
     ) ; progn
   (alert "> Ellipse objects failed to be converted")
   )   ; if
     )     ; progn
   )       ; if
 (princ)
 )       ; defun

Link to comment
Share on other sites

  • 5 years later...
I think you look for like this code

(defun c:e2a (/ acaddoc acadms acadobj center endangle obj radius ss ssn startangle)
 (vl-load-com)
 (if 
   (setq ss (ssget '((0 . "ellipse"))))
   (progn      
     (setq acadobj (vlax-get-acad-object))
     (setq acaddoc (vla-get-activeDocument acadobj))
     (setq acadms (vla-get-modelspace acaddoc))
     (setq ssn (ssname ss 0))
     (setq obj (vlax-ename->vla-object ssn))
     (if
obj ;(equal (vla-get-RadiusRatio obj) 1 0.0001)
(progn
  (setq radius (vla-get-MajorRadius obj))
  (setq StartAngle (vla-get-StartAngle OBJ))
  (setq EndAngle (vla-get-EndAngle obj))
  (setq Center (vlax-get obj 'center))
  (entdel ssn)
  (vla-addarc acadms (vlax-3d-point Center) radius StartAngle EndAngle)
  ) ; progn
(alert "> Ellipse objects failed to be converted")
)   ; if
     )     ; progn
   )       ; if
 (princ)
 )       ; defun

 

When I ran this .lsp app, the end points do not match the original end points for the ellipse. Is there a quick fix in the code that will fix this?

 

Thanks!

 

Richard

Link to comment
Share on other sites

You could perhaps try my Ellipse to Arc program here.

 

Lee

 

Thank you, Lee Mac! Shortly after posting my question, I found that same link! Very helpful and exactly what I was looking for! Have a great day!

 

Richard

Link to comment
Share on other sites

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