ini文件读取咨询
请教下大家有一 123.ini文件
内容如下
A C D R M G ;可能还有其它列
3 1.5 2 3 5 2.5
4 2 2.5 4 6 3.3
5 2.5 3 5 6 4.2
可能还有其它行
### 说明文字
### 说明文字
想实现功能
(cond
((= (abs A) 3)(setq C 1.5) (setq D 2) (setq R 3) (setq M 5)(setq G 2.5))
((= (abs A) 4)(setq C 2) (setq D 2.5) (setq R 4) (setq M 6)(setq G 3.3))
((= (abs A) 5)(setq C 2.5) (setq D 3) (setq R 5) (setq M 6)(setq G 4.2))
((= (abs A) 6)(setq C 3) (setq D 4) (setq R 6) (setq M 7)(setq G 5.0))
........
)
(defun C:44 ()
(setq fname "123.ini")
(setq f (findfile fname ))
(setq tx (strcat "★" fname "★" "文件丢失" ",程序退出"))
(if(not f)
(progn(alert tx)(exit)))
(setq ff (open f "r"))
(while (and (setq txt1 ( read-line ff)))
(if (and (/= "" (substr txt1 1 1))
(/= " " (substr txt1 1 1))
(/= "#" (substr txt1 1 1)))
(PROGN
(setq TXT_TD (CONS TXT1 TXT_TD))
;这里不会写了........
)
)
)
(CLOSE ff)
(princ)
)
本帖最后由 1028695446 于 2021-1-26 22:33 编辑
;;主程序
(defun C:44 ()
(setq fname "D:/123.ini")
(setq tx (strcat "★" fname "★" "文件丢失" ",程序退出"))
(if (and
(setq f (findfile fname ))
(setq str_lst(Get_Txt f))
)
(progn
(setq lst1
(vl-remove-if-not
'(lambda(txt1)
(and
(/= "" (substr txt1 1 1))
(/= " " (substr txt1 1 1))
(/= "#" (substr txt1 1 1))
)
)
str_lst
)
) ;;移除首字符是#,空格,空行
(setq lst2
(mapcar
'(lambda(x)(Split-ZZ x " "))
lst1
)
)
(setq lst3
(mapcar
'(lambda(x)(cons (car x) (list(cdr x))))
lst2
)
)
(setq A "3")
(mapcar 'set '(C D R M G) '(nil nil nil nil nil))
(if (setq lst4 (assoc A (cdr lst3)))
(mapcar
'(lambda(x y)(eval(read(strcat "(setq " x " " y")"))));;赋值
(setq lst33(car(cdr(car lst3))))
(setq lst44(car(cdr lst4)))
)
)
(princ lst33)
(princ "\n")
(princ lst44)
)
(progn
(alert tx)
(exit)
)
)
(princ)
)
;;获取文本内容转为表
(defun Get_Txt (datfile / exec tmplst x fn)
(setq fn (open datfile "r"))
(while (setq x (read-line fn))
(setq tmplst (append tmplst (list x)))
)
(close fn)
tmplst
)
;;分割字符为表
(defun Split-ZZ (s p / L r)
(setq r (vlax-create-object "vbscript.regexp"))
(vlax-put-property r 'Global 1)
(vlax-put-property r 'Pattern (strcat "([^" p "]+)"))
(vlax-for x (vlax-invoke r 'Execute s)
(setq L (cons (vla-get-Value x) L))
)
(vlax-release-object r)
(reverse L)
)
(princ)
谢谢,1028695446网友 谢谢! 1028695446分享程序!!!!! 1028695446 发表于 2021-1-26 22:31
;;主程序
(defun C:44 ()
(setq fname "D:/123.ini")
你好我没看懂这个程序干了啥,能不能解释下
页:
[1]