推荐于2016-02-25 · 知道合伙人软件行家
;程序写了一个,选择圆,然后选择圆外一点,得到的图形如下
(defun C:tes ( / #k1 #os1 &r1 &tc1 ang1 ent1 ent2 ob1 ob2 pt1 pt2 pt3 x)
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(vl-load-com) ;;加载vlax扩展函数
(setq #os1 (getvar "osmode"))
(if (and (setq ent1 (entsel "\n请选择圆"));1
(setq ent1 (car ent1))
(setq #k1 (entget ent1))
(= (cdr (assoc 0 #k1)) "CIRCLE")
(setq ob1 (vlax-ename->vla-object ent1))
(setq pt1 (getpoint "\n请选择圆外一点"))
)
(progn;;1
(setvar "osmode" 0)
(setq pt2 (cdr (assoc 10 #k1));提取圆心坐标
&tc1 (cdr (assoc 8 #k1));取得圆图层
)
(setq pt3 (mapcar '(lambda (x) (* x 0.5)) (mapcar '+ pt1 pt2)));两点中心点
(setq &r1 (distance pt3 pt1));长度
(entmake (list '(0 . "CIRCLE") (cons 10 pt3) (cons 40 &r1)));绘制圆
(setq ent2 (entlast) ob2 (vlax-ename->vla-object ent2))
(if (and (setq pt3 (vlax-invoke ob1 'IntersectWith ob2 0));2
(= (length pt3) 6)
);计算交点,如果在圆外一点就有交点
(progn;;2
(setq &r1 (cdr (assoc 40 #k1)));取得圆半径
(setq ang1 (angle pt2 pt1) pt2 (polar pt2 ang1 &r1));计算修剪点
(command "TRIM" ent2 "" (list ent1 pt2) "");修剪圆
(repeat 2
(setq pt2 (list (car pt3) (cadr pt3)) pt3 (cdddr pt3))
(entmake (list '(0 . "LINE") (cons 8 &tc1) (cons 10 pt1) (cons 11 pt2)));绘制切线
);repeat
);progn;2
);if;2
(entdel ent2) ;删除绘制的圆
(setvar "osmode" #os1)
);progn;1
);if;1
(prin1)
);复制到记事本,以【.lsp】为后缀命名,autolisp加载,命令【TES】