盛麒毓 发表于 2011-4-10 19:52:34

请教如何用Lisp生成txt文件

如题,请教各位如何实现,先谢过了

mandala 发表于 2011-4-10 20:06:53

一个例子,将一个点坐标列表的内容输出到idout.txt。你可以参考一下。
(defun pointout
       (pointlist / f i point x y point1)
       (setq f (open "idout.txt" "w"))
       (setq i 0)
       (repeat (length pointlist)
      (setq point (nth i pointlist))
      (setq x (/ (car point) 2)
      y (/ (cadr point) 2)
      ) ;_ 结束setq
      (setq x (/ (fix (* x 1e5)) 1e5)
      y (/ (fix (* y 1e5)) 1e5)
      ) ;_ 结束setq
      (princ (strcat (if (= i 0)
             ""
             "\n"
         ) ;_ 结束if
         (itoa (1+ i))
         ","
         (rtos x 2 5)
         ","
         (rtos y 2 5)
         ) ;_ 结束strcat
         f
      ) ;_ 结束princ
      (setq i (1+ i))
       );repeat
       (setq point1 (nth 0 pointlist)
       x      (/ (car point1) 2)
       y      (/ (cadr point1) 2)
       ) ;_ 结束setq
       (setq x (/ (fix (* x 1e5)) 1e5)
       y (/ (fix (* y 1e5)) 1e5)
       ) ;_ 结束setq
       (princ (strcat "\n" (itoa 1) "," (rtos x 2 5) "," (rtos y 2 5))
      f
       ) ;_ 结束princ
       (close f)
) ;_ 结束dufun

盛麒毓 发表于 2011-4-10 20:15:31

回复 mandala 的帖子

恩,谢谢啦

mandala 发表于 2011-4-10 22:27:37

本帖最后由 mandala 于 2011-4-10 22:28 编辑

输出的路径可以自己设置,如c:\\cad\\works\\或d:/works/123/。我这个lsp里选择的是默认路径。
页: [1]
查看完整版本: 请教如何用Lisp生成txt文件