View Full Version : Convert Circles to Polylines routine not working correctly
Lions60
2006-08-02, 02:41 PM
Heres is code to convert circles to plines, but when the program runs it does not place the pline conversions back where the original circles were. If anyone can help it would be much appreciated.
(defun C2P (/ OLDVAR1 COUNT LINENO SS1 ename elist pt )
(alert "\nConverting Circles to PLines\n")
(command ".undo" "Mark")
(setq OLDVAR1 (getvar "CMDECHO")) (setvar "CMDECHO" 0)
(setq SS1 nil)
(setq SS1 (ssget "X" ' ((0 . "CIRCLE"))))
(setq LINENO (sslength SS1))
(setq COUNT 0)
(setq PLINFO (ssadd))
(repeat LINENO
(progn
(setq ename (ssname SS1 COUNT))
(setq elist (entget ename))
(setq dia (* 2 (cdr (assoc 40 elist)))) ;get diameter
(setq pt (cdr (assoc 10 elist))) ;get center point
(setq lay (cdr (assoc 8 elist))) ;get layer
(command "donut" dia dia pt "") ;make the donut
(setq ename (entlast)) ;move donut to circle's layer
(setq elist (entget ename))
(setq elist (subst (cons 8 lay) (assoc 8 elist) elist))
(entmod elist)
(setq COUNT (1+ COUNT))
)
)
(COMMAND "ERASE" SS1 "")
(setvar "CMDECHO" OLDVAR1)
(prompt (strcat "\n" "Erasing original Circles..." "\n"))
(princ) ; end program
(terpri)
); end convert.lsp
rkmcswain
2006-08-02, 02:46 PM
Works here *unless* you are not in WCS.
Replace
(command "donut" dia dia pt "")
with
(command "donut" dia dia (trans pt 0 1) "")
Lions60
2006-08-02, 03:01 PM
Nope still didn't work but worth a try.
rkmcswain
2006-08-02, 03:10 PM
Nope still didn't work but worth a try.
Ok, you must have some other situation going on. Post (or email me) a drawing where it doesn't work.
Nope still didn't work but worth a try.
Do you have your OSNAPS on? I did not see anywhere in your code that verified the OSMODE was changed.
Lions60
2006-08-02, 03:37 PM
Here is a drawing that the code doesn't work right in.
abdulhuck
2006-08-02, 03:50 PM
Heres is code to convert circles to plines, but when the program runs it does not place the pline conversions back where the original circles were. If anyone can help it would be much appreciated.
Hi Lions,
Your original code works in my computer, without any errors, the polylines are drawn in the original location as of the circles. I am afraid that some variables in your code are conflicting with other Lisp routines in your system, because they may not be local variables. There may be some global variables with the same names. Try to replace the first line as I show below
(defun C2P (/ Oldvar1 ss1 lineno count plinfo ename elist dia pt lay )
If it gives you the same problem, try to run this code in an AutoCAD session without any other Lisp files loaded and see the difference.
I tried it in AutoCAD 2005, but it should be the same in any version.
Regards,
Abdul Huck
Lions60
2006-08-02, 04:03 PM
I ran the code in an autocad session with no other lisp routines loaded and it still displaces the converted pline circles at a point other than their origin. I attached a drawing to a post earlier maybe you can open it and try the code there.
CAB2k
2006-08-02, 05:39 PM
FYI
Lions60 AKA lispman21 did get a solution here (http://www.theswamp.org/index.php?topic=11477.0)
mengseng
2006-08-03, 04:57 AM
I ran the code in an autocad session with no other lisp routines loaded and it still displaces the converted pline circles at a point other than their origin. I attached a drawing to a post earlier maybe you can open it and try the code there.
I had try on your drawing. seem like not all object in same plane(try using 3D orbit to look at it). Would this be the problem?
Maybe you need a code to convert all Z axis number to 0(zero) before convert the circle to polyline.
CAB2k
2006-08-03, 06:31 AM
Try it with trans
(defun c2p (/ oldvar1 ss1 ename elist pt dia lay)
(alert "\nConverting Circles to PLines\n")
(command ".undo" "Mark")
(setq oldvar1 (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq ss1 (ssget "X" '((0 . "CIRCLE"))))
(setq i -1)
(while (setq ename (ssname ss1 (setq i (1+ i))))
(setq elist (entget ename))
(setq dia (* 2 (cdr (assoc 40 elist))))
(setq pt (cdr (assoc 10 elist)))
(setq lay (cdr (assoc 8 elist)))
(command "donut" dia dia "non" (trans pt ename 0) "")
(setq elist (entget (entlast)))
(entmod (subst (cons 8 lay) (assoc 8 elist) elist))
)
(command "ERASE" ss1 "")
(setvar "CMDECHO" oldvar1)
(prompt (strcat "\n" "Erasing original Circles..." "\n"))
(princ)
)
Lions60
2006-08-03, 01:52 PM
Yes, CAB2k the code you have written also works. Thanks for the post.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.