Jump to content

Anyway to Change an Ellipse into a Polyline?


fewer_98

Recommended Posts

If you trim it in half or what ever and you want to connect it to another polyline is there anyway to accompolish this? Pedit doesn't work. Any help would be greatly appreciated

 

Thanks.

Link to comment
Share on other sites

  • Replies 38
  • Created
  • Last Reply

Top Posters In This Topic

  • fuccaro

    12

  • CADIDAC

    6

  • CADTutor

    5

  • fewer_98

    5

In recent versions of AutoCAD, new ellipses are created as splines. This makes more sense in terms of geometry. However, by setting the pellipse variable to 1, you force all new ellipses to be created as polylines. Unfortunately, you cannot transform existing spline ellipses using this variable.

Link to comment
Share on other sites

Unfortunately, you cannot transform existing spline ellipses using this variable.
;| Transforms a spline ellipse into a polyline ellipse
   and brings it on the current layer
[email="mfuccaro@hotmail.com"]mfuccaro@hotmail.com[/email]  AUGUST 2004
-------------------------------------------------------------
|;

(defun c:ell2p    ; ELLipse TO Polyline

      ( / old cen p1 p1n p2n sc old_PELLIPSE old_OSMODE)
 (setq old (car (entsel "\n select ellipse to change ")))
 (while old
   (if    (= (cdr (assoc 0 (entget old))) "ELLIPSE")
     (progn
   (setq cen (cdr (assoc 10 (entget old)))
         p1 (cdr (assoc 11 (entget old)))
         p1n (list (+ (car cen) (car p1))
           (+ (cadr cen) (cadr p1))
           (caddr cen))
         
         p2n (list (- (car cen) (car p1))
           (- (cadr cen) (cadr p1))
           (caddr cen))
         
         sc (cdr (assoc 40 (entget old)))
         old_PELLIPSE (getvar "PELLIPSE")
         old_OSMODE   (getvar "OSMODE")
   )
   (setvar "PELLIPSE" 1)
   (setvar "OSMODE" 0)
   (entdel old)
   (command "ELLIPSE" p1n p2n
        (polar    cen
           (+ (angle cen p1n) (/ PI 2.0))
           (* sc (distance cen p1n))))
   
   (setvar "PELLIPSE" old_PELLIPSE)
   (setvar "OSMODE" old_OSMODE)
     )
     (alert "This is not an ELLIPSE")
   )
   (setq old (car (entsel "\n select ellipse or none for exit ")))
 )
 (princ)
)

:D :D :D :D :D

Link to comment
Share on other sites

Fuccaro - what can I say? Top marks. That is an excellent little routine and more than worthy of being added to our LISP library.

 

That sould also be an inspiration to those wondering whether it's worth learning AutoLISP. A little bit of LISP goes a long way. Something that is impossible to do with AutoCAD out of the box is easily done with a small but perfectly formed routine. 8)

Link to comment
Share on other sites

Just if someone is curious how the lisp above works:

The user selects an ellipse. The data is extracted/stored and the ellipse is deleted. The PELLIPSE is set to 1 and the program draws a new ellipse (on the current layer) based on the saved data. Finaly the PELLIPSE is restored.

My turn to ask: why to transform a spline ellipse into a polyline one?

Link to comment
Share on other sites

Just one observation. Would it not be preferable to get the layer of the old ellipse and draw in on that layer rather than the current layer? More coding, I know but it seems to make sense. The impression to the user would then be a straight transformation.

Link to comment
Share on other sites

;| Transforms a spline ellipse into a polyline ellipse

[email="mfuccaro@hotmail.com"]mfuccaro@hotmail.com[/email]  AUGUST 2004
-------------------------------------------------------------
|;
;modificated after few hours: 
;the polyline ellipse is placed on the same layer

(defun c:ell2p    ; ELLipse TO Polyline

      ( / old new    ;existent and new-generated ellipse
   cen p1        ;center, deplasament of end point of axis
   p1n p2n        ;end points of axis
   sc        ;scale factor for other axis length
   old_LAYER
   old_PELLIPSE old_OSMODE)    ;to save settings
 (setq old (car (entsel "\n select ellipse to change ")))
 (while old
   (if    (= (cdr (assoc 0 (entget old))) "ELLIPSE")
     (progn
   (setq cen (cdr (assoc 10 (entget old)))
         p1 (cdr (assoc 11 (entget old)))
         p1n (list (+ (car cen) (car p1))
           (+ (cadr cen) (cadr p1))
           (caddr cen))
         
         p2n (list (- (car cen) (car p1))
           (- (cadr cen) (cadr p1))
           (caddr cen))
         
         sc (cdr (assoc 40 (entget old)))
         old_LAYER (cdr (assoc 8 (entget old)))
         old_PELLIPSE (getvar "PELLIPSE")
         old_OSMODE   (getvar "OSMODE")
   )
   (setvar "PELLIPSE" 1)
   (setvar "OSMODE" 0)
   (entdel old)
   (command "ELLIPSE" p1n p2n
        (polar    cen
           (+ (angle cen p1n) (/ PI 2.0))
           (* sc (distance cen p1n))))
   (setq new (entget (entlast))
         new (subst (cons 8 old_LAYER) (assoc 8 new) new))
   (entmod new)    ;changing the layer
   
   (setvar "PELLIPSE" old_PELLIPSE)    ;restore old
   (setvar "OSMODE" old_OSMODE)        ;settings
     )
     (alert "This is not an ELLIPSE")
   )
   (setq old (car (entsel "\n select ellipse or none for exit ")))
 )
 (princ)
)

Link to comment
Share on other sites

...

My turn to ask: why to transform a spline ellipse into a polyline one?

We use .dxf files for our plazma table here at work, and if you draw something in a polyline it doesn't have to start and stop at each end, it just follows it. So before it would follow the polyline and then come to the ellipse arc and skip it, and come back later and burn that out. It just saves a bit of time and also elliminates having to repunchure the material. If any of that is understandable. :D. But thanks alot for your help.

Link to comment
Share on other sites

;| Transforms a spline ellipse into a polyline ellipse

[email="mfuccaro@hotmail.com"]mfuccaro@hotmail.com[/email]  AUGUST 2004
-------------------------------------------------------------
|;
;modificated after few hours: 
;the polyline ellipse is placed on the same layer

(defun c:ell2p    ; ELLipse TO Polyline

      ( / old new    ;existent and new-generated ellipse
   cen p1        ;center, deplasament of end point of axis
   p1n p2n        ;end points of axis
   sc        ;scale factor for other axis length
   old_LAYER
   old_PELLIPSE old_OSMODE)    ;to save settings
 (setq old (car (entsel "\n select ellipse to change ")))
 (while old
   (if    (= (cdr (assoc 0 (entget old))) "ELLIPSE")
     (progn
   (setq cen (cdr (assoc 10 (entget old)))
         p1 (cdr (assoc 11 (entget old)))
         p1n (list (+ (car cen) (car p1))
           (+ (cadr cen) (cadr p1))
           (caddr cen))
         
         p2n (list (- (car cen) (car p1))
           (- (cadr cen) (cadr p1))
           (caddr cen))
         
         sc (cdr (assoc 40 (entget old)))
         old_LAYER (cdr (assoc 8 (entget old)))
         old_PELLIPSE (getvar "PELLIPSE")
         old_OSMODE   (getvar "OSMODE")
   )
   (setvar "PELLIPSE" 1)
   (setvar "OSMODE" 0)
   (entdel old)
   (command "ELLIPSE" p1n p2n
        (polar    cen
           (+ (angle cen p1n) (/ PI 2.0))
           (* sc (distance cen p1n))))
   (setq new (entget (entlast))
         new (subst (cons 8 old_LAYER) (assoc 8 new) new))
   (entmod new)    ;changing the layer
   
   (setvar "PELLIPSE" old_PELLIPSE)    ;restore old
   (setvar "OSMODE" old_OSMODE)        ;settings
     )
     (alert "This is not an ELLIPSE")
   )
   (setq old (car (entsel "\n select ellipse or none for exit ")))
 )
 (princ)
)

 

I used your Lisp and it worked, but it inserts the Ellipse in a different area. Did I do something wrong or is there something I'm missing?

Link to comment
Share on other sites

I can't reproduce that error on my computer. I sent a PM to Fewer_98 asking a dwg with trouble. Until that can someone please give a try to the ell2p lisp (the 2nd one) and post here a feedback?

Thanks!

Link to comment
Share on other sites

I have tested this and I have also managed to simulate the error. It's all caused by UCS.

 

If you draw the ellipse in the World CS and then set some other UCS, offset from World, then use ell2p, you will see the ellipse jump from one location to the other. The direction and distance of jump is exactly relative to the offset of the new UCS to World.

Link to comment
Share on other sites

Bugs fixed (I think :roll: ) In fact I rewrote the routine so this is a new one.

Testers wanted!

;| Transforms a spline ellipse into a polyline ellipse
[email="mfuccaro@hotmail.com"]mfuccaro@hotmail.com[/email]  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)
  )

Link to comment
Share on other sites

Bugs fixed (I think :roll: ) In fact I rewrote the routine so this is a new one.

Testers wanted!

;| Transforms a spline ellipse into a polyline ellipse
[email="mfuccaro@hotmail.com"]mfuccaro@hotmail.com[/email]  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)
  )

 

Thanks Fuccaro, that one works perfect, even with my UCS messed up :D, thanks again!!

Link to comment
Share on other sites

  • 1 month later...

Hello Mr Fuccaro,

Just wanted to say I thanks for a good lisp routine. Its my first time using one and the only trouble I had was the cadtutor topic "How to use the Lisp routines in this archive" instructs us to copy the routine to windows note pad , but in the example it shows the copied routine as begining with (defun c:zone Ect..... But in practice I learned that there is

a bit of code priar to that and must be copied or the routine will not run.

Anyway this routine is a big timesaver for me as I have a whole directory

of molding profiles that I drew when I was strictly a 2D guy and now that

I am into 3D I need to extrude them and allmost all of them contain spline

ellipses. Before I found your routine I was haveing to create a series of arcs that approxamated the ellipses before I could extrude them. What a pain!!! Thank you for a valuable gift. I am now a "Lisp Beliver"

Frank (ps, the lisp I used was from your third

posting on this topic)

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