代码改变世界

AutoLISP线段端点画圆和内接正方形

2011-03-28 10:17  精诚所至 金石为开  阅读(632)  评论(0编辑  收藏  举报

AutoLISP线段端点画圆和内接正方形,代码如下。

(defun c:test()
  (setvar "cmdecho" 0)
  (setq en (car (entsel "\n选取线:")))
  (setq endata (entget en))
  (setq pt1 (cdr (assoc 10 endata)))
  (setq pt2 (cdr (assoc 11 endata)))
  (setq dd (distance pt1 pt2))
  (setq ang (angle pt1 pt2))
  (setq s_rr (/ dd 5))
  (princ (strcat "\n------<线段长度=" (rtos dd 2) ">------"))
  (setq str_rr (strcat "\n圆半径<" (rtos s_rr 2) ">:"))
  (setq rr (getdist pt1 str_rr))
  (if (null rr) (setq rr s_rr))
  (command "circle" pt1 rr)
  (setq ciren1 (entlast))
  (command "circle" pt2 rr)
  (setq ciren2 (entlast))
  (command "trim" ciren1 ciren2 "" (list en pt1) (list en pt2) "")
  (command "polygon" 4 pt1 "i" (polar pt1 ang rr))
  (command "polygon" 4 pt2 "i" (polar pt2 (- ang pi) rr))
  (prin1)
  )

代码完。