明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2664|回复: 5

批量给圆孔、圆弧画中心线的程序

[复制链接]
发表于 2004-9-16 15:29:00 | 显示全部楼层 |阅读模式
(defun C:mc (/ circle-ssget arc-ssget temp-int
temp-entname var-osmode var-layer var-cmdecho
p1 p2 p3 p4
dia-value center-point
)
(setq var-osmode (getvar "osmode"))
(setq var-layer (getvar "clayer"))
(setq var-cmdecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(if (= (tblsearch "layer" "center") nil)
(command "layer" "new" "center" "color" 1
"center" "ltype" "center" "center" "set"
"center" ""
)
(command "layer" "set" "center" "")
)
(setq circle-ssget
(ssget
"c"
(setq p1
(getpoint
"\n您选择框内的所有圆和圆弧都画上中心线。\n 请给出选择框的第一个点:"
)
)
(progn
(print "请给出选择框的对角点:")
(while (/= 3 (car (setq p2 (grread 1 1 0))))
(redraw)
(grdraw p1 (list (car p1) (nth 1 (cadr p2))) -1 1)
(grdraw p1 (list (nth 0 (cadr p2)) (nth 1 p1)) -1 1)
(grdraw (cadr p2)
(list (nth 0 (cadr p2)) (nth 1 p1))
-1
1
)
(grdraw (cadr p2)
(list (nth 0 p1) (nth 1 (cadr p2)))
-1
1
) (setq p2 (cadr p2)) )
)
'((0 . "circle")) )
)
(redraw)
(setvar "osmode" 0)
(setq arc-ssget (ssget "c" p1 (cadr p2) '((0 . "arc"))))
(setq temp-int 0)
(if (/= circle-ssget nil)
(repeat (sslength circle-ssget)
(setq temp-entname (ssname circle-ssget temp-int))
(setq center-point (cdr (assoc 10 (entget temp-entname))))
(setq dia-value (cdr (assoc 40 (entget temp-entname))))
(setq dia-value (* 1.3 dia-value))
(setq
p1
(list (car center-point) (- (nth 1 center-point) dia-value))
)
(setq
p2
(list (car center-point) (+ (nth 1 center-point) dia-value))
)
(setq p3 (list (- (nth 0 center-point) dia-value)
(nth 1 center-point)
)
)
(setq p4 (list (+ (nth 0 center-point) dia-value)
(nth 1 center-point)
)
)
(command "line" p1 p2 "")
(command "line" p3 p4 "")
(setq temp-int (+ temp-int 1))
)
)
(princ)
(princ) (setq temp-int 0)
(if (/= arc-ssget nil)
(repeat (sslength arc-ssget)
(setq temp-entname (ssname arc-ssget temp-int))
(setq center-point (cdr (assoc 10 (entget temp-entname))))
(setq dia-value (cdr (assoc 40 (entget temp-entname))))
(setq dia-value (* 1.3 dia-value))
(setq
p1
(list (car center-point) (- (nth 1 center-point) dia-value))
)
(setq
p2
(list (car center-point) (+ (nth 1 center-point) dia-value))
)
(setq p3 (list (- (nth 0 center-point) dia-value)
(nth 1 center-point)
)
)
(setq p4 (list (+ (nth 0 center-point) dia-value)
(nth 1 center-point)
)
)
(command "line" p1 p2 "")
(command "line" p3 p4 "") (setq temp-int (+ temp-int 1))
)
)
(setvar "osmode" var-osmode)
(command "layer" "set" var-layer "")
(setvar "cmdecho" var-cmdecho)
(princ)
(princ)
) 1 该程序可以在你框选内自动识别圆孔、圆弧;
2 该程序将画好的中心线放在CENTER图层里(如果你没有建这个层,命令会自动建立该层),该图层设为中心线层。
刚刚学习用LISP,写得不好,请不要丢西红柿。
发表于 2004-9-16 16:39:00 | 显示全部楼层
发表于 2004-9-16 16:42:00 | 显示全部楼层
我丢一个: 选择圆为何不直接用ssget '((0 . "circle")))?前面加个提示: (prompt "请选择圆...")
(ssget '((0 . "circle"))) 这样不一定采用C的方式,选择方式由用户去决定,还可以多种方式并存,不是更好?
发表于 2004-9-17 04:38:00 | 显示全部楼层
;;重来不用画这个,纯玩玩:),现编一个
  1. (defun c:cenline ( / ss i ocen e pt out2) ;; out 全局.
  2.    (princ "\n画圆心标志,选择标注实体:")
  3.    (vl-cmdf ".undo" "be")
  4.    (setq ss (ssget '((0 . "CIRCLE,ARC")))
  5.   out2 (getdist (strcat "\n线出头长度" (if out (rtos out 2 2) "") ":"))
  6.   i -1
  7.   ocen (getvar "dimcen"))
  8.    (if out2 (setq out out2))
  9.    (while (setq e (ssname ss (setq i (1+ i))))
  10.        (setvar "dimcen" (+ out (cdr (assoc 40 (entget e)))))
  11.        (setq pt (vlax-curve-getstartpoint e))
  12.        (vl-cmdf "dimcenter" (princ (list e pt)))
  13.    )
  14.    (setvar "dimcen" ocen)
  15.    (vl-cmdf ".undo" "e")
  16.    (princ)
  17. )
发表于 2004-9-17 15:42:00 | 显示全部楼层
本帖最后由 作者 于 2004-9-17 23:08:02 编辑

无痕发表于2004-9-17 4:38:00;;重来不用画这个,纯玩玩:),现编一个 getdist (strcat \"\n线出头长度\"
岂不麻烦?应该改,(按直径的15%比较好)
发表于 2004-9-17 19:28:00 | 显示全部楼层
怎么适合怎么改啦,我不用这个的,也不知道出头长度的通常要求
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-18 17:51 , Processed in 0.170568 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表