Sorry, I forgot joining mxv routine.
Here's a new (better) version which works whatever the ellipses construction plane and current UCS.
{code};; ELLIPSE->POLYLINE
;; ELLIPSE->POLYLINE
;; Converts an ellipse (or an elliptical arc) into a polyline
;;
;; Arguement
;; ent : une ellipse (ename)
(defun ellipse->polyline (ent / elst ucs os ec pe cen ext pa1 pa2 grd prd ang
pt1 pt2 mat line ed)
(setq elst (entget ent))
(or
(equal (trans '(0 0 1) 1 0 T) (cdr (assoc 210 elst)) 1e-9)
(and
(setq ucs T)
(command "_.ucs" "_zaxis" '(0 0 0) (trans (cdr (assoc 210 elst)) ent 1 T))
)
)
(setq ec (getvar "cmdecho")
pe (getvar "pellipse")
elst (entget ent)
cen (cdr (assoc 10 elst))
elv (caddr (trans cen 0 (cdr (assoc 210 elst))))
ext (trans (mapcar '+ cen (cdr (assoc 11 elst))) 0 1)
cen (trans cen 0 1)
pa1 (cdr (assoc 41 elst))
pa2 (cdr (assoc 42 elst))
grd (distance cen ext)
prd (* grd (cdr (assoc 40 elst)))
ang (angle cen ext)
)
(entdel ent)
(setvar "cmdecho" 0)
(setvar "pellipse" 1)
(command "_.ellipse" "_c" "_non" cen "_non" (polar cen ang grd) prd)
(if (or (/= pa1 0.0) (/= pa2 (* 2 pi)))
(progn
(setq ent (entlast)
pt1 (list (* grd (cos pa1)) (* prd (sin pa1)))
pt2 (list (* grd (cos pa2)) (* prd (sin pa2)))
mat (list (list (cos ang) (- (sin ang)) 0)
(list (sin ang) (cos ang) 0)
'(0 0 1)
)
pt1 (mapcar '+ cen (mxv mat pt1))
pt2 (mapcar '+ cen (mxv mat pt2))
)
(command "_.line" "_non" pt1 "_non" pt2 "")
(setq line (entlast))
(cond
((equal ext pt2 1e-9)
(command "_.break" ent "_non" pt1 "_non" pt1)
(entdel (entnext line))
)
((equal ext pt1 1e-9)
(command "_.break" ent "_non" pt2 "_non" pt2)
(entdel (entlast))
)
((< (atof (angtos pa2)) (atof (angtos pa1)))
(setq ed (getvar "EDGEMODE"))
(setvar "EDGEMODE" 1)
(command "_.trim" line "" (polar cen (+ ang pi) grd) "")
(setvar "EDGEMODE" ed)
(command "_.pedit" (entlast) "_j" (entnext line) "" "")
)
(T
(setq ed (getvar "EDGEMODE"))
(setvar "EDGEMODE" 1)
(command "_.trim" line "" ext "")
(setvar "EDGEMODE" ed)
)
)
(entdel line)
)
)
(command "_.convert" "_p" "_s" (entlast) "")
(and ucs (command "_.ucs" "_previous"))
(setvar "cmdecho" ec)
(setvar "pellipse" pe)
)
;;===================================================;;
;; MXV
;; Applies a transformation matrix to a vector -Vladimir Nesterovsky-
;;
;; Arguments : a matrix and a vector
(defun mxv (m v)
(mapcar (function (lambda (r) (apply '+ (mapcar '* r v)))) m)
)
;;===================================================;;
;; ELP
;; Creates a polyline figuring an ellipse (or an elliptical arc)
(defun c:elp (/ *error* ec pe old ent)
(defun *error* (msg)
(if (= msg "Function cancelled")
(princ)
(princ (strcat "\nError: " msg))
)
(setvar "cmdecho" ec)
(setvar "pellipse" pe)
(princ)
)
(setq ec (getvar "cmdecho")
pe (getvar "pellipse")
old (entlast)
)
(setvar "cmdecho" 1)
(setvar "pellipse" 0)
(command "_.ellipse")
(while (/= 0 (getvar "cmdactive"))
(command pause)
)
(if (not (eq old (setq ent (entlast))))
(ellipse->polyline ent)
)
(setvar "cmdecho" ec)
(setvar "pellipse" pe)
(princ)
)
;;===================================================;;
;; EL2PL
;; Converts a selection set of ellipses (or an elliptical arcs) into
polylines
(defun c:el2pl (/ ss n)
(setq n 0)
(if (setq ss (ssget '((0 . "ELLIPSE"))))
(progn
(command "_.undo" "_begin")
(repeat (sslength ss)
(ellipse->polyline (ssname ss n))
(setq n (1+ n))
)
(command "_.undo" "_end")
)
)
(princ (strcat "\n\t" (itoa n) " ellipse(s) converted into polyline(s)"
)
)
(princ)
){code}