我们一起学习lisp开发(第二辑)
这一辑做个程序绘制图框和标题栏,看了之后能充分体会到AutoLISP的工作原理程序源代码如下:
;;;绘制A4图框和标题栏
(defun c:a4 (/ v1 v2 lj cl shl bl) ;定义命令的名字为a4
;;初始化环境
(setq v1 (getvar "osmode"))
(setq v2 (getvar "cmdecho"))
(setvar "osmode" 0)
(setvar "cmdecho" 0)
;;获取初值
(setq lj (getstring "\n输入零件名称: "))
(setq cl (getstring "\n输入零件材料: "))
(setq shl (getint "输入零件数量: "))
(setq shl (itoa shl)) ;将整数转换为字符串
(setq bl (getstring "\n输入绘图比例: "))
;;
(command "style" "hz" "gbcbig" "" "" "" "" "" "") ;定义汉字样式为hz(6个默认)
(command "layer" "m" "xixian" "") ;生成当前图层xixian
(command "limits" "0,0" "210,297")
(command "zoom" "a")
(command "line" "0,0" "210,0" "210,297" "0,297" "c") ;绘制a4图纸边界线
(command "layer" "m" "cuxian" "lw" 0.3 "" "") ;生成当前图层cuxian
(command "line" "25,5" "205,5" "205,292" "25,292" "c") ;绘制图框粗线
(command "line" "85,5" "85,27" "205,27" "") ;绘制标题栏框粗线
(command "layer" "m" "xixian" "") ;在细线层上绘制内部线条
(command "line" "85,13" "205,13" "")
(command "line" "100,13" "100,27" "")
(command "line" "120,13" "120,27" "")
(command "line" "132,5" "132,27" "")
(command "line" "162,5" "162,13" "")
(command "line" "180,5" "180,27" "")
(command "line" "85,20" "132,20" "")
(command "layer" "m" "wenzi" "") ;生成当前图层wenzi
(command "text" "m" (list 108.5 9) 5 0 "清华大学机械厂") ;填写标题栏
(command "text" "m" (list 147 9) 5 0 (strcat "材料" cl))
(command "text" "m" (list 171 9) 5 0 (strcat "数量" shl))
(command "text" "m" (list 192.5 9) 5 0 (strcat "比例" bl))
(command "text" "m" (list 92.2 23.5) 5 0 "制图")
(command "text" "m" (list 92.2 16.5) 5 0 "校核")
(command "text" "m" (list 156 20) 10 0 lj) ;零件名
;;还原环境设置
(setvar "osmode" v1)
(setvar "cmdecho" v2)
(princ)
)
读完代码你会惊奇的发现,这不就是画图过程嘛:调用的command命令,一句一句的执行,一点难度都没有。lisp就是这样,很容易理解。(只要记住了第一辑讲的,呵呵!)
看懂程序后对它稍微一改,就能做出符合自己要求的图框和标题栏,一劳永逸,岂不快哉。(注意:由于版本的变化,可能需要对程序稍作修改才能适应)
(程序里有看不大明白的都可以跟贴问啊,我相信很多人都会乐意助人解惑的)
[ 本帖最后由 yrgui 于 2008-10-3 18:26 编辑 ] 好的东西,学习学习
回复
估计 得从基础的基础开始学习...... 看不怎么懂啊~~~看看先回复
比想象的稍微简单那么一点点 看不懂,哎,这么难学呀 有没有学这个的资料啊回复 #7 ljwin82 的帖子
可以去大一点的图书店买一本教材,或者网上邮购。其实:) ACAD帮助文件里就有开发人员帮助文档,也不错。还是那句话:遇到问题上论坛问,不就OK了。[ 本帖最后由 yrgui 于 2008-10-10 13:01 编辑 ] 版主真好,学习学习 有点困难,看不懂,全是代码.它跟CAD能交替使用么?
下了
下了,顶一个!!!谢了 虽然不是太懂,还是谢谢了 ,最近正在学,有什么问题再请教 原帖由 yushuluan 于 2008-10-23 15:15 发表 http://askcad.com/bbs/images/common/back.gif虽然不是太懂,还是谢谢了 ,最近正在学,有什么问题再请教
发点时间学程序很值的! 刚刚起步,估计我需要从基础开始 顶了再看!!!!