# Thread: Polyline to circle

1. ## Polyline to circle

Registered forum members do not see this ad.

Perhaps i have to post this here?

http://www.cadtutor.net/forum/showth...922#post231922

Can some one expert help me to develop a Lisp routine?
I think is not easy to do that.

/automicro

2. are we to assume that the polyline is in a roundish type shape? If not, how do you purpose to locate the center? What you want is actually pretty easy, make sure the polyline is closed, get the area, do some math to find a circle of the same area, use the centroid of the polyline area, and locate the circle.

3. I must have been bored... no error checking and not extensively tested, kinda slow
Using CmdrDuh's idea...
Code:
```(defun c:test (/ ss1 num cnt ename obj rp ar rad)
(vl-load-com)
(setq ss1 (ssget '((0 . "*polyline")))
num (sslength ss1)
cnt 0)
(repeat num
(setq ename (ssname ss1 cnt))
(setq obj (vlax-ename->vla-object ename))
(vlax-put-property obj 'Closed 1)
(vl-cmdf "region" ename "")
(setq obj (vlax-ename->vla-object (entlast)))
(setq ar (vlax-get-property obj 'Area)
rp (vlax-safearray->list (vlax-variant-value (vlax-get-property obj 'Centroid)))
rad (sqrt (/ ar pi))
)
(entdel (entlast));remove this line if you want to keep original
(vl-cmdf "circle" rp rad)
(setq cnt (1+ cnt))
)
(princ)
)```

4. I was just thinking out loud, HAHA, but thanks for making it a reality

5. Great LISP for quickly typed one, - nice one Larry.

Not to be critical, but I would only make a few aesthetic changes:

Code:
```(defun c:test  (/ ss obj rp ar rad)
(vl-load-com)
(if (setq ss (ssget (list (cons 0 "*POLYLINE")
(if (getvar "CTAB")
(cons 410 (getvar "CTAB"))
(cons 67 (- 1 (getvar "TILEMODE")))))))
(foreach x (mapcar 'vlax-ename->vla-object
(vl-remove-if 'listp
(mapcar 'cadr (ssnamex ss))))
(vlax-put-property x 'Closed 1)
(vl-cmdf "_region" (vlax-vla-object->ename x) "")
(setq obj (vlax-ename->vla-object (entlast))
ar  (vlax-get-property obj 'Area)
rp  (vlax-safearray->list
(vlax-variant-value
(vlax-get-property obj 'Centroid)))
rad (sqrt (/ ar pi)))
(vla-delete obj) ; -> Remove to Keep Original
(vl-cmdf "_circle" rp rad))
(princ "\n<!> Nothing Selected <!>"))
(princ))```

6. Lee, how did you get your code to be color coded?

7. I wrote a LISP to write a file with the [ color] tags in

8. Incredibly good, this savings me lots of jobs.
Thanks to lpseifert and Lee Mac

But he discovered that many of polylines is double stored above each other
Is there a simple way to remove double elements stored?

What a coincidence you both seem to enjoy motorcycles
I myself drive BMW F800GS

9. Originally Posted by automicro
But he discovered that many of polylines is double stored above each other
Is there a simple way to remove double elements stored?
Maybe OVERKILL?

10. Registered forum members do not see this ad.

Originally Posted by automicro
Incredibly good, this savings me lots of jobs.
Thanks to lpseifert and Lee Mac

But he discovered that many of polylines is double stored above each other
Is there a simple way to remove double elements stored?
I would recommend OVERKILL from Express Tools - that'll be a much better than anything I could write for you.

Originally Posted by automicro
What a coincidence you both seem to enjoy motorcycles
I myself drive BMW F800GS
Great looking bike - bit on the tall side, but a smooth ride.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts