Author Topic: Ellipse to Line Help  (Read 2872 times)

0 Members and 1 Guest are viewing this topic.

A_LOTA_NOTA

  • Guest
Ellipse to Line Help
« on: October 30, 2007, 08:08:24 AM »
Thanks I got it! :-)
« Last Edit: October 30, 2007, 09:29:25 AM by A_LOTA_NOTA »

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Re: Ellipse to Line Help
« Reply #1 on: October 30, 2007, 04:17:53 PM »
Would it be possible to post your question and your solution to help other members in the future

Thanks
T :-)
Thanks for explaining the word "many" to me, it means a lot.

LE

  • Guest
Re: Ellipse to Line Help
« Reply #2 on: October 30, 2007, 07:32:34 PM »
Tracey;

The easiest way [or another form] to convert an Ellipse to lines is:

1. Call the DXFOUT and use the R12 DXF
2. Open a new drawing from scratch and call DXFIN
3. Explode the ellipse object.
4. There you have the lines.

Adesu

  • Guest
Re: Ellipse to Line Help
« Reply #3 on: October 31, 2007, 03:58:19 AM »
Hi A_LOTA_NOTA,
Here a sample code it's my concept
Code: [Select]
; cetl is stand for Convert Ellipse To Line
;        Design by  : Adesu <Ade Suharna>
;        Email      : mteybid@yuasabattery.co.id
;        Homepage   : http://www.yuasa-battery.co.id
;        Create     : 27 September 2006
;        Program no.: 0437/09/2006
;        Edit by    :

(defun c:cetl (/ cmt cnt len lst opt spt ss sse ssl ssn ssp)
  (setq ss (car (entsel "\nSelect an ellipse")))
  (setq opt (getreal "\nEnter number of segment <12>: "))
  (if
    (= opt nil)
    (setq opt 12)
    (setq opt (fix opt))                                    ; 1).
    )                                     ; repeat
  (command "_divide" ss opt "")
  (setq ssp (ssget "x" '((0 . "point"))))
  (setq ssl (sslength ssp))
  (setq cnt 0)
  (repeat
    ssl
    (setq ssn (ssname ssp cnt))
    (setq sse (entget ssn))
    (setq spt (cdr (assoc 10 sse)))
    (setq lst (append lst (list spt)))
    (command "_erase" ssn "")
    (setq cnt (1+ cnt))
    )                                     ; repeat
  (command "_erase" ss "")
  (setq cmt 0)
  (repeat
    ssl
    (command "_line" (nth cmt lst)
     (nth (1+ cmt) lst) "")
    (setq cmt (1+ cmt))
    )                                     ; repeat
  (command "_line" (last lst)(car lst) "")
  (princ)
  )                                       ; defun
 

Thanks I got it! :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Ellipse to Line Help
« Reply #4 on: October 31, 2007, 09:39:31 AM »
IMO, the best way would be to use vlax-curve functions to return a point list which could then be
used to create a pline. The number of points would determine how accurate the trace of the object
was. If you wanted a more accurate trace you would need to determine the bulge of the curve and
create arc pline segments ILO straight segments. This would reduce the number of points needed &
produce a more accurate trace of the object.

My 2 cents. 8-)

PS I seem to remember Joe Burke doing something like this. Maybe not for ellipses though.
« Last Edit: October 31, 2007, 09:41:12 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Ellipse to Line Help
« Reply #5 on: October 31, 2007, 09:44:55 AM »
Tangent: You could also wmfout / in (set view parameters as hi res as possible first). I and others have used this as the partial basis for flatteners in the past.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Joe Burke

  • Guest
Re: Ellipse to Line Help
« Reply #6 on: October 31, 2007, 11:15:35 AM »
Quote
PS I seem to remember Joe Burke doing something like this. Maybe not for ellipses though.

Alan,

The attached TraceObject function works with elliptical objects. It returns a list of points, so creation of a pline is up to the calling function.
« Last Edit: October 31, 2007, 11:18:42 AM by Joe Burke »

Fuccaro

  • Guest
Re: Ellipse to Line Help
« Reply #7 on: November 04, 2007, 02:15:04 PM »
I wrote a short lisp to transform a spline ellipse into a polyline ellipse. The routine was published at that time in the CADTutor forum. Here is the code:
Code: [Select]
;| Transforms a spline ellipse into a polyline ellipse
 mfuccaro@hotmail.com  AUGUST 2004
-------------------------------------------------------------
|;
(defun c:e2p( /
     old new ;existent and new polyline
     sav ;store system variables
     cen ;center of ellipse
     dep ;axis end point deplacement (relative to cen)
     p1 p2 ;first axis enpoints
     p3 ;sec. axis endpoint
    )
  (setq old (car (entsel "\n select ellipse to change ")))
  (while old
    (if (= (cdr (assoc 0 (entget old))) "ELLIPSE")
      (progn
(setq sav (mapcar 'getvar '("PELLIPSE" "OSMODE" "UCSICON"))
      cen (cdr (assoc 10 (entget old)))
      dep (cdr (assoc 11 (entget old))))
(mapcar 'setvar '("PELLIPSE" "OSMODE" "UCSICON") '(1 0 0))
(command "UCS" "e" old)
(setq p1 (trans (list (+ (car cen) (car dep))
      (+ (cadr cen) (cadr dep))
      (+ (caddr cen) (caddr dep)))
0 1)
      p2 (trans (list (- (car cen) (car dep))
      (- (cadr cen) (cadr dep))
      (- (caddr cen) (caddr dep)))
0 1)
      p3 (trans (polar cen
       (+ (/ PI 2.0) (angle p1 p2))
       (* 0.5 (cdr (assoc 40 (entget old))) (distance p1 p2)))
0 1)
      )
(command "ellipse" p1 p2 p3)
(setq new (entget (entlast))
      new (subst (cons 8 (cdr (assoc 8 (entget old)))) (assoc 8 new) new))
(entmod new)
(entdel old)
(command "ucs" "p")
(mapcar 'setvar '("PELLIPSE" "OSMODE" "UCSICON") sav)
)
      (alert "This is not a spline ellipse!")
      )
    (setq old (car (entsel "\n next ellipse -or none for exit ")))
    )
(princ)
   )

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Ellipse to Line Help
« Reply #8 on: November 04, 2007, 03:59:14 PM »
Hi,

Here're my 2 cents

First one, to change (el2pl) a true ellipse (or an elliptical arc) into a polyline or to draw (pell) a pline figuring an ellipse (or an elliptical arc).

Code: [Select]
;; ELLIPSE->POLYLINE
;; Tranform an ellipse (or an elliptical arc) into a polyline
;;
;; Arguement
;; ent : an ellipse (ename)

(defun ellipse->polyline (ent / os ec pe elst cen ext pa1 pa2 grd prd ang pt1
  pt2 mat ss)
  (setq ec   (getvar "cmdecho")
pe   (getvar "pellipse")
elst (entget ent)
cen  (trans (cdr (assoc 10 elst)) 0 1)
ext  (mapcar '+ cen (cdr (assoc 11 elst)))
pa1  (cdr (assoc 41 elst))
pa2  (cdr (assoc 42 elst))
grd  (distance cen ext)
prd  (* grd (cdr (assoc 40 elst)))
ang  (- (angle cen ext)
(angle '(0 0 0) (getvar "ucsxdir"))
     )
  )
  (entdel ent)
  (setvar "cmdecho" 0)
  (setvar "pellipse" 1)
  (command "_.ellipse" "_c" cen (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))
      )
      (if (clockwise-p cen pt1 ext)
(command "_.mirror"
ent
""
cen
(polar cen (+ (/ pi 2) ang) 1.0)
"_y"
)
      )
      (command "_.break" ent "_non" pt2 "_non" pt1)
      (setq ss (ssadd)
    ent (entnext ent)
      )
      (while ent
(ssadd ent ss)
(setq ent (entnext ent))
      )
      (command "_.pedit" "_m" ss "" "_j" "" "")
    )
  )
  (command "_.convert" "_p" "_s" (entlast) "")
  (setvar "cmdecho" ec)
  (setvar "pellipse" pe)
)

;;; Clockwise-p
;;; Return T if p1 p2 et p3 are clockwise

(defun clockwise-p (p1 p2 p3)
  (< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14)
)

;;===================================================;;

;; PELL
;; Creats a polyline figuring an ellipse (or an elliptical arc)

(defun c:pell (/ erreur ec pe old)

  (defun erreur (msg)
    (if (= msg "Fonction annulée")
      (princ)
      (princ (strcat "\nErreur: " msg))
    )
    (setvar "cmdecho" ec)
    (setvar "pellipse" pe)
    (setq *error* m:err
  m:err nil
    )
    (princ)
  )

  (setq ec (getvar "cmdecho")
pe (getvar "pellipse")
m:err *error*
*error* erreur
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)
  (setq *error* m:err
m:err nil
  )
  (princ)
)

;;===================================================;;

;; EL2PL
;; Change ellipses (or an elliptical arc) into polylines
(defun c:el2pl (/ ss n)
  (if (setq n  0
    ss (ssget '((0 . "ELLIPSE")))
      )
    (repeat (sslength ss)
      (ellipse->polyline (ssname ss n))
      (setq n (1+ n))
    )
  )
  (princ (strcat "\n\t"
(itoa n)
" ellipse(s) changées en polylignes"
)
  )
  (princ)
)

Second one, to get a list of points (current UCS coordinates) along an ellipse.
The example returns 51 points but this can be changed according to what you need

Code: [Select]
;; Return a list of 51 points (current UCS coordinates) along an ellipse

(defun ellipse2points (el / elst   norm    cen     majax
       minax stratang startpar incang   matrix   plst
      )
  (setq elst (entget el)
norm (cdr (assoc 210 elst))
cen (trans (cdr (assoc 10 elst)) 0 norm)
majax (distance '(0 0 0) (cdr (assoc 11 elst)))
minax (* majax (cdr (assoc 40 elst)))
startang (angle '(0 0 0) (trans (cdr (assoc 11 elst)) 0 norm))
startpar (cdr (assoc 41 elst))
incang (/ (- (cdr (assoc 42 elst)) startpar) 50)
matrix (list (list (cos startang) (- (sin startang)) 0)
       (list (sin startang) (cos startang) 0)
       '(0 0 1)
)
  )
  (repeat (setq n 51)
    (setq n    (1- n)
  plst (cons
(trans
   (mapcar '+
   cen
   (mxv matrix
(list (* majax (cos (+ startpar (* n incang))))
      (* minax (sin (+ startpar (* n incang))))
      0.0
)
   )
   )
   norm
   1
)
plst
       )
    )
  )
)

;; Apply a transformation matrix to a vector (Vladimir Nesterovsky)
(defun mxv (m v)
  (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m)
)

;;=========================================================================;;

(defun c:test (/ ent osmo echo)
  (if
    (and
      (setq ent (car (entsel)))
      (= "ELLIPSE" (cdr (assoc 0 (entget ent))))
    )
     (progn
       (setq osmo (getvar "osmode"))
       (setq echo (getvar "cmdecho"))
       (setvar "osmode" 0)
       (setvar "cmdecho" 0)
       (command "_pline")
       (mapcar 'command (ellipse2points ent))
       (command)
       (setvar "osmode" osmo)
       (setvar "cmdecho" echo)
     )
  )
  (princ)
)
Speaking English as a French Frog

fools

  • Newt
  • Posts: 72
  • China
Re: Ellipse to Line Help
« Reply #9 on: August 04, 2008, 09:07:35 PM »
Tangent: You could also wmfout / in (set view parameters as hi res as possible first). I and others have used this as the partial basis for flatteners in the past.
How to set  view parameters as hi as possible?
Thx
Good good study , day day up . Sorry about my Chinglish .