Convert polyline-circle to normal circle

Convert polyline-circle to normal circle

Henrik_Lo
Collaborator Collaborator
21,568 Views
39 Replies
Message 1 of 40

Convert polyline-circle to normal circle

Henrik_Lo
Collaborator
Collaborator

HI

 

I dose anyone have a LISP program there can convert polyline-circle to normal circle.

I do have 10 different polyline-circles in my drawing, and a lot of them.

I looked up at code, there can do the job for one polyline-circle, but I need it be able

selecting all, and then convert them to normal circles.

 

 

This is the code I looked up.

(defun c:Test (/ ss)

;; Author : Tharwat 20. jan. 2014 ;;

(if (setq ss (ssget "_:L" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))

((lambda (i / sn l x y)

(while (setq sn (ssname ss (setq i (1+ i))))

(setq l (mapcar 'cdr (vl-remove-if-not (function (lambda (u) (eq (car u) 10))) (entget sn)))

x (/ (apply '+ (mapcar 'car l)) (length l))

y (/ (apply '+ (mapcar 'cadr l)) (length l))

)

(if (entmakex (list '(0 . "CIRCLE") (cons 10 (list x y)) (cons 40 (distance (list x y) (car l)))))

(entdel sn)

)

(setq l nil

x nil

y nil

)

)

)

-1

)

)

(princ)

)

(vl-load-com)

 

 

 

 

 

 

Regards

Henrik

 

0 Likes
Accepted solutions (1)
21,569 Views
39 Replies
Replies (39)
Message 21 of 40

Anonymous
Not applicable

i am new to all of this. would love to be able to remove all but 4 vertex's for any and all of my artwork. as for now i need to remove them from a circle.

i do not know what the codes are for or how to use them. any help, would help.. i hope

0 Likes
Message 22 of 40

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

i am new to all of this. would love to be able to remove all but 4 vertex's for any and all of my artwork. as for now i need to remove them from a circle. ....


Can you explain further, and/or post a sample drawing with before and after conditions?  If you're talking about Circle entities, they don't have vertices, so I'm trying to picture what you really need to do.  If you're talking about converting circular Polylines into the same but with fewer vertices, they can have as few as 2 and still be circular -- is there any reason to keep 4 vertices?  If you have approximations of circles in something like Polylines with lots of short line segments, those may or may not be easily convertible, depending on how accurately polygonal they are, but see Post 11.

Kent Cooper, AIA
0 Likes
Message 23 of 40

Anonymous
Not applicable

i have attached two circles and or letters. that have too many lines, i need a circle or arc, with 2 or 4 that's not too in portent. these files are as is, it would take me hours to click and remove vertex.

0 Likes
Message 24 of 40

stevor
Collaborator
Collaborator
Google 'autolisp Polyline to Circle ' for a few.
S
0 Likes
Message 25 of 40

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

i have attached two circles and or letters. that have too many lines, i need a circle or arc, .... it would take me hours to click and remove vertex.


When I bring in your .dxf files, those are already Circles, so you can't remove vertices, and there's nothing to convert.  If they look like they're made up of line segments, that's just a matter of view resolution.  If you Zoom in and they look segmented, and after a REGEN they look curved, that's all it is.

 

Type VIEWRES, answer Yes to the question whether you want fast zooms, and then give it a higher number for the circle zoom percent [the default is 100 -- there's not much reason not to give it the maximum of 20000], and you should not have that problem any more unless you Zoom way far out and then back in, but REGEN will always fix their on-screen appearance.

Kent Cooper, AIA
0 Likes
Message 26 of 40

Anonymous
Not applicable

they're made up of line segments, very small and i need to remove most of them.  to make a ark.  at least  i need 2 segments.

when you explode them there are too many.  see attached 

0 Likes
Message 27 of 40

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

they're made up of line segments, very small and i need to remove most of them.  ....


That one is a Polyline, at last [none of the previous attachments were, via DXFIN -- they were Circles].  The code in Post 1 will make a Circle from that, but the Polyline is a little taller than it is wide, so the "match" is not perfect.  The code in Post 11 will do it, too, but because it does it differently, the "match" is off in a different way.  Unlike the Post 1 code, the Post 11 code leaves the Polyline in place, so you can see how they compare, but it could be made to delete the Polyline, as the code in Post 1 does, if you prefer.

Kent Cooper, AIA
0 Likes
Message 28 of 40

stevor
Collaborator
Collaborator

Try this. Appears that the Pline is not circular.

May have been done before, using least squares.

 

 :  3 point approx of Circle, SCG, from C:82C Kent1Cooper 2012, etal
 (defun C:Pl3C (/ p1 p2 p3 ClosF EndN D2 NI2  D3 NI3  EndD DC )  
  (IF (and (setq EN (car (entsel "\n Sel Pline for Circle: ")))
           (or (= "LWPOLYLINE" (cdr (assoc 0 (entget EN))))
               (and (princ (strcat "\n Not Pline: "  
                (cdr (assoc 0 (entget EN))) " .. " ) nil))) )
   (progn (REDRAW)
    (setq ClosF (vlax-curve-isClosed EN)
          P1 (vlax-curve-getStartPoint EN)
          EndN (vlax-curve-getEndParam EN)
          EndD (vlax-curve-getDistAtParam EN EndN)
          D2 (/ EndD 3)  N2 (vlax-curve-getParamAtDist EN D2)
          D3 (* 2 D2)    N3 (vlax-curve-getParamAtDist EN D3)
          NI2 (fix (+ N2 0.5))  NI3 (fix (+ N3 0.5)) ; closerS
          P2 (vLax-curve-getPointAtParam EN NI2)  
          P3 (vLax-curve-getPointAtParam EN NI3)   )
    ;(pnl_"ClosF EndN D2 NI2  D3 NI3 ")
    ;(gr_xdc P1 2 1) (gr_xdc P2 2 2) (gr_xdc P3 2 3)(W_"p1=1, P2"); (exit_S" ")
    (command  "_.circle"  "3P" P1 P2 P3)
   );     (entdel EN)
  )
 ); defun

S
0 Likes
Message 29 of 40

Anonymous
Not applicable

can you explain how to use the vectorscript.. i have looked on youtube and some tell how but not in detail. if you can direct me to a video or screenshot the steps.  I have added a file, I removed about 10 dots from two sides so, diamond nest can put tabs in. at the same time when I cut the part, it is very slow.

0 Likes
Message 30 of 40

stevor
Collaborator
Collaborator

I have no idea of your dots and all;

but to use a lisp function,

you can drag the file into your graphic screen,

and it should execute.

 

Also, it would be to your advantage to learn

some of the autolisp procedures

if you do much autocad.

 

S
Message 31 of 40

Anonymous
Not applicable

i started yesterday. i know nothing about it but what i had done, i class 9 months ago and they don't tell you about this kind of commands. that is why i am here with you all. I did as you said and nothing happened.thanks for the file. i download a book on vectorscript last night almost 300 pages. i hope it helps. thanks for all the help. 

0 Likes
Message 32 of 40

stevor
Collaborator
Collaborator

What counts is your time.

I think it would be easier to watch this site,

and use it, or google, to search for solutions.

S
0 Likes
Message 33 of 40

sharpl
Advocate
Advocate

Works! Is there one for ellipse? Thank you much! 

0 Likes
Message 34 of 40

Kent1Cooper
Consultant
Consultant

@sharpl wrote:

Works! Is there one for ellipse? .... 


 

Are you talking about converting a full  Polyline ellipse-approximation drawn with the ELLIPSE command when the PELLIPSE System Variable is set to 1, into a true Ellipse?  I can actually imagine a way to do that, because there are characteristics of such Polylines that can be relied on to be regular, from which to define the Ellipse.

 

But if you're talking about one that's been broken  into an elliptical arc [partial ellipse], or, for example, an elliptical shape as a Polyline of loads of short line  segments [as a lot of circle-approximations discussed in this thread are], those would be entirely different challenges, if they would be possible at all.

 

[And by the way -- what  "Works!" ?  There are a lot of routines on this thread, and even just limiting it to the person you're Replying to, @stevor posted two, in Messages 28 & 30, though maybe they're the same code-wise.]

Kent Cooper, AIA
0 Likes
Message 35 of 40

sharpl
Advocate
Advocate

The code mentioned here to convert plines into a circle, works like a magic!  And yes, I have a bunch of broken polylines I am trying to convert back to ellipse. I know it is nearly impossible unless some bright person will write a code. I run codes, and trying to learn VBA to make my own, not quite there thou 😞

0 Likes
Message 36 of 40

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:
.... Are you talking about converting a full  Polyline ellipse-approximation drawn with the ELLIPSE command when the PELLIPSE System Variable is set to 1, into a true Ellipse?  I can actually imagine a way to do that....

Just for full ellipses of that kind, without the usual enhancements, and very lightly tested, but here's the way I imagined to do at least that:

;| ELLIPSE-1to0.lsp [command name: E10]
To convert Ellipse(s) from PELLIPSE=1 Polyline approximation to
  PELLIPSE=0 true Ellipse.
Works on only full closed "heavy" 2D Polyline ellipses of 16 arc segments, such
  as made by ELLIPSE command when PELLIPSE System Variable is set to 1.
Kent Cooper, 8 November 2018
|;
(defun C:E10 (/ ss n el)
  (setvar 'pellipse 0)
  (if (setq ss (ssget '((0 . "POLYLINE"))))
    (repeat (setq n (sslength ss))
      (if (= (vlax-curve-getEndParam (setq el (ssname ss (setq n (1- n))))) 16.0)
        (progn ; then
          (command "_.ellipse"
            "_none" (vlax-curve-getStartPoint el)
            "_none" (vlax-curve-getPointAtParam el 8)
            "_none" (vlax-curve-getPointAtParam el 4)
            "_.erase" el ""
          ); command
        ); progn
      ); if
    ); repeat
  ); if
  (princ)
); defun

 

For broken  ones, it's really hard to think of a way that a routine could find the locations by which to define a true Ellipse.  OSNAPping to CENter locations would give different ones for each arc segment involved.  It might be possible with enough of them to calculate an effective ellipse center, but I assume you wouldn't always have the same number of arc segments remaining, so that could be very unreliable.

Kent Cooper, AIA
0 Likes
Message 37 of 40

Anonymous
Not applicable

Dear Sir,

I have attached one drawings and applied the code to convert from Polyline to circle, But couldn't get the circles. Can you please have a look on my attachment.?

0 Likes
Message 38 of 40

cadffm
Consultant
Consultant

Are you sure you tried the right code for your case, (lw)Polyline-to-Circle?

I checked this thread and the only code from Kent for this was the program

from the linked thread in his <answer#7 on page1>

You need P2C "Type P2C to convert circular Polyline(s) to equivalent Circle(s)."

And it works for your objects, sure.

Sebastian

0 Likes
Message 39 of 40

sharpl
Advocate
Advocate

Broken lines - ellipse in the past- converted to CAD from a .pdf file. I have to redraw the ellipses each time. 

0 Likes
Message 40 of 40

Kent1Cooper
Consultant
Consultant

@sharpl wrote:

Broken lines - ellipse in the past- converted to CAD from a .pdf file. I have to redraw the ellipses each time. 


 

Depending on the nature of the conversion from .PDF:

 

If they're actual partial Ellipse objects, you can use the attached ArcClose.lsp with its AC command to draw the complete Ellipses that they're part of.  [Despite the name, it closes partial Ellipses into closed/full ones, as well as closing Arcs into Circles.]

 

But if they're [for example] Arcs, or arc segments of Polylines, it won't do what you want, but will complete the Circle  that they're part of.

 

[If they're a series of little Line  objects somehow, I don't have anything to offer to automate drawing the equivalent Ellipses.]

Kent Cooper, AIA
0 Likes