网站开发工具概述与比较,ps网站交互设计,展会展台搭建服务,做淘宝客网站需要备案吗目录 一、文件操作1.1 写文件1.2 读文件 二、对话框DCL2.1 初识对话框2.2 常用对话框界面2.2.1 复选框、列表框2.2.2 下拉框2.2.3 文字输入框、单选点框 2.3 Lisp对dcl的驱动2.4 对话框按钮实现拾取2.5 对话框加载图片2.5.1 幻灯片图片制作2.5.1 代码部分 一、文件操作
1.1 写… 目录 一、文件操作1.1 写文件1.2 读文件 二、对话框DCL2.1 初识对话框2.2 常用对话框界面2.2.1 复选框、列表框2.2.2 下拉框2.2.3 文字输入框、单选点框 2.3 Lisp对dcl的驱动2.4 对话框按钮实现拾取2.5 对话框加载图片2.5.1 幻灯片图片制作2.5.1 代码部分 一、文件操作
1.1 写文件
代码示例(defun c:writefile();getfiled函数对话框的名称默认文件夹路径过滤后缀名flag;getfiled返回的是文件的绝对路径是字符串(setq filepath (getfiled 选择要预览的对话框所在的文件 C:\\Users\\ txt 7));返回文件的操作符;w有则覆盖没有则新建。a有则追加无则新建(setq file (open filepath w))(write-line 0,0 file)(write-line 100,0 file)(close file)
)对话框选择
1.2 读文件
代码示例(defun c:readfile();getfiled返回的是文件的绝对路径是字符串(setq filepath (getfiled 选择要预览的对话框所在的文件 C:\\Users\\ txt 2));返回文件的操作符(setq file (open filepath r));操作文件操作符(setq fdata (read-line file));注意这里演示可以把一个命令拆分成几块(command pline)(while fdata(command fdata)(setq fdata (rade-line file)))(command )(close file)(print)
)对话框选择
二、对话框DCL
DCLDialog Control Language对话框控制语言后缀名dcl定义对话框样式布局。重点一定别忘了分号一定要用英文标点
2.1 初识对话框
显示效果 按确认会在命令行输出“确认”temp.lsp中定义 temp.dcl// 冒号后面为控件名字
// 对话框的名字demo1_dcl
demo1_dcl:dialog{// 中括号内为属性label对话框名;// 中括号内也可以包含空间:text{// 控件中的属性label对话框内容;}// cad封装好的控件ok_cancel; }temp.lsp完全版可以作为模版(defun C:demo1 ();选择dcl对话框文件一个对话框文件中可以包含多个对话框(setq dlg_file (getfiled 选择要预览的对话框所在的文件 C:\\Users\\ dcl 2))(if ( dlg_file nil) (exit));选择对话框文件中的demo1_dcl命名的对话框有此提示时候输入demo1_dcl(setq dlg_name (getstring \n输入对话框名称))(if ( dlg_name ) (exit));加载dcl对话框文件返回加载标识符如果只有文件名则搜索默认路径见代码下注释(setq dlg_id (load_dialog dlg_file));加载失败退出(if ( dlg_id 0) (exit));;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;用于保存对话框操作状态(setq std 0);创建对话框对象此时还没显示对话框可以向对话框中添加东西(if (not (new_dialog dlg_name dlg_id))(exit));此处有两个key值accept,cancel是系统封装的确定取消按钮控件的key名;确认是accept取消是cancel;done_dialog函数结束当前对话框并指定一个结束码;通常用来判断用户点击了哪个控件(action_tile accept (done_dialog 1))(action_tile cancel (done_dialog 0));启动对话框:开始接受使用者输入对话框获得控制权(setq std (start_dialog));卸载对话框控制权还给cad主程序(unload_dialog dlg_id);根据std做相应动作(if ( std 1) (print 确定))(if ( std 0) (print 取消))(print)
)默认搜索路径通过(getvar “acadprefix”) C:\Users\Administrator\appdata\roaming\autodesk\autocad 2014\r19.1\chs\support; C:\program files\autodesk\autocad 2014\support; C:\program files\autodesk\autocad 2014\fonts; C:\program files\autodesk\autocad 2014\help; C:\program files\autodesk\autocad 2014\support\zh-cn; C:\Program Files\Autodesk\AutoCAD 2014\drv; temp.lsp精简版(defun C:demo1 ()(setq dlg_file C:\\Users\\Administrator\\Desktop\\code\\temp.dcl)(setq std 0)(setq dlg_id (load_dialog dlg_file))(new_dialog demo1_dcl dlg_id)(action_tile accept (done_dialog 1))(action_tile cancel (done_dialog 0))(setq std (start_dialog))(unload_dialog dlg_id)(if ( std 1)(print 确定))(if ( std 0)(print 取消))(print)
)2.2 常用对话框界面
2.2.1 复选框、列表框
temp.dcldemo1_dcl:dialog{label带边框的单复选框;// row控件中的元素都在一行// boxed_row带边框的行:row{//带外边框的列:boxed_column{label水果;// 复选框:toggle{label苹果;}// value1默认选中预设值:toggle{label香蕉;value1;}:toggle{label石榴;}}// 清单选框:list_box{label蔬菜;// 直接换行分割list西红柿\n黄瓜\n金针菇;// 默认选择第三个从0开始value2;// 开启多选(按住shift)没有则是单选multiple_selecttrue;}}ok_cancel;}效果 加载temp.lsp及调出对话框同2.1
2.2.2 下拉框
temp.dcldemo1_dcl:dialog{label带边框的单复选框;spacer_1;:row{:popup_list{label干果;list核桃\n夏威夷果\n杏仁;// 默认选择第三个value2;// 右侧下拉框的宽度edit_width10;}}//加一个空行spacer_1;ok_cancel; }效果
2.2.3 文字输入框、单选点框
temp.dcldemo1_dcl:dialog{label对话框名;:row{ // 带边框的列排版用:boxed_column{label坐标;:edit_box{// 后的字母会有下划线对应键盘快捷键labelX 坐标;// 输入框宽度edit_width10;}}:boxed_radio_row{label性别;:radio_button{labelmale;}:radio_button{labelfemale;}:radio_button{labelmiddle;value1;}}}ok_cancel;}效果
2.3 Lisp对dcl的驱动
temp.lsp精简模式(defun C:demo1 ()(setq dlg_file C:\\Users\\Administrator\\Desktop\\code\\temp.dcl)(setq std 0);加载对话框文件(setq dlg_id (load_dialog dlg_file));创建对话框对象此时可以向里面加东西(new_dialog demo1_dcl dlg_id);设置对应key值的value(setdata);设置对应两个按钮控件的回调函数此处有两个(action_tile accept (getdata) (done_dialog 1))(action_tile cancel (done_dialog 0));显示对话框同时控制权从cad主程序转给对话框(setq std (start_dialog));卸载对话框(unload_dialog dlg_id);点确定做相应动作(if ( std 1)(command circle (list x y) r))(if ( std 0)(print 取消))(command zoom e)(print)
)
;获得控件对应key值的value其是字符串
(defun getdata ()(setq x (atof (get_tile cir_x)))(setq y (atof (get_tile cir_y)))(setq r (atof (get_tile cir_r)))
)
;设置控件对应key值的默认value其是字符串
;如果是radio等类型控件则其value值是真假0、1
;如果是list等类型控件则其value值是序号“0”、“1”、“2”
(defun setdata ()(set_tile cir_x 200.00)(set_tile cir_y 200.00)(set_tile cir_r 200.00)
)temp.dcldemo1_dcl:dialog{label对话框名;:boxed_row{ label画圆;:edit_box{labelX 坐标;edit_width10;// 设置控件的key值keycir_x;}:edit_box{labelY 坐标;edit_width10;// 设置控件的key值keycir_y;}:edit_box{labelR 半径;edit_width10;// 设置控件的key值keycir_r;}}ok_cancel;}显示效果
2.4 对话框按钮实现拾取 效果图 temp.dcl demo1_dcl:dialog{label绘制圆;:column{ :edit_box{labelR 半径;edit_width10;keycir_r;}:boxed_column{label中心;:button{label拾取中心点;keybut_cir;}:edit_box{labelX 坐标;edit_width10;keycir_x;}:edit_box{labelY 坐标;edit_width10;keycir_y;}}}spacer_1;ok_cancel;}temp.lsp (defun C:demo1 ()(setq dlg_id (load_dialogC:\\Users\\Administrator\\Desktop\\code\\temp.dcl))(if ( dlg_id 0) (exit));为了使下面while启动此处设置大于1的整型(setq r 200 x 200 y 200 std 2);只要没点确认或取消就一直循环(while ( std 1);注意每次循环都用相同的dcl文件创建一个新的对话框对象(if (not (new_dialog demo1_dcl dlg_id))(exit));设置控件value值(setdata cir_r r cir_x x cir_y y);设置按钮动作done_dialog函数可以关闭对话框(action_tile but_cir (getdata) (done_dialog 2))(action_tile accept (getdata) (done_dialog 1))(action_tile cancel (done_dialog 0));上面三个的done_dialog函数可以关闭对话框并返回std(setq std (start_dialog))(if ( std 2)(progn (initget 1)(setq p (getpoint \n请选择圆心))(setq x (car p) y (cadr p)))));跳出循环卸载对话框 (unload_dialog dlg_id);针对确定、取消做动作(if ( std 1)(command circle (list x y) r))(if ( std 0)(print 取消));退出前做了一次缩放(command zoom e)(print)
)
;;;获取当前控件key值对应的value并设置x y rdcl-》lisp
;;;用于计算
(defun getdata ()(setq x (atof (get_tile cir_x)))(setq y (atof (get_tile cir_y)))(setq r (atof (get_tile cir_r)))
)
;;;设置当前控件key值对应的valuelisp -》dcl
;;;用于展示
(defun setdata (key_r r1 key_x x1 key_y y1)(set_tile key_r (rtos r1 2 2))(set_tile key_x (rtos x1 2 2))(set_tile key_y (rtos y1 2 2))
)2.5 对话框加载图片
2.5.1 幻灯片图片制作
步骤 新建cad绘制想展示的图片命令行输入mslidemake slide的意思制作幻灯片保存即可 图示
2.5.1 代码部分 效果 temp.lsp (defun C:demo1 ()(setq dlg_id (load_dialogC:\\Users\\Administrator\\Desktop\\code\\temp.dcl))(if ( dlg_id 0) (exit))(if (not (new_dialog demo1_dcl dlg_id)) (exit));;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;只有此区间新增(start_image img_1)(slide_image 0 -20 (dimx_tile img_1)(dimy_tile img_1)C:\\Users\\Administrator\\Desktop\\code\\img_1.sld)(end_image);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;(action_tile accept (done_dialog 1))(action_tile cancel (done_dialog 0))(setq std (start_dialog))(unload_dialog dlg_id)(if ( std 1) (print 确认))(if ( std 0) (print 取消))(print)
)temp.dcl demo1_dcl:dialog{labelimage展示;:row{:column{:image{//先确定宽度调整高度时不要同时调宽度width30;//通过调整高度使图像显示在中间需要一点点试height10;// 使背景色同主窗口color-2;keyimg_1;}}}ok_cancel;
}返回目录