Circle to lwpline problems

Mike Krous

Usenet Archive
Joined
Sep 11, 2003
Messages
3
Reaction score
0
I am trying to convert a circle entity to a lwpline entity so it may be used by a routine that only likes plines...I am having problems converting from the circle information to lwpline information. My script takes a circle and converts it to an lwpline...anyone know where im going wrong? It works sometimes but alot of the time it just gives me odd shaped arcs.

(edata holds a circle entity, ename holds the entity name) .... (setq cenPt (getdxf 10 edata)) ;get centerpoint (setq rad (getdxf 40 edata)) ;get radius (setq startPt (polar cenPt 0 rad)) ;get the point at 0 degrees (setq endPt (polar cenPt pi rad)) ;get the point at 180 degrees (command "pline" startPt "a" "ce" cenPt endPt "") ;draw a pline from 0 degrees to 180 degrees (setq ent1 (entlast)) ;get our newly created entity for later join to ent2 (command "pline" endPt "a" "ce" cenPt startPt "") ;draw a pline from 180 degrees to 0 degrees (setq ent2 (entlast)) ;get our newly created entity for later join to ent1 (command "pedit" ent1 "j" ent2 "" "") ;join ent1 and ent2 to create our new "pline-circle" (entdel ename) ;get rid of the original circle .... ;--------------------------------------------------------------------------- (defun getdxf (dxfcode ent) (cdr (assoc dxfcode ent))
)

All suggestions are appreciated.

Mike Krous
 
Hi Mike,
I'm lazy and like sweets. Therefore DONUTs mustn't be ignored ;-)

;circle 2 pline - ruul 03/09/11
(defun c:c2p ( / ent eli cd pc)
(cond
((null (setq ent (entsel))))
((/= "CIRCLE" (cdr (assoc 0 (setq eli (entget (setq ent (car ent)))))))) (T (setq cd (* 2.0 (cdr (assoc 40 eli))) pc (cdr (assoc 10 eli))) (command "_donut" cd cd pc ^C) (entdel ent) ) ) (prin1)
)

On 11.09.2003 22:33 Mike Krous wrote:

[... a lot ...]
All suggestions are appreciated.

Mike Krous

ok, you got one here
;^)
 
Thanks for the reply jason, I tried your routine and it works like one should...thank you very much...

Mike Krous

Jason Piercey said:
Here is one that I wrote a couple of years ago.

----

;Written By: Jason Piercey 07.31.01
;Revised: 01.16.02 To handle multiple selection

(defun C:Circle2Pline (/ CirEnt CirElst CirCen CirRad CirLay CirLin CirClr CirLts PlineEnt ss i );ss1)

(setq ss (ssget '((0 . "CIRCLE"))))
(if ss
(progn
(setq i 0 );ss1 (ssadd))
(repeat (sslength ss)
(setq CirEnt (ssname ss i)
CirElst (entget CirEnt)
CirCen (cdr (assoc 10 CirElst))
CirRad (cdr (assoc 40 CirElst))
CirLay (cdr (assoc 8 CirElst))
CirLin (cdr (assoc 6 CirElst))
CirClr (cdr (assoc 62 CirElst))
CirLts (cdr (assoc 48 CirElst))
)

(setq PlineEnt (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
(cons 8 CirLay)
'(100 . "AcDbPolyline")
'(90 . 2)
'(70 . 1)
'(43 . 0.0)
'(38 . 0.0)
'(39 . 0.0)
(cons 10 (polar CirCen (* pi) CirRad))
'(40 . 0.0)
'(41 . 0.0)
'(42 . 1.0)
(cons 10 (polar CirCen (* pi 2.0) CirRad))
'(40 . 0.0)
'(41 . 0.0)
'(42 . 1.0)
'(210 0.0 0.0 1.0)
)
)

(if CirLin (setq PlineEnt (append PlineEnt (list (cons 6 CirLin))))) (if CirClr (setq PlineEnt (append PlineEnt (list (cons 62 CirClr))))) (if CirLts (setq PlineEnt (append PlineEnt (list (cons 48 CirLts))))) (entmake PlineEnt) (entdel CirEnt) (setq i (1+ i)) ) ) ) ;(ssget "p") (princ (strcat "\n"(itoa i) " Circles converted to LwPolylines")) (princ)
)
 
Thanks for the reply ruul, Jasons's post was a little faster for me to decipher, thanks again..

Mike Krous

ruul morawetz said:
Hi Mike,
I'm lazy and like sweets. Therefore DONUTs mustn't be ignored ;-)

;circle 2 pline - ruul 03/09/11
(defun c:c2p ( / ent eli cd pc)
(cond
((null (setq ent (entsel))))
((/= "CIRCLE" (cdr (assoc 0 (setq eli (entget (setq ent (car ent)))))))) (T (setq cd (* 2.0 (cdr (assoc 40 eli))) pc (cdr (assoc 10 eli))) (command "_donut" cd cd pc ^C) (entdel ent) ) ) (prin1)
)

On 11.09.2003 22:33 Mike Krous wrote:

[... a lot ...]
All suggestions are appreciated.

Mike Krous

ok, you got one here
;^)
 
Thanks for the reply ruul, Jasons's post was a little faster for me to decipher, thanks again..
Don't worry, if you don't want the DONUTs I eat 'em myself ;-)

Of course when trying to avoid the command function Jason's method for sure is one to go.

OTOH I try to let AutoCAD do as much as possible ;-)
and a DONUT creates a POLYLINE in the shape of a circle.

The type of the polyline is dependant on the PLINETYPE setting.
 

Latest threads

Back
Top