我大致看了一下,主要意图是给pline线节点写编号的程序,主要看了一下正向编号的程序,大致思路是这样的(一下内容为正向编号,即代码为1):
程序执行后先输入“字体高度”,依次为选择“正反向编号代码(1为正向,2为反向)”,选择pline线及需要输入编号的第一个节点(鼠标输入后程序会在该点写入编号“1”),程序自动去选择plist剩余节点然后进行相应编号,假如所选的第一个节点并非pline线的起点,程序在转回起点进行累加编号。
另:程序中还有几处错误!(if (or (= key 1) (= key nil))应改为(if (or (= key "1") (= key nil))
(command "text" pt0 h "0" 1)应改为(command "text" pt0 h "0" "1")
更改后的程序:
- (defun c:bh ()
- ;编号高度
- (if (null h)
- (setq h (getvar "textsize"))
- )
- (setq input (getreal (strcat "\\n\\t输入编号高度<" (rtos h) ">")))
- (if (/= input nil)
- (setq h input)
- )
- (initget "1 2")
- (setq key (getkword "\\n\\t1-正向编号/2-反向编号<1>:"))
- (setq s1 (entsel "\\n\\t选择对象<退出>"))
- (setq ent (entget (car s1)))
- (redraw (car s1) 3)
- (setq pt0 (getpoint "\\n选择编号起号位置"))
- (setq x (car pt0))
- (setq y (cadr pt0))
- (redraw (car s1) 4)
- (setq n (cdr (assoc 90 ent)))
- ;正向编号
- (if (or (= key "1") (= key nil))
- (progn
- (command "text" pt0 h "0" "1")
- (setq plist (member (list 10 x y) ent))
- (SETQ pplist (member (assoc 10 ent) ent))
- (setq count 1)
- (setq d (cdr plist))
- (setq plist (member (assoc 10 d) d))
- (while (/= plist nil)
- (setq count (1+ count))
- (setq pp_t (car plist))
- (setq pp (cdr pp_t))
- (command "text" pp h "0" (itoa count))
- (setq d (cdr plist))
- (setq plist (member (assoc 10 d) d))
- )
- (while (/= pplist nil)
- (setq count (1+ count))
- (setq pp_t (car pplist))
- (setq pp (cdr pp_t))
- (setq pp_x (car pp))
- (setq pp_y (cadr pp))
- (if (and (= pp_x x) (= pp_y y))
- (exit)
- (progn
- (command "text" pp h "0" (itoa count))
- (setq d (cdr pplist))
- (setq pplist (member (assoc 10 d) d))
- ) ;end progn
- ) ;end if
- ) ;end while
- ) ;end progn
- ;反向编号
- (progn
- (command "text" pt0 h "0" (itoa n))
- (setq plist (member (list 10 x y) ent))
- (SETQ pplist (member (assoc 10 ent) ent))
- (setq d (cdr plist))
- (setq plist (member (assoc 10 d) d))
- (setq n (1- n))
- (while (/= plist nil)
- (setq pp_t (car plist))
- (setq pp (cdr pp_t))
- (command "text" pp h "0" (itoa n))
- (setq d (cdr plist))
- (setq plist (member (assoc 10 d) d))
- (setq n (1- n))
- )
- (while (/= pplist nil)
- (setq pp_t (car pplist))
- (setq pp (cdr pp_t))
- (setq pp_x (car pp))
- (setq pp_y (cadr pp))
- (if (and (= pp_x x) (= pp_y y))
- (exit)
- (progn
- (command "text" pp h "0" (itoa n))
- (setq d (cdr pplist))
- (setq pplist (member (assoc 10 d) d))
- (setq n (1- n))
- ) ;end progn
- ) ;end if
- ) ;end while
- ) ;end progn
- ) ;end if
- ) ;end defun
- (prompt
- "\\n多义线角点自动编号程序,键入:bh执行,程序设计:小谢"
- )
- (princ)
以下图片是程序执行结果,点1即为输入编号的第一个节点(本来想做个flash动画,可惜我的软件过期了): |