马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 晨曦CAD 于 2021-3-13 19:54 编辑
 - ;;list数据输出到文件
- ;@晨曦 2021.3
- ;输入参数:lst list数据
- ; ff 文件描述符,open函数返回值
- (defun list->file(lst ff / i temp conslst)
- (princ "(" ff)
-
- ;处理关联表
- (if(= (isRealList lst) 2)
- (progn
- (setq conslst(nth 1 (con2list lst))
- lst(nth 0 (con2list lst)))
- )
- )
-
- (setq i 0)
- (repeat(length lst)
- (setq temp(nth i lst))
- (cond
- ;list
- ((= (type temp) (quote LIST)) (list->file temp ff))
- ;字符串
- ((= (type temp) (quote STR)) (princ (chr 34) ff)(princ temp ff)(princ (chr 34) ff))
- ;int real数值
- ((or(= (type temp) (quote INT))(= (type temp) (quote REAL))) (princ temp ff)(princ (chr 32) ff))
- ;图元(实体名会变 ,此处输出为字符串)
- ((= (type temp) (quote ENAME)) (princ (chr 34) ff)
- (princ (vl-string-subst "" " "(VL-PRINC-TO-STRING temp)) ff)
- (princ (chr 34) ff))
- ;选择集(此处仅输出为选择集名称LIST)
- ((= (type temp) (quote PICKSET))(list->file (list (VL-PRINC-TO-STRING temp)) ff))
- ;符号
- ((= (type temp) (quote SYM))(princ temp ff)(princ (chr 32) ff))
- );cond
- (setq i(1+ i))
- );repeat
-
- ;处理关联表
- (if(/= conslst nil)
- (progn
- (princ (chr 32) ff) ;空格
- (princ (chr 46) ff) ;逗号
- (princ (chr 32) ff)
- (cond
- ;list
- ((= (type conslst) (quote LIST)) (list->file conslst ff))
- ;字符串
- ((= (type conslst) (quote STR)) (princ (chr 34) ff)(princ conslst ff)(princ (chr 34) ff))
- ;int real数值
- ((or(= (type conslst) (quote INT))(= (type conslst) (quote REAL))) (princ conslst ff)(princ (chr 32) ff))
- ;图元(实体名会变,可自动转换为句柄 DXF 5 ,此处输出为字符串)
- ((= (type conslst) (quote ENAME)) (princ (chr 34) ff)
- (princ (vl-string-subst "" " "(VL-PRINC-TO-STRING conslst)) ff)
- (princ (chr 34) ff))
- ;选择集(此处仅输出为选择集名称LIST)
- ((= (type conslst) (quote PICKSET))(list->file (list (VL-PRINC-TO-STRING conslst)) ff))
- ;符号
- ((= (type conslst) (quote SYM))(princ conslst ff)(princ (chr 32) ff))
- )
- )
- )
-
- (princ ")" ff)
- )
;测试案例
(defun tt(/ ll f )
(setq ll (list 1 2 "3" "4" 5 '(1 2 "3" 4 "" 5) (cons 44 55)(CAR(ENTSEL))'<))
(setq f(open "TT.txt" "w"))
(list->file ll f)
(close f)
)
|