注意文本的书写格式保持一致- (defun DelSpace(a / n i str strtmp)
- (setq n (strlen a))
- (setq i 1)
- (setq str (substr a 1 1))
- (while (= (substr a i 1) " ")
- (setq str (substr a (1+ i) 1))
- (setq i (1+ i))
- )
- (setq i (1+ i))
- (while (<= i n)
- (setq strtmp (substr a i 1))
- (if (/= strtmp " ")
- (setq str (strcat str strtmp))
- )
- (setq i (1+ i))
- )
- str
- )(defun ReadStr(str_line / str i ch strtmp lst ch_old)
- (setq str str_line)
- (setq i 1)
- (setq strtmp "")
- (setq lst nil)
- (repeat (strlen str)
- (setq ch (substr str i 1))
- (if (or (and (>= (ascii ch) 48) (<= (ascii ch) 57)) (= ch "."))
- (if (or (and (>= (ascii ch_old) 48) (<= (ascii ch_old) 57)) (= ch_old ".") (= ch_old "="))
- (setq strtmp (strcat strtmp ch))
- )
- (progn
- (if (/= strtmp "")
- (setq lst (append lst (list (atof strtmp))))
- )
- (setq strtmp "")
- )
- )
- (setq ch_old ch)
- (setq i (1+ i))
- )
- (if (or (and (>= (ascii ch) 48) (<= (ascii ch) 57)) (= ch "."))
- (setq lst (append lst (list (atof strtmp))))
- )
- lst
- )
-
- ;函数ReadTet
- ;功能:选择文本文件,将文件中数据读入程序
- (defun ReadText( / fname f str pt_lst)
- (setq fname (getfiled "选择输入文件" "" "txt" 0));选择文件
- (if fname
- (progn
- (setq f (open fname "r"));打开文件
- ;循环读取数据,每组以X\t\tY\t\tZ标识,读取前要保证文本格式的正确性,以程序生成的为准
- (while (setq str (read-line f))
- (setq str (delspace str))
- (if (= (strcase (substr str 1 1)) "X")
- (progn
- (setq pt (ReadStr str))
- (setq pt1 (list (car pt) (cadr pt)))
- (setq pt2 (list (caddr pt) (cadddr pt)))
- (setq pt_lst (append pt_lst (list (list pt1 pt2))))
- )
- )
- );while
- (close f);关闭文件
- );progn
- );if
- pt_lst
- )(defun c:test( / pt_lst os)
- (setq pt_lst (ReadText))
- (setq os (getvar "osmode"))
- (setvar "osmode" 0)
- (mapcar '(lambda(e) (command "_.line" (car e) (cadr e) "")) pt_lst)
- (setvar "osmode" os)
- (princ)
- )
|