Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Convert Arc/Ellipse to 2D PLine

40 REPLIES 40
Reply
Message 1 of 41
ArchD
6060 Views, 40 Replies

Convert Arc/Ellipse to 2D PLine

Does anyone have a lisp routine for converting an ellipse to a PLine? I've searched the forums here and at other sites, and can only find lsp that convert PLines to Arcs/Ellipse. Any help would be appreciated. Thanks.
Archie Dodge
Applications Expert - Infrastructure Solutions Division
IMAGINiT Technologies
40 REPLIES 40
Message 2 of 41
Anonymous
in reply to: ArchD


offset the ellipse a distance and then offset it
back

 

PJ

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Does
anyone have a lisp routine for converting an ellipse to a PLine? I've searched
the forums here and at other sites, and can only find lsp that convert PLines
to Arcs/Ellipse. Any help would be appreciated.
Thanks.
Message 3 of 41
ArchD
in reply to: ArchD

What a simple solution, wow. Never knew that did that, but how about arcs? The solution you provided worked for what I need, thanks for that, but while I'm at it, how about converting arcs and circles to Plines?

Thanks again Princess. Edited by: ARCHD on Mar 5, 2009 11:44 AM
Archie Dodge
Applications Expert - Infrastructure Solutions Division
IMAGINiT Technologies
Message 4 of 41
Anonymous
in reply to: ArchD

That will make it a Spline, not a Polyline.

An Arc can be converted by selecting it in PEDIT, and answering Yes to the question whether you want
to change it into a Polyline.

For an Ellipse, are you looking for a Polyline approximation that's made of *arc* segments, such as
you would get if you drew the Ellipse with the PELLIPSE System Variable set to 1? That could
probably be done, extracting information from the Ellipse. Or would an approximation made of short
*line* segments do for you? If so, check out my WobblyPline routine at the end of this thread:

http://discussion.autodesk.com/forums/thread.jspa?messageID=6044735㰿

and give it a large number of segments and *zero* randomization. With enough segments, that would
lie much more accurately along the true elliptical path than the Polyline Ellipse approach.

--
Kent Cooper


"Princess Jamie" wrote...
offset the ellipse a distance and then offset it back
....

ARCHD wrote...
Does anyone have a lisp routine for converting an ellipse to a PLine? ....
Message 5 of 41
Anonymous
in reply to: ArchD


pellipse = 1

redraw a new ellipse.

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
What
a simple solution, wow. Never knew that did that, but how about arcs? The
solution you provided worked for what I need, thanks for that, but while I'm
at it, how about converting arcs and circles to Plines? Thanks again Princess.
Edited by: ARCHD on Mar 5, 2009 11:44 AM
Message 6 of 41
Anonymous
in reply to: ArchD

That's good, if a Spline works for you as well as a Polyline would.

A Circle can't be done within PEDIT as an Arc can. But it would be pretty easy to extract the
center point and diameter, and draw a Donut with both inside and outside diameters equal to that of
the Circle. The result of the DONUT command is a two-arc-segment closed circular Polyline.

--
Kent Cooper


ARCHD wrote...
What a simple solution, wow. Never knew that did that, but how about arcs? The solution you provided
worked for what I need, thanks for that, but while I'm at it, how about converting arcs and circles
to Plines? Thanks again Princess. Edited by: ARCHD on Mar 5, 2009 11:44 AM
Message 7 of 41
Anonymous
in reply to: ArchD


Hi,

If you want ellipses to be polylines for
size=3>machining or other similar purposes,

size=2>for the new drawings you can always workaround this problem by setting
the variable PELLIPSE to 1, so the ellipses will be created by default as
polylines.

 

As for existing drawings where the ellipses were
created as true ellipses, here is a function that will convert them to
polylines. It takes two arguments, the first one being the entity name [returned
by (ssname..) or (entlast) or (car (entsel))] and the second one, a delete
flag, i.e. T to delete the original ellipse and nil to preserve
it. The function
should be called like
this:

 

(ellipse2polyline entity_name flag)

 

HTH

 


size=2>;;;========================================
(defun ellipse2polyline
(
                                  
ellipse_name
                                  
delete_flag
                                  
/
                                  
*error*
                                  
dxf
                                  
ocmdecho
                                  
oosmode
                                  
opellipse
                                  
oclayer
                                  
entinfo
                                  
entlayer
                                  
ltype
                                  
center
                                  
min2max_axisratio
                                  
endptmajaxis
                                  
halfmajaxis
                                  
endptminaxis
                                
)

  (defun dxf (code elist)(cdr (assoc code
elist)))

 

  (setq entinfo (entget
ellipse_name))
  (setq entlayer (dxf 8 entinfo))

 

  (if (= (dxf 0 entinfo)
"ELLIPSE")
    (if (< (cdr (assoc 70 (tblsearch "layer"
entlayer))) 4)
     
(progn
       

        (setq ocmdecho (getvar
"cmdecho"))
        (setvar "cmdecho"
0)

 

        (setq
oosmode (getvar "osmode"))
        (setvar
"osmode" 0)
       

        (setq opellipse (getvar
"pellipse"))
        (setvar "pellipse"
1)
       

        (setq oclayer (getvar
"clayer"))
        (if (/= oclayer
entlayer)(setvar "clayer" entlayer))

 

        (setq
ltype (dxf 6 entinfo))
        (setq
center (dxf 10 entinfo))
        (setq
min2max_axisratio (dxf 40
entinfo))
        (setq endptmajaxis
(mapcar '+ center (dxf 11
entinfo)))
        (setq halfmajaxis
(distance center endptmajaxis))
       
(setq endptminaxis
         
(polar
           
center
            (+
(angle center endptmajaxis) (/ pi
2.0))
            (*
halfmajaxis
min2max_axisratio)
         
)
        )

 

        (command
"_.undo" "_begin")
       

       
(command
         
".ellipse"
         
"c"
          (trans center 0
1)
          (trans endptmajaxis
0 1)
          (trans
endptminaxis 0 1)
       
)
       
(if
         
(and
           
ltype
           
(/=
             
(dxf 6 (tblsearch "layer"
entlayer))
             
ltype
           
)
         
)
         
(progn
           
(command ".chprop" "l" "" "lt" ltype
"")
           
(command ".pedit" "l" "l" "on"
"")
         
)
        )

 

        (if
delete_flag (entdel ellipse_name))

 

        (command
"_.undo" "end")

 

        (setvar
"clayer" oclayer)
        (setvar "osmode"
oosmode) 
        (setvar "cmdecho"
ocmdecho)
        (setvar "pellipse"
opellipse)
      )
     
(alert "The selected ellipse is on a locked layer.")
   
)
    (alert "The selected object is not an
ellipse.")
  )
  (princ)
)


size=2>;;;========================================

--
Humans
are born with a wide horizon.
As time goes by, the horizon narrows
and
narrows, until it becomes a point of view.

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Does
anyone have a lisp routine for converting an ellipse to a PLine? I've searched
the forums here and at other sites, and can only find lsp that convert PLines
to Arcs/Ellipse. Any help would be appreciated.
Thanks.
Message 8 of 41
ArchD
in reply to: ArchD

Mr. Cooper, you're hitting my problem on the head. Slines aren't working too well for me, and it took me a second to find out that offsetting the ellipses were in fact splines. The application I need this for is an annotation boundry on a map, so the lines dont have to be exact, just a very close rough representation of a circle or an ellipse.

Your WobblyPline is perfect. Thank you so very much. Exactly what I needed.
Archie Dodge
Applications Expert - Infrastructure Solutions Division
IMAGINiT Technologies
Message 9 of 41
Anonymous
in reply to: ArchD

This is 1 of the better ones I've seen:

;| 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)
)
Message 10 of 41
Anonymous
in reply to: ArchD

In basic form:

{code}
(defun C:C2P (/ cirobj cirdata cirdia)
(setq
cirobj (car (entsel "\nSelect Circle to convert to Polyline: "))
cirdata (entget cirobj)
cirdia (* (cdr (assoc 40 cirdata)) 2)
); end setq
(entdel cirobj)
(command "_.donut" cirdia cirdia (cdr (assoc 10 cirdata)) "")
); end defun
{code}

It could be enhanced with error controls, limitation of object-type in the selection, switching to
the selected Circle's layer, option of keeping the selected Circle, etc., but you get the idea.

--
Kent Cooper


"Kent Cooper" wrote...
....
A Circle can't be done within PEDIT as an Arc can. But it would be pretty easy to extract the
center point and diameter, and draw a Donut with both inside and outside diameters equal to that of
the Circle. The result of the DONUT command is a two-arc-segment closed circular Polyline.

....
Message 11 of 41
ArchD
in reply to: ArchD

pellipse to 1 is also great, never knew that variable, should come in handy. This whole thread is a huge help to my everyday annotation on my drawings, wish I knew them earlier. Thanks everyone.
Archie Dodge
Applications Expert - Infrastructure Solutions Division
IMAGINiT Technologies
Message 12 of 41
Anonymous
in reply to: ArchD

You're welcome. It would also work on Arcs and Circles (and anything of a linear/curved nature
other than Xlines and Rays). But for Arcs, Pedit, and for Circles, something like my C2P
suggestion, would be better, because they'd preserve the actual curvature (and they're more
memory-efficient, if you care).
--
Kent Cooper


ARCHD wrote...
Mr. Cooper, you're hitting my problem on the head. Slines aren't working too well for me, and it
took me a second to find out that offsetting the ellipses were in fact splines. The application I
need this for is an annotation boundry on a map, so the lines dont have to be exact, just a very
close rough representation of a circle or an ellipse. Your WobblyPline is perfect. Thank you so very
much. Exactly what I needed.
Message 13 of 41
Anonymous
in reply to: ArchD

You *could* even make an all-inclusive routine. The User could pick something to convert, and then
the routine could find out what entity type it is, and:

:: if it's a Line or LWPolyline, the routine could say "don't bother" and exit;
:: if it's an Arc, it could invoke PEDIT and convert it;
:: if it's a Circle, it could invoke C2P or the like, and convert it;
:: if it's an Ellipse or Spline, it could invoke WobblyPline (and could even figure out an
appropriate number of segments, depending on the length or something), or any of the other suggested
routines, and convert it.

That way, the User wouldn't need to know what kind of object they're looking at in order to choose
the right routine. It could even be made to select everything in the drawing, or everything on a
given Layer, or whatever, and convert all of the objects, and only those objects, that need it.

--
Kent Cooper


ARCHD wrote...
Does anyone have a lisp routine for converting an ellipse to a PLine? I've searched the forums here
and at other sites, and can only find lsp that convert PLines to Arcs/Ellipse. Any help would be
appreciated. Thanks.
Message 14 of 41
ArchD
in reply to: ArchD

This would be great. I get drawings all the time from engineers that don't understand the need for certain entities in the drawings and using this to convert them to polylines would be great, it would speed everything up so I don't have to redraw it using a donut, new ellipse or what not. If it would be done, I would really appreciate it, but the help provided already is a huge improvement when I clean up what they give me. If you are able to, could you include the lisps that are necessary for it to work also. The only one I have from your recommendations is the WobblyPLine and it works great. What your talking about is just the icing on the cake!!
Archie Dodge
Applications Expert - Infrastructure Solutions Division
IMAGINiT Technologies
Message 15 of 41
Anonymous
in reply to: ArchD

It would actually be a lot simpler than invoking WobblyPline for Ellipses or Splines. The
complicated part of that routine is the randomization, and since you wouldn't want that, it could be
pared down quite a bit.

I may play with that in the next few days over lunch times or something, but answer me a couple of
things:

Am I correct that Lines wouldn't need to be converted, or should they become Polylines, too?

What kind of criteria would be appropriate for Ellipses/Splines, to determine the number of segments
in a zero-randomization WobblyPline-type conversion? Would there be some absolute number of
segments that would always be high enough? Should it be based on a maximum segment length? If so,
would that be an absolute, or should it be calculated from something like a percentage of the
drawing extents (sort of like the VIEWRES System Variable at lower settings)?

Would you want it always to just grab every Arc/Circle/Ellipse/Spline in the drawing, or let the
User select things? [It could be done so that the User could grab a whole area, with a Window or
Crossing selection, and it would convert only the appropriate entity types.]

--
Kent Cooper


ARCHD wrote...
This would be great. I get drawings all the time from engineers that don't understand the need for
certain entities in the drawings and using this to convert them to polylines would be great, it
would speed everything up so I don't have to redraw it using a donut, new ellipse or what not. If it
would be done, I would really appreciate it, but the help provided already is a huge improvement
when I clean up what they give me. If you are able to, could you include the lisps that are
necessary for it to work also. The only one I have from your recommendations is the WobblyPLine and
it works great. What your talking about is just the icing on the cake!!
Message 16 of 41
Anonymous
in reply to: ArchD

Also, would you have any need for the option to *retain* the original objects? [I would assume not,
but I'll leave that to you.]

[And it can be even *more* simpler than WobblyPline than I was thinking before, considering that you
wouldn't need the option to draw your own path, but would always be working on existing objects.]

--
Kent Cooper


"Kent Cooper" wrote...
It would actually be a lot simpler than invoking WobblyPline for Ellipses or Splines. The
complicated part of that routine is the randomization, and since you wouldn't want that, it could be
pared down quite a bit.

I may play with that in the next few days over lunch times or something, but answer me a couple of
things:
....
Message 17 of 41
Anonymous
in reply to: ArchD

Hi-
If you have Express Tools loaded here is a line of code that will convert an ellipse to a pline. It allows for a single pick. You can easily add it to a function to check for errors.

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

Jim
Message 18 of 41
ArchD
in reply to: ArchD

Q. Am I correct that Lines wouldn't need to be converted, or should they become Polylines, too?

A. I don't know about others, but I use PLines religeously. I even have my "L" key on my keyboard mapped so that it automatically makes PLines, so if that was an option for me, I would like for it to conver lines to Plines, but for the sake of others who would use this lisp, I don't think it's necessary considering that may be my own preference.

Q. What kind of criteria would be appropriate for Ellipses/Splines, to determine the number of segments
in a zero-randomization WobblyPline-type conversion? Would there be some absolute number of
segments that would always be high enough? Should it be based on a maximum segment length? If so,
would that be an absolute, or should it be calculated from something like a percentage of the
drawing extents (sort of like the VIEWRES System Variable at lower settings)?

A. I wouldn't imagine that it would need to be a set number, considering some circles could be small, and a max number of verticies may be too much. Maybe a proportion to the diameter of the circle? But then ellipses wouldn't be able to be done that way I wouldn't imagine. I think something along the lines of a VIEWRES, so that it takes into account the zoom factor of the view you are in when you execute the command.

Q. Would you want it always to just grab every Arc/Circle/Ellipse/Spline in the drawing, or let the
User select things? [It could be done so that the User could grab a whole area, with a Window or
Crossing selection, and it would convert only the appropriate entity types.]

A. Could it do just what you select with an option of for Multiple then have a selction window or pick box for one object after another?

Q. Also, would you have any need for the option to *retain* the original objects? [I would assume not,
but I'll leave that to you.]

A. No need to retain, it started as trash in my eyes and that's where it will end.

Thanks again Mr. Cooper, this is something that will be used on a regular basis, I've already shared WobblyPline with my co-workers and they appreciate it also.
Archie Dodge
Applications Expert - Infrastructure Solutions Division
IMAGINiT Technologies
Message 19 of 41
Anonymous
in reply to: ArchD

That's very nice. [But I can't find it documented in Help -- what other undocumented Express Tools
are out there?]

It uses more arc segments to approximate the ellipse than an Polyline-form Ellipse [drawn with the
Ellipse command and PELLIPSE = 1] does, so it's a lot closer to the true elliptical shape.

There doesn't seem to be an equivalent for Splines, though [at least not simply the same with Spline
in place of Ellipse], so something like WobblyPline could still be preferable there.

--
Kent Cooper


jsowinski wrote...
Hi- If you have Express Tools loaded here is a line of code that will convert an ellipse to a pline.
It allows for a single pick. You can easily add it to a function to check for errors.
(ACET-GEOM-ELLIPSE-TO-PLINE (car (entsel))) Jim
Message 20 of 41
ArchD
in reply to: ArchD

Yes, this is a great line of code. Now if only there was one for circles too!
Archie Dodge
Applications Expert - Infrastructure Solutions Division
IMAGINiT Technologies

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost