Jump to content

Trimed ellipse to Polyline


Recommended Posts

Posted

Hi, as I said in other topics, I am developing an application to simplify my work 8)

but still can not make things more complicated alone:cry:

 

The problem is this ...

 

I need to convert the ellipses to polylines, I found this function here on the forum, which makes it, but if the ellipses are trimmed, the conversion makes the complete ellipse.

 

The function:

Without Russian Text

(defun C:E2P (/ adoc el ssnab en item lays lay lock pell ptcen osm count)
 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
 (setq lays (vla-get-layers adoc) count 0)
 (vla-startundomark adoc)
 (princ "\nSelect Ellipse")
 (setq ssnab (ssget '((0 . "ELLIPSE"))))
 (setq pell (getvar "PELLIPSE"))
 (setq osm (getvar "OSMODE"))
 (setvar "OSMODE" 0)
 (setvar "PELLIPSE" 1)
 (while (and ssnab (> (sslength ssnab) 0))
   (setq el (ssname ssnab 0))
   (setq en (vlax-ename->vla-object el))
   (setq lay (vla-item lays (vla-get-layer en)))
   (if (= (vla-get-lock lay) :vlax-true)
     (progn (vla-put-lock lay :vlax-false)
     (setq lock (cons lay lock))))
   (setq item (vla-get-ObjectName en))
   (cond
     ((= item "AcDbEllipse")(setq count (1+ count))
      (setq ptcen (vlax-safearray->list(vlax-variant-value (vla-get-center en))))
      (command "_.ellipse"  "_C" (trans ptcen 0 1)
               (trans (mapcar '+ ptcen (vlax-safearray->list(vlax-variant-value (vla-get-MajorAxis en)))) 0 1)
               (trans (mapcar '+ ptcen (vlax-safearray->list(vlax-variant-value (vla-get-MinorAxis en)))) 0 1))
      (mapcar '(lambda (x y)(vlax-put-property (vlax-ename->vla-object (entlast)) x y))
              '(Linetype LineWeight Color Layer)
              (mapcar '(lambda (x)(vlax-get-property en x))
                      '(Linetype LineWeight Color Layer))
              )
      (vla-Delete en)
     )
     (t nil)
   )
   (ssdel el ssnab)
 )
 (setvar "PELLIPSE" pell)
 (setvar "OSMODE" osm)
 (if lock (foreach x lock (vla-put-lock x :vlax-true)))
 (vla-endundomark adoc)
 (princ (strcat "\nTransformation " (itoa count) " Ellipse is completed"))
 (princ)
)
(princ "\nType E2P to run command")

PS. Corrected

 

You can change this function to the case of the ellipse are trimmed?

 

in my head I think I know how to do it, but pass it to the lisp is that it is complicated ...

 

My Pseudocode:

- Draw a line from the center of the ellipse to the starting point

- Draw a line from the center of the ellipse to the ending point

- Convert the ellipse with the previous routine

- Trim the resultant polyline between the two auxiliary lines

- Delete the auxiliary lines

Posted

I had seen some of these topics, and was to do the rest, but I found what I'm looking :(

Posted

Hi...

I researched and researched and found that these functions seem to work fairly well.

 

I think this is the main function:

;; EL2PL
;; Converts ellipses and elliptcal arcs into polylines

(defun c:el2pl (/ *error* fra acdoc ss)
 (vl-load-com)
 
 (defun *error* (msg)
   (if (and (/= msg "Fonction annulée")
            (/= msg "Function cancelled")
       )
     (princ (strcat (if (= "FRA" (getvar 'locale))
                      "\nErreur: "
                      "\Error: "
                    )
                    msg
            )
     )
   )
   (vla-endUndoMark acdoc)
   (princ)
 )
 (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
 (if (ssget '((0 . "ELLIPSE")))
   (progn
     (vla-StartUndoMark acdoc)
     (vlax-for e (setq ss (vla-get-ActiveSelectionSet acdoc))
       (EllipseToPolyline e)
       (vla-delete e)
     )
     (vla-delete ss)
     (vla-EndUndoMark acdoc)
   )
 )
 (princ)
)

;; PELL
;; Draws an ellipse or an elliptical arc approximation (polyline) on the fly
(defun c:pell (/ *error* ec pe old ent)

 (vl-load-com)
 
 (defun *error* (msg)
   (if (and msg
            (/= msg "Fonction annulée")
            (/= msg "Function cancelled")
       )
     (princ (strcat (if (= "FRA" (getvar 'locale))
                      "\nErreur: "
                      "\Error: "
                    )
                    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))))
   (progn
   (EllipseToPolyline (vlax-ename->vla-object ent))
   (entdel ent)
   )
 )
 (*error* nil)
)

 

And the sub-functions:

;; EllipseToPolyline
;; Returns a polyline (vla-object) which is an approximation of the ellipse (or elliptical arc)
;;
;; Argument : an ellipse (vla-object)

(defun EllipseToPolyline (el    /     cl    norm  cen   elv   pt0   pt1   pt2
                         pt3   pt4   ac0   ac4   a04   a02   a24   bsc0  bsc2
                         bsc3  bsc4  plst  blst  spt   spa   fspa  srat  ept
                         epa   fepa  erat  n
                        )
 (vl-load-com)
 (setq cl   (and (= (vla-get-StartAngle el) 0.0)
                 (= (vla-get-EndAngle el) (* 2 pi))
            )
       norm (vlax-get el 'Normal)
       cen  (trans (vlax-get el 'Center) 0 norm)
       elv  (caddr cen)
       cen  (3dTo2dPt cen)
       pt0  (mapcar '+ (trans (vlax-get el 'MajorAxis) 0 norm) cen)
       ac0  (angle cen pt0)
       pt4  (mapcar '+ cen (trans (vlax-get el 'MinorAxis) 0 norm))
       pt2  (3dTo2dPt (trans (vlax-curve-getPointAtparam el (/ pi 4.)) 0 norm))
       ac4  (angle cen pt4)
       a04  (angle pt0 pt4)
       a02  (angle pt0 pt2)
       a24  (angle pt2 pt4)
       bsc0 (/ (ang<2pi (- a02 ac4)) 2.)
       bsc2 (/ (ang<2pi (- a04 a02)) 2.)
       bsc3 (/ (ang<2pi (- a24 a04)) 2.)
       bsc4 (/ (ang<2pi (- (+ ac0 pi) a24)) 2.)
       pt1  (inters pt0
                    (polar pt0 (+ ac0 (/ pi 2.) bsc0) 1.)
                    pt2
                    (polar pt2 (+ a02 bsc2) 1.)
                    nil
            )
       pt3  (inters pt2
                    (polar pt2 (+ a04 bsc3) 1.)
                    pt4
                    (polar pt4 (+ a24 bsc4) 1.)
                    nil
            )
       plst (list pt4 pt3 pt2 pt1 pt0)
       blst (mapcar '(lambda (b) (tan (/ b 2.)))
                    (list bsc4 bsc3 bsc2 bsc0)
            )
 )
 (foreach b blst
   (setq blst (cons b blst))
 )
 (foreach b blst
   (setq blst (cons b blst))
 )
 (foreach p (cdr plst)
   (setq ang  (angle cen p)
         plst (cons
                (polar cen (+ ang (* 2 (- ac4 ang))) (distance cen p))
                plst
              )
   )
 )
 (foreach p (cdr plst)
   (setq ang  (angle cen p)
         plst (cons
                (polar cen (+ ang (* 2 (- ac0 ang))) (distance cen p))
                plst
              )
   )
 )
 (setq pl
        (vlax-invoke
          (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)))
          'AddLightWeightPolyline
          (apply 'append
                 (setq plst
                        (reverse (if cl
                                   (cdr plst)
                                   plst
                                 )
                        )
                 )
          )
        )
 )
 (vlax-put pl 'Normal norm)
 (vla-put-Elevation pl elv)
 (mapcar '(lambda (i v) (vla-SetBulge pl i v))
         '(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)
         blst
 )
 (if cl
   (vla-put-Closed pl :vlax-true)
   (progn
     (setq spt  (vlax-curve-getClosestPointTo pl (vlax-get el 'Startpoint))
           spa  (vlax-curve-getParamAtPoint pl spt)
           fspa (fix spa)
           ept  (vlax-curve-getClosestPointTo pl (vlax-get el 'Endpoint))
           epa  (vlax-curve-getParamAtPoint pl ept)
           fepa (fix epa)
           n    0
     )
     (cond
       ((equal spt (trans pt0 norm 0) 1e-9)
        (if (= epa fepa)
          (setq plst (sublist plst 0 (1+ fepa))
                blst (sublist blst 0 (1+ fepa))
          )
          (setq erat (/ (- (vlax-curve-getDistAtParam pl epa)
                      (vlax-curve-getDistAtParam pl fepa)
                   )
                   (- (vlax-curve-getDistAtParam pl (1+ fepa))
                      (vlax-curve-getDistAtParam pl fepa)
                   )
                )
                plst (append (sublist plst 0 (1+ fepa))
                             (list (3dTo2dPt (trans ept 0 norm)))
                     )
                blst (append (sublist blst 0 (1+ fepa))
                             (list (k*bulge (nth fepa blst) erat))
                     )
          )
        )
       )
       ((equal ept (trans pt0 norm 0) 1e-9)
        (if (= spa fspa)
          (setq plst (sublist plst fspa nil)
                blst (sublist blst fspa nil)
          )
          (setq srat (/ (- (vlax-curve-getDistAtParam pl (1+ fspa))
                           (vlax-curve-getDistAtParam pl spa)
                        )
                        (- (vlax-curve-getDistAtParam pl (1+ fspa))
                           (vlax-curve-getDistAtParam pl fspa)
                        )
                     )
                plst (cons (3dTo2dPt (trans spt 0 norm))
                           (sublist plst (1+ fspa) nil)
                     )
                blst (cons (k*bulge (nth fspa blst) srat)
                           (sublist blst (1+ fspa) nil)
                     )
          )
        )
       )
       (T
        (setq srat (/ (- (vlax-curve-getDistAtParam pl (1+ fspa))
                           (vlax-curve-getDistAtParam pl spa)
                        )
                        (- (vlax-curve-getDistAtParam pl (1+ fspa))
                           (vlax-curve-getDistAtParam pl fspa)
                        )
                     )
              erat (/ (- (vlax-curve-getDistAtParam pl epa)
                      (vlax-curve-getDistAtParam pl fepa)
                   )
                   (- (vlax-curve-getDistAtParam pl (1+ fepa))
                      (vlax-curve-getDistAtParam pl fepa)
                   )
                )
              )
        (if (< epa spa)
          (setq plst (append
                       (if (= spa fspa)
                         (sublist plst fspa nil)
                         (cons (3dTo2dPt (trans spt 0 norm))
                               (sublist plst (1+ fspa) nil)
                         )
                       )
                       (cdr (sublist plst 0 (1+ fepa)))
                       (if (/= epa fepa)
                         (list (3dTo2dPt (trans ept 0 norm)))
                       )
                     )
                blst (append
                       (if (= spa fspa)
                         (sublist blst fspa nil)
                         (cons 
                           (k*bulge (nth fspa blst) srat)
                               (sublist blst (1+ fspa) nil)
                         )
                       )
                       (sublist blst 0 fepa)
                       (if (= epa fepa)
                         (list (nth fepa blst))
                         (list (k*bulge (nth fepa blst) erat))
                       )
                     )
          )
          (setq plst (append
                       (if (= spa fspa)
                         (sublist plst fspa (1+ (- fepa fspa)))
                         (cons (3dTo2dPt (trans spt 0 norm))
                               (sublist plst (1+ fspa) (- fepa fspa))
                         )
                       )
                       (list (3dTo2dPt (trans ept 0 norm)))
                     )
                blst (append
                       (if (= spa fspa)
                         (sublist blst fspa (- fepa fspa))
                         (cons
                           (k*bulge (nth fspa blst) srat)
                               (sublist blst (1+ fspa) (- fepa fspa))
                         )
                       )
                       (if (= epa fepa)
                         (list (nth fepa blst))
                         (list (k*bulge (nth fepa blst) erat))
                       )
                     )
          )
        )
       )
     )
     (vlax-put pl 'Coordinates (apply 'append plst))
     (foreach b blst
       (vla-SetBulge pl n b)
       (setq n (1+ n))
     )
   )
 )
 pl
)

;; Ang<2pi
;; Returns the angle expression beweem 0 and 2*pi
(defun ang<2pi (ang)
 (if (and (<= 0 ang) (< ang (* 2 pi)))
   ang
   (ang<2pi (rem (+ ang (* 2 pi)) (* 2 pi)))
 )
)

;; 3dTo2dPt
;; Returns the 2d point (x y) of a 3d point (x y z)
(defun 3dTo2dPt (pt) (list (car pt) (cadr pt)))

;; Tan
;; Returns the angle tangent
(defun tan (a) (/ (sin a) (cos a)))

;; SUBLIST 
;; Returns a sub list
;;
;; Arguments
;; lst : a list
;; start : start index (first item = 0)
;; leng : the sub list length (number of items) or nil
(defun sublist (lst start leng / n r)
 (if (or (not leng) (< (- (length lst) start) leng))
   (setq leng (- (length lst) start))
 )
 (setq n (+ start leng))
 (while (< start n)
   (setq r (cons (nth (setq n (1- n)) lst) r))
 )
)

;; K*BULGE
;; Returns the proportinal bulge to the référence bulge
;; Arguments :
;; b : the bulge
;; k : the proportion ratio (between angles or arcs length)
(defun k*bulge (b k / a)
 (setq a (atan b))
 (/ (sin (* k a)) (cos (* k a)))
)

 

my problem now is when the arc of the ellipse has the start point or end point in angles 0 or 180 :( In this case the routine makes the complete ellipse.

 

 

 

one can try to solve this problem? is that for me this is very ahead ...

Posted

I think I've detected the problem, I went to see the code dxf arc that was giving me problems and found the following:

(40 . 0.240816) (41 . -1.87175e-007) (42 . 3.14176))

the value in bold corresponds to the start angle and should be 0 :o it's possible to contour that problem???

Posted
I think I've detected the problem, I went to see the code dxf arc that was giving me problems and found the following:

(40 . 0.240816) (41 . -1.87175e-007) (42 . 3.14176))

the value in bold corresponds to the start angle and should be 0 :o it's possible to contour that problem???

try replacing

 (and (= (vla-get-StartAngle el) 0.0)
                  (= (Vla-get-EndAngle el) (* 2 pi))
             )

on

(and (equal (vla-get-StartAngle el) 0.0 1e-6)
         (equal (vla-get-EndAngle el) (* 2 pi) 1e-6)
             )

Posted
try replacing

 (and (= (vla-get-StartAngle el) 0.0)
                  (= (Vla-get-EndAngle el) (* 2 pi))
             )

on

(and (equal (vla-get-StartAngle el) 0.0 1e-6)
         (equal (vla-get-EndAngle el) (* 2 pi) 1e-6)
             )

 

Gives me that error:

 

Error: bad argument type: numberp: nil

Posted

i mean it

;; EllipseToPolyline
;; Returns a polyline (vla-object) which is an approximation of the ellipse (or elliptical arc)
;;
;; Argument : an ellipse (vla-object)

(defun EllipseToPolyline (el    /     cl    norm  cen   elv   pt0   pt1   pt2
                         pt3   pt4   ac0   ac4   a04   a02   a24   bsc0  bsc2
                         bsc3  bsc4  plst  blst  spt   spa   fspa  srat  ept
                         epa   fepa  erat  n
                        )
 (vl-load-com)
 (setq cl   [color="red"](and (equal (vla-get-StartAngle el) 0.0 1e-6)
                 (equal (vla-get-EndAngle el) (* 2 pi) 1e-6)
            )[/color]
       norm (vlax-get el 'Normal)
       cen  (trans (vlax-get el 'Center) 0 norm)
       elv  (caddr cen)
       cen  (3dTo2dPt cen)
       pt0  (mapcar '+ (trans (vlax-get el 'MajorAxis) 0 norm) cen)
       ac0  (angle cen pt0)
       pt4  (mapcar '+ cen (trans (vlax-get el 'MinorAxis) 0 norm))
       pt2  (3dTo2dPt (trans (vlax-curve-getPointAtparam el (/ pi 4.)) 0 norm))
       ac4  (angle cen pt4)
       a04  (angle pt0 pt4)
       a02  (angle pt0 pt2)
       a24  (angle pt2 pt4)
       bsc0 (/ (ang<2pi (- a02 ac4)) 2.)
       bsc2 (/ (ang<2pi (- a04 a02)) 2.)
       bsc3 (/ (ang<2pi (- a24 a04)) 2.)
       bsc4 (/ (ang<2pi (- (+ ac0 pi) a24)) 2.)
       pt1  (inters pt0
                    (polar pt0 (+ ac0 (/ pi 2.) bsc0) 1.)
                    pt2
                    (polar pt2 (+ a02 bsc2) 1.)
                    nil
            )
       pt3  (inters pt2
                    (polar pt2 (+ a04 bsc3) 1.)
                    pt4
                    (polar pt4 (+ a24 bsc4) 1.)
                    nil
            )
       plst (list pt4 pt3 pt2 pt1 pt0)
       blst (mapcar '(lambda (b) (tan (/ b 2.)))
                    (list bsc4 bsc3 bsc2 bsc0)
            )
 )
 (foreach b blst
   (setq blst (cons b blst))
 )
 (foreach b blst
   (setq blst (cons b blst))
 )
 (foreach p (cdr plst)
   (setq ang  (angle cen p)
         plst (cons
                (polar cen (+ ang (* 2 (- ac4 ang))) (distance cen p))
                plst
              )
   )
 )
 (foreach p (cdr plst)
   (setq ang  (angle cen p)
         plst (cons
                (polar cen (+ ang (* 2 (- ac0 ang))) (distance cen p))
                plst
              )
   )
 )
 (setq pl
        (vlax-invoke
          (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)))
          'AddLightWeightPolyline
          (apply 'append
                 (setq plst
                        (reverse (if cl
                                   (cdr plst)
                                   plst
                                 )
                        )
                 )
          )
        )
 )
 (vlax-put pl 'Normal norm)
 (vla-put-Elevation pl elv)
 (mapcar '(lambda (i v) (vla-SetBulge pl i v))
         '(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)
         blst
 )
 (if cl
   (vla-put-Closed pl :vlax-true)
   (progn
     (setq spt  (vlax-curve-getClosestPointTo pl (vlax-get el 'Startpoint))
           spa  (vlax-curve-getParamAtPoint pl spt)
           fspa (fix spa)
           ept  (vlax-curve-getClosestPointTo pl (vlax-get el 'Endpoint))
           epa  (vlax-curve-getParamAtPoint pl ept)
           fepa (fix epa)
           n    0
     )
     (cond
       ((equal spt (trans pt0 norm 0) 1e-9)
        (if (= epa fepa)
          (setq plst (sublist plst 0 (1+ fepa))
                blst (sublist blst 0 (1+ fepa))
          )
          (setq erat (/ (- (vlax-curve-getDistAtParam pl epa)
                      (vlax-curve-getDistAtParam pl fepa)
                   )
                   (- (vlax-curve-getDistAtParam pl (1+ fepa))
                      (vlax-curve-getDistAtParam pl fepa)
                   )
                )
                plst (append (sublist plst 0 (1+ fepa))
                             (list (3dTo2dPt (trans ept 0 norm)))
                     )
                blst (append (sublist blst 0 (1+ fepa))
                             (list (k*bulge (nth fepa blst) erat))
                     )
          )
        )
       )
       ((equal ept (trans pt0 norm 0) 1e-9)
        (if (= spa fspa)
          (setq plst (sublist plst fspa nil)
                blst (sublist blst fspa nil)
          )
          (setq srat (/ (- (vlax-curve-getDistAtParam pl (1+ fspa))
                           (vlax-curve-getDistAtParam pl spa)
                        )
                        (- (vlax-curve-getDistAtParam pl (1+ fspa))
                           (vlax-curve-getDistAtParam pl fspa)
                        )
                     )
                plst (cons (3dTo2dPt (trans spt 0 norm))
                           (sublist plst (1+ fspa) nil)
                     )
                blst (cons (k*bulge (nth fspa blst) srat)
                           (sublist blst (1+ fspa) nil)
                     )
          )
        )
       )
       (T
        (setq srat (/ (- (vlax-curve-getDistAtParam pl (1+ fspa))
                           (vlax-curve-getDistAtParam pl spa)
                        )
                        (- (vlax-curve-getDistAtParam pl (1+ fspa))
                           (vlax-curve-getDistAtParam pl fspa)
                        )
                     )
              erat (/ (- (vlax-curve-getDistAtParam pl epa)
                      (vlax-curve-getDistAtParam pl fepa)
                   )
                   (- (vlax-curve-getDistAtParam pl (1+ fepa))
                      (vlax-curve-getDistAtParam pl fepa)
                   )
                )
              )
        (if (< epa spa)
          (setq plst (append
                       (if (= spa fspa)
                         (sublist plst fspa nil)
                         (cons (3dTo2dPt (trans spt 0 norm))
                               (sublist plst (1+ fspa) nil)
                         )
                       )
                       (cdr (sublist plst 0 (1+ fepa)))
                       (if (/= epa fepa)
                         (list (3dTo2dPt (trans ept 0 norm)))
                       )
                     )
                blst (append
                       (if (= spa fspa)
                         (sublist blst fspa nil)
                         (cons 
                           (k*bulge (nth fspa blst) srat)
                               (sublist blst (1+ fspa) nil)
                         )
                       )
                       (sublist blst 0 fepa)
                       (if (= epa fepa)
                         (list (nth fepa blst))
                         (list (k*bulge (nth fepa blst) erat))
                       )
                     )
          )
          (setq plst (append
                       (if (= spa fspa)
                         (sublist plst fspa (1+ (- fepa fspa)))
                         (cons (3dTo2dPt (trans spt 0 norm))
                               (sublist plst (1+ fspa) (- fepa fspa))
                         )
                       )
                       (list (3dTo2dPt (trans ept 0 norm)))
                     )
                blst (append
                       (if (= spa fspa)
                         (sublist blst fspa (- fepa fspa))
                         (cons
                           (k*bulge (nth fspa blst) srat)
                               (sublist blst (1+ fspa) (- fepa fspa))
                         )
                       )
                       (if (= epa fepa)
                         (list (nth fepa blst))
                         (list (k*bulge (nth fepa blst) erat))
                       )
                     )
          )
        )
       )
     )
     (vlax-put pl 'Coordinates (apply 'append plst))
     (foreach b blst
       (vla-SetBulge pl n b)
       (setq n (1+ n))
     )
   )
 )
 pl
)

;; Ang<2pi
;; Returns the angle expression beweem 0 and 2*pi
(defun ang<2pi (ang)
 (if (and (<= 0 ang) (< ang (* 2 pi)))
   ang
   (ang<2pi (rem (+ ang (* 2 pi)) (* 2 pi)))
 )
)

;; 3dTo2dPt
;; Returns the 2d point (x y) of a 3d point (x y z)
(defun 3dTo2dPt (pt) (list (car pt) (cadr pt)))

;; Tan
;; Returns the angle tangent
(defun tan (a) (/ (sin a) (cos a)))

;; SUBLIST 
;; Returns a sub list
;;
;; Arguments
;; lst : a list
;; start : start index (first item = 0)
;; leng : the sub list length (number of items) or nil
(defun sublist (lst start leng / n r)
 (if (or (not leng) (< (- (length lst) start) leng))
   (setq leng (- (length lst) start))
 )
 (setq n (+ start leng))
 (while (< start n)
   (setq r (cons (nth (setq n (1- n)) lst) r))
 )
)

;; K*BULGE
;; Returns the proportinal bulge to the rйfйrence bulge
;; Arguments :
;; b : the bulge
;; k : the proportion ratio (between angles or arcs length)
(defun k*bulge (b k / a)
 (setq a (atan b))
 (/ (sin (* k a)) (cos (* k a)))
)

Posted

Hi-

If you have Express tools loaded there is a great function that will convert an ellipse into a pline. I like the simplicity of it. Try it. Load this at the command line and pick an ellipse. That's it. You can add this to a lisp routine and enhance it.

 

(ACET-GEOM-ELLIPSE-TO-PLINE (car (entsel)))

 

Some people will argue about using Express tool functions because not everyone has Express tools. I can respect that, but as for me I like using them. I hope that helps.

 

jsowinski

Posted
Hi-

If you have Express tools loaded there is a great function that will convert an ellipse into a pline. I like the simplicity of it. Try it. Load this at the command line and pick an ellipse. That's it. You can add this to a lisp routine and enhance it.

 

(ACET-GEOM-ELLIPSE-TO-PLINE (car (entsel)))

 

Some people will argue about using Express tool functions because not everyone has Express tools. I can respect that, but as for me I like using them. I hope that helps.

 

jsowinski

 

wow.... so simple and efficient... I'll try to make a function with this command

Posted

Hi...

I ventured to make a routine alone and gave it:

(
defun c:elixp ( / el i en )

(vl-load-com)

  (setq el (ssget "_X" '((0 . "ELLIPSE")))
  )           


(if el
   (progn
     (princ(strcat "\n" (itoa(sslength el)) " found."))
     (sssetfirst nil el)
     ); end progn
    (princ "\nNothing found. ")
   ); end if

(repeat (setq i (sslength el))
           (setq en (entget (ssname el (setq i (1- i)))))
           (ACET-GEOM-ELLIPSE-TO-PLINE (car (entsel)))
       );end repeat

)

and the result was ... nothing

I think the mistake is that I must select the ellipse after the function

(ACET-GEOM-ELLIPSE-TO-PLINE (car (entsel)))

and I'm selecting them all before, I am thinking as well? how do I get around this?

Posted

Quick mod:

 

(defun c:elixp ( / el i )
   (if (setq el (ssget "_X" '((0 . "ELLIPSE"))))
       (repeat (setq i (sslength el))
           (ACET-GEOM-ELLIPSE-TO-PLINE (ssname el (setq i (1- i))))
       )
   )
   (princ)
)

Posted
Quick mod:

 

(defun c:elixp ( / el i )
(if (setq el (ssget "_X" '((0 . "ELLIPSE"))))
(repeat (setq i (sslength el))
(ACET-GEOM-ELLIPSE-TO-PLINE (ssname el (setq i (1- i))))
)
)
(princ)
)

 

 

Very nice Lee.

One other thing I want to point out is that the pline is created on top of the ellipse. It doesn't replace the ellipse. So if you want to delete the original ellipse you may want to add a line of code to delete the "el" selection set.

 

example: (command "erase" el "")

 

Just a thought.

 

jsowinski

Posted
Very nice Lee. One other thing I want to point out is that the pline is created on top of the ellipse. It doesn't replace the ellipse.

 

Cheers jsowinkski, to erase also:

 

[font=monospace](defun c:elixp ( / el i )
   (if (setq el (ssget "_X" '((0 . "ELLIPSE"))))
       (repeat (setq i (sslength el))
           (ACET-GEOM-ELLIPSE-TO-PLINE (ssname el (setq i (1- i))))
           (entdel (ssname el i))
       )
   )
   (princ)
)[/font]

Posted

Many thanks jsowinski and Super Lee ... :beer:

 

I see that I still have very little work to start making my own functions from scratch.

By the way, I've been researching some routine that explodes linetypes, but I find all have problems with the scale,is that there are already some of the best around and I'm not the find? :oops:

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