明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1706|回复: 8

如何实现autolisp调用数据文件*.dat

[复制链接]
发表于 2004-10-6 15:08:00 | 显示全部楼层 |阅读模式
能否发个LISP编写的源程序看看,如果可行的话,我将学习编写标准件,提供给大家
发表于 2004-10-6 15:11:00 | 显示全部楼层
Use the following functions:


open, read-line, close


Read on-line help file of AutoCAD for details.
 楼主| 发表于 2004-10-6 17:22:00 | 显示全部楼层
能不能发个简单的例子啊
发表于 2004-10-6 17:46:00 | 显示全部楼层
;;;调用格式 (GET_FILE_NR "aa.dat")
(defun GET_FILE_NR (fi / fil pe fel screw_list)
(setq screw_list nil)
(if (findfile fi)
(progn
(setq fil (findfile fi))
(setq pe (open fil "r"))
(setq fel T)
(while (/= fel nil)
(setq fel (read-line pe))
(setq screw_list (cons fel screw_list))
)
(close pe)
(setq screw_list (cdddr (reverse (cdr screw_list))))
;根据文本的内容而定
)
)
screw_list
)
 楼主| 发表于 2004-10-7 08:46:00 | 显示全部楼层
请帮忙帮我改一下我的这个程序好不好: LISP文件: (defun read_file()
(findfile "ddd.dat")
(setq fname "ddd.dat")
(setq rdata (open fname "r"))
(setq data1 (read-line rdata))
(setq data1-1 (read data1)) (setq canshu data1-1)
(setq d1 (nth 0 canshu))
(setq d2 (nth 1 canshu))
(setq d3 (nth 2 canshu))
(setq d4 (nth 3 canshu))
(close rdata)
) (defun fanhui()
(setq shuju (get_tile "canshu"))
(setq shuju (atof shuju))
)
(defun C:dd()
(setq pt1 (getpoint "\n请输入绘制点:"))
(setq pt2 (polar pt1 0 (* scal 20)))
(setq pt3 (polar pt1 0 (* scal 40)))
(setq pt4 (polar pt1 0 (* scal 60)))
(read_file)
(setq shuju (get_tile "canshu"))
(fanhui)
(command "text" pt1 "" "" d1)
(command "text" pt2 "" "" d2)
(command "text" pt3 "" "" d3)
(command "text" pt4 "" "" d4) ) DAT文件:文件名为ddd.dat (20 15 4 5)
(25 20 5 6)
(30 25 5 6)
(40 32 6 5)
(50 42 8 10)
发表于 2004-10-7 10:07:00 | 显示全部楼层
(defun read_file ()
(findfile "ddd.dat")
(setq fname "ddd.dat")
(setq rdata (open fname "r"))
(setq data1 (read-line rdata))
(setq data1-1 (read data1))
(setq canshu data1-1)
(setq d1 (nth 0 canshu))
(setq d2 (nth 1 canshu))
(setq d3 (nth 2 canshu))
(setq d4 (nth 3 canshu))
(close rdata)
) (defun C:dd ()
(setq scal 1)
(setq pt1 (getpoint "\n请输入绘制点:"))
(setq pt2 (polar pt1 0 (* scal 20)))
(setq pt3 (polar pt1 0 (* scal 40)))
(setq pt4 (polar pt1 0 (* scal 60)))
(read_file)
(command "text" pt1 "" "" d1)
(command "text" pt2 "" "" d2)
(command "text" pt3 "" "" d3)
(command "text" pt4 "" "" d4)
)
 楼主| 发表于 2004-10-7 10:15:00 | 显示全部楼层
怎么还不能用啊
发表于 2004-10-7 12:34:00 | 显示全部楼层
你确定ddd.dat在搜索路径里吗?????? 把其中一个函数改成如下试试 (defun read_file ()
(setq fname (getfiled "" "" "dat" 0)
(setq rdata (open fname "r"))
(setq data1 (read-line rdata))
(setq data1-1 (read data1))
(setq canshu data1-1)
(setq d1 (nth 0 canshu))
(setq d2 (nth 1 canshu))
(setq d3 (nth 2 canshu))
(setq d4 (nth 3 canshu))
(close rdata)
)
 楼主| 发表于 2004-10-7 13:31:00 | 显示全部楼层
非常感谢呀,终于成功了 (setq fname (getfiled "" "" "dat" 0)   后面再加个)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-18 13:24 , Processed in 0.261378 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表