Jump to content

Help!!Lisp!!Circle become polygon(polygon can't change at the same time)


Rain0923

Recommended Posts

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)

)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

--->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

Link to comment
Share on other sites

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])

Link to comment
Share on other sites

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])

Link to comment
Share on other sites

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])

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...