Rain0923 Posted October 15, 2014 Share Posted October 15, 2014 I tried to write a lisp for circle become polygon I choose many circle and type the dimension but the polygon can't change at the same time what is problem from my lisp? please help (defun c:ctrr () (prompt "\n>") (prompt "\n>") (setq ss (ssget '((0 . "circle")))) (if (null n)(setq n 4)) (setq i 0) (repeat (sslength ss) (setq en (ssname ss i)) (setq endata (entget en)) (setq cen (cdr (assoc 10 endata))) (setq ll(getreal "\nlength:")) (command "polygon" n cen "c" (/ ll 2)) (entdel en) (setq i (1+ i)) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted October 15, 2014 Share Posted October 15, 2014 I think, you should specify point inside polygon command instead of (/ ll 2)... For ways of creating point, I suggest that you look into (polar origin_point angle_radians distance)... For origin_point, you should supply cen, and for distance (/ ll 2), angle in radians is also important, but for a start I suggest 0.0 radians = 0.0 degrees - aligned with X axis of current active UCS... HTH, M.R. Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted October 15, 2014 Share Posted October 15, 2014 hi Rain0923, welcome to forum if the length is applied for each circle, then you can put outside the repeat loop (defun c:ctrr ( / [color="red"]ss n i ll en endata cen [/color] ) ;<-- localize variable (prompt "\n<<let circle become polygon>>") (prompt "\n<<please select circle:>>") (setq ss (ssget '((0 . "circle")))) (if (null n)(setq n 4)) (setq i 0) [color="red"](setq ll(getreal "\nlength:"))[/color] ;<--- move this before repeat loop ([color="blue"]repeat[/color] (sslength ss) (setq en (ssname ss i)) (setq endata (entget en)) (setq cen (cdr (assoc 10 endata))) (command "polygon" n cen "c" (/ ll 2)) (entdel en) (setq i (1+ i)) ) (princ) ) HTH Quote Link to comment Share on other sites More sharing options...
Rain0923 Posted October 15, 2014 Author Share Posted October 15, 2014 hanhphuc --->Many thanks for your help, it can work now YA!! hi Rain0923,welcome to forum if the length is applied for each circle, then you can put outside the repeat loop (defun c:ctrr ( / [color="red"]ss n i ll en endata cen [/color] ) ;<-- localize variable (prompt "\n<<let circle become polygon>>") (prompt "\n<<please select circle:>>") (setq ss (ssget '((0 . "circle")))) (if (null n)(setq n 4)) (setq i 0) [color="red"](setq ll(getreal "\nlength:"))[/color] ;<--- move this before repeat loop ([color="blue"]repeat[/color] (sslength ss) (setq en (ssname ss i)) (setq endata (entget en)) (setq cen (cdr (assoc 10 endata))) (command "polygon" n cen "c" (/ ll 2)) (entdel en) (setq i (1+ i)) ) (princ) ) HTH Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted October 15, 2014 Share Posted October 15, 2014 you are welcome. yeah. Marco's tips also helpful, if you are working in different UCS, thanx (setq cen [color="red"](trans [/color](cdr (assoc 10 endata)) [color="red"]0 1)[/color]) Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted October 15, 2014 Share Posted October 15, 2014 No, it's not that hanhphuc... Should be : (setq cen [color=red](trans [/color](cdr (assoc 10 endata)) [color=darkred](cdr (assoc -1 endata))[/color][color=red] 1)[/color]) Circles centers are defined in their OCS - it's not the same as ellipse where this DXF 10 code belongs to WCS... Or better, for already known ename : (setq cen [color=red](trans [/color](cdr (assoc 10 endata)) [color=darkred]en[/color][color=red] 1)[/color]) Quote Link to comment Share on other sites More sharing options...
SLW210 Posted October 15, 2014 Share Posted October 15, 2014 Rain0923, Please read the Code Posting Guidelines and edit your post to include the Code in Code Tags. Quote Link to comment Share on other sites More sharing options...
Rain0923 Posted October 15, 2014 Author Share Posted October 15, 2014 Marko, I need to thank you also, you and hanhphuc are very kind. This is my first time that I write the lisp so it can work I feel very happy. Thank you two QUOTE=marko_ribar;610942]No, it's not that hanhphuc... Should be : (setq cen [color=red](trans [/color](cdr (assoc 10 endata)) [color=darkred](cdr (assoc -1 endata))[/color][color=red] 1)[/color]) Circles centers are defined in their OCS - it's not the same as ellipse where this DXF 10 code belongs to WCS... Or better, for already known ename : (setq cen [color=red](trans [/color](cdr (assoc 10 endata)) [color=darkred]en[/color][color=red] 1)[/color]) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.