本帖最后由 tryhi 于 2015-9-10 15:45 编辑
- (setq rrno1 5)
- ;;函数名:zjhy(自交画圆)
- ;;功能:在多段线是线自相交处画圆圈标注
- ;;注:多段线为纯线段,不含弧线
- (defun c:zjhy(/ $i $j jiaodian lss nn ns os pt1 pt2 pt3 pt4)
- (setq lss (Vertexs (car(entsel))));获取定点表
- (setq rrno1 (ureal 0 "" "输入圆圈半径" rrno1))
- (setq nn 0)
- (setq os (getvar "osmode"))
- (setvar "osmode" 0)(setvar "CMDECHO" 0)
- (setq ns (length lss));返回顶点个数
- (setq $i 0);循环初始
- (setq $j 2);嵌套循环初始
- (repeat (- ns 1);循环从第一点到倒数第二点
- (repeat (if(= $i 0)(1-(- ns $j))(- ns $j));循环到第一点(首点除外)
- (setq pt1(nth $i lss));0
- (setq pt2(nth (1+ $i) lss));1
- (setq pt3(nth $j lss));2
- (setq pt4(nth (if(=(1+ $j)ns)0(1+ $j)) lss));3(超过最后一个点跳到第一点)
- (setq jiaodian(inters pt1 pt2 pt3 pt4));判断线段相交
- (if jiaodian(command "CIRCLE" jiaodian rrno1));画圆
- (if jiaodian(setq nn(1+ nn)));计数
- (setq $j (1+ $j))
- )
- (setq $i (1+ $i))
- (setq $j (+ 2 $i))
- )
- (setvar "osmode" os)
- (princ "\n共找到") (princ nn)(princ "个自相交点。")
- (prin1)
- )
- (prompt
- "\n******* zjhy[自交画圆]命令加载完成!*******------tryhi----2015-9-10"
- )(prin1)
- ;;返回多段线顶点表
- (defun Vertexs (s1 / lst);
- (setq lst (entget s1)
- lst (vl-remove-if-not '(lambda (x) (= (car x) 10)) lst)
- lst (mapcar 'cdr lst)
- )
- )
- ;; 实型数输入格式化
- (defun ureal (bit kwd msg def / inp)
- (if def
- (setq msg (strcat "\n" msg "<" (rtos def 2) ">: ") bit (* 2 (fix (/ bit 2))))
- (setq msg (strcat "\n" msg ": "))
- )
- (initget bit kwd)
- (setq inp (getreal msg))
- (if inp inp def)
- )
|