《论文(设计)运用DCL 语言开发基于AutoCAD 的粗糙度绘制器.doc》由会员分享,可在线阅读,更多相关《论文(设计)运用DCL 语言开发基于AutoCAD 的粗糙度绘制器.doc(7页珍藏版)》请在三一办公上搜索。
1、运用DCL语言开发基于AutoCAD的粗糙度绘制器黄立靖(福建林业职业技术学院信息工程系,南平 353000)摘要:利用AutoCAD内嵌的对话框控制语言DCL开发图形模式的对话框输入界面。简要介绍了DCL语言的特点、运行方式。以粗造度绘制器的开发为例,详细分析了DCL语言的开发过程。关键词:对话框控制语言;AutoCAD;粗糙度;可编程对话框 中图文类号:TP39计算机辅助设计软件AutoCAD,以其功能强大,使用方便,易于开发,而深受世界各国用户的青睐。但在零件图中标注表面粗糙度方面,却存在不尽人意之处。近几年,国内许多用户采用AutoLISP语言来开发粗糙度符号的各种标注方法,虽然解决了
2、粗糙度标注不便问题,但是单纯的AutoLISP程序只能在命令行根据系统的提示输入数据与系统交流,这种交流模式效率不高,生硬死板。如果使用对话框来标注粗糙度符号,用户就可以方便而直观地与AutoCAD实现数据交流。鉴于此,笔者用对话框控制语言(Dialog Control Language,简称DCL)来开发AutoCAD欠缺的粗糙度绘制器,这样比单纯采用AutoLISP语言进行开发更加灵活、交流效率更高。1、 DCL语言的特点与运行DCL语言结合了AutoLISP与DCL两种语法的功能,可以让用户半自动地架构出“图形模式”的对话框界面,即可编程对话框PDB,一个DCL文件的基本架构外观是:对话
3、框名称:dialoglabel:“对话框标题”; :框栏形式 label:“框栏标题”; (各种对话框基本控件的排行组合) /框栏定义至此结束 /对话框定义至此结束1DCL对话框的屏幕画面以框栏(Tile)为基本结构,将框栏按左右、上下或混合排行之后,就组成了对话框的主要外观。每个框栏内部可以容纳对话框的基本控件。DCL语法可以自动调整控件之间的相对位置,用户只需要将控件代码和各控件的排行模式代码按顺序写在DCL文件里即可,一般不用考虑控件的尺寸问题。系统会自动计算应有的对话框尺寸,并自动规划适当的空间来放置这些控件。DCL文件与AutoLISP程序一样,是单纯的ASCII格式的文本文件,可使
4、用VLISP或一般的文本编辑器(如:记事本等)来编辑和修改,用DCL语法撰写的对话框,其扩展名为.dcl。对话框程序的运行,按先后顺序可分为3步骤:第1步:在AutoLISP文件里调用DCL对话框程序。第2步:用户在对话框里输入数据。第3步:将用户输入的数据返回AutoLISP文件执行。1DCL文件本身并不能单独运作,必须在AutoLISP主程序里进行初始设定,然后由主程序调用DCL文件,才能显示在AutoCAD的作图屏幕上。用户输入数据后,单击程序设置的按钮,DCL文件再将取得的键值数据送回AutoLISP主程序执行,关闭对话框后,AutoLISP主程序还将继续执行后续的代码。2、 粗糙度绘
5、制器的开发在制造业中,进行零件设计时必须在零件图上标注各表面的表面粗糙度符号及其高度参数值,机械零件表面获得的方法一般可分为三种:去除表面材料的方法,指采用某一特定的机加工方法切除毛坯表面;用任何方法获得的表面,指对加工方法不作严格要求而得到的表面;不去除表面材料的方法,指对毛坯表面不作切除加工。对零件的每一表面而言,其粗糙度的标注只能有一种。因此,用DCL语言开发粗糙度绘制器,可用单选按钮来设计,用户可以方便地通过对话框标注出任一种粗糙度符号,粗糙度绘制器的DCL程序代码如下。c_ccd:dialoglabel = “粗糙度符号绘制器”;: textlabel = “选择标注类型,然后单击确
6、定”;: boxed_column: radio_buttonlabel = “去除表面材料的方法”;key = “g1”;value = 0;fixed_width = true;width = 5;alignment = centered;: radio_buttonlabel = “用任何方法获得的表面”; key = “g2”;value = 0; fixed_width = true; width = 5; 图1 粗糙度绘制器界面alignment = centered;: radio_buttonlabel = “不去除表面材料的方法”;key = “g3”;value = 1;f
7、ixed_width = true;width = 5;alignment = centered;ok_cancel;程序运行结果如图1。程序中三个单选按钮都有key(关键字)和value(值)这两个重要属性。关键字是应用程序用来引用控件的名字,其取值就对话框而言必须是唯一的。value属性规定了控件的初值,取0表示预设未被选中,取1表示预设被选中。程序编制完毕,将其保存为c_ccd.dcl的文件。调用粗糙度绘制器对话框的AutoLISP程序,应该包括处理用户选择动作的程序和根据不同取值调用不同粗糙度的子程序,具体编写如下。主程序代码2(defun c:load_ccd (/ dcl_id j
8、) (setq dcl_id (load_dialog “c_ccd .dcl”) (if (not (new_dialog “c_ccd” dcl_id)(exit) ) (action_tile “g1” “(setq ccd_type 1)”) ; 给变量ccd_type赋不同的数值 (action_tile “g2” “(setq ccd_type 2)”) (action_tile “g3” “(setq ccd_type 3)”) (start_dialog) (unload_dialog dcl_id) (princ) (cond ;利用条件函数调用不同绘制粗糙度的子程序(= c
9、cd_type 1) (draw 1)(= ccd_type 2) (draw 2)(= ccd_type 3) (draw 3) ) (command “text” ;书写粗糙度值,点pt3和变量f1、f2另外求取(list (+ (car pt3) 1.0) (+ (cadr pt3) 0.7 ) “ ” “ ” f1 “ ”) (command “text” (list (+ (car pt3) 1.0) (+ (cadr pt3) 3.8 ))“ ” “ ” f2 “ ”)主程序中,load_dialog函数可装入.dcl文件;new_dialog函数用来显示已装入的对话框序列值dcl
10、_id对应的DCL文件中的对话框c_ccd;start_dialog函数激活已显示的对话框,并把控制权交给对话框;unload_dialog函数卸载对话框,使DCL文件从内存中消除。action_tile函数是处理用户的动作的:当用户选择DCL对话框中的不同单选按钮时,就给变量ccd_type赋不同的数值1,2,3,然后根据变量ccd_type的不同取值,用条件函数cond调用不同的绘制粗糙度的子程序。绘制三种粗糙度符号的子程序代码如下。(defun draw1 ( ) ;第一种符号程序,各点位置及符号如图2(setq cp (getpoint “n 指定粗糙度符号的位置:”) (setq p
11、t1 (list (car cp) (- (cadr cp) 5)(setq pt2 (polar pt1 (/ pi 3) 17)(setq pt3 (polar pt1 (/ (* 2 pi) 3) 8)(setq pt4 (polar pt1 (/ pi 3) 8)(setq f1 (getstring “n指定粗糙度值或最大粗糙度值:”)(setq f2 (getstring “n指定最小粗糙度值:”)(command “line” pt4 pt3 pt1 pt2 “”)(defun draw2 ( ) ;第二种符号程序,各点位置同前,如图3(setq cp (getpoint “n
12、指定粗糙度符号的位置:”) (setq pt1 (list (car cp) (- (cadr cp) 5)(setq pt2 (polar pt1 (/ pi 3) 17)(setq pt3 (polar pt1 (/ (* 2 pi) 3) 8)(setq pt4 (polar pt1 (/ pi 3) 8)(setq f1 (getstring “n指定粗糙度值或最大粗糙度值:”)(setq f2 (getstring “n指定最小粗糙度值:”)(command “line” pt3 pt1 pt2 “”)(defun draw3 ( ) ;第三种符号程序,各点位置同前,如图4(setq
13、 cp (getpoint “n 指定粗糙度符号的位置:”) (setq pt1 (list (car cp) (- (cadr cp) 5)(setq pt2 (polar pt1 (/ pi 3) 17)(setq pt3 (polar pt1 (/ (* 2 pi) 3) 8)(setq pt4 (polar pt1 (/ pi 3) 8)(setq f1 (getstring “n指定粗糙度值或最大粗糙度值:”)(setq f2 (getstring “n指定最小粗糙度值:”)(command “line” pt3 pt1 pt2 “”)(command “circle” cp “D”
14、 5)图2 各点位置及第一种符号 图3 第二种符号 图4 第三种符号以上三个子程序中,采用两个交互性输入数据函数:getpoint和getstring 。getpoint函数提示用户输入粗糙度符号的位置,可以采用AutoCAD任何一种点的输入方式。getstring函数提示用户输入字符串,并返回该字符串,用于输入粗糙度数值。程序编写完成后,将主程序和三个子程序保存为load_ccd.lsp的文件。确保将c_ccd.dcl和load_ccd.lsp两个文件保存在AutoCAD安装目录下的support文件夹中,用(load “load_ccd”)装载load_ccd.lsp程序,还可将自定义函数
15、load_ccd写入AutoCAD中的Acad.lsp的文件中,以后直接调用load_ccd函数就如同执行AutoCAD原有的命令,即可调出粗糙度绘制器对话框,用户就可方便地在零件图中进行粗糙度的标注。3、 结束语将对话框控制语言DCL与AutoLISP的可编程对话框函数2相结合,用户可设计出形式多样,包罗万象的对话框应用程序。各专业的技术人员结合本专业或本单位的实际情况进行可编程对话框的设计,一定能大大提高绘图的速度和质量,DCL语言确实是二次开发AutoCAD的有效工具。参考文献1舒飞.AutoCAD2004二次开发标准教程M.上海:上海科学普及出版社,2004.2杨素敏.AutoCAD2
16、000定制与开发M.北京:人民邮电出版社,2000.Development Of Rough Draw IN AutoCAD By Using Dialog Control LanguageHUANG Li-jing(Fu Jian Forestry Vocational & Technical College , Nanping 353000 China )Abstract The dialogue boxes for graphical user interface can be developed by using Dialog Control Language in AutoCAD.T
17、he DCL is introduced in brief about feature and method of running. The development process of DCL is analysed in particular by using the example of development of rough draw.Key Words Dialog Control Language; AutoCAD; Rough ; Programmable Dialogue Boxes;作者简介黄立靖,男,1965年10出生,汉族,籍贯:福州,高级讲师,大学本科学历,工学学士。
18、在福建林业职业技术学院信息工程系从事计算机科学与技术的教学工作,主要研究方向为计算机可视化编程、图形图像的制作与处理。联系电话:13859488170(手机);05998689591、6166358。联系地址:福建省南平市金山路140号福建林业职业技术学院信息工程系。E-mail: fjnphlj或fjhclhlj邮编:353000。Editors note: Judson Jones is a meteorologist, journalist and photographer. He has freelanced with CNN for four years, covering seve
19、re weather from tornadoes to typhoons. Follow him on Twitter: jnjonesjr (CNN) - I will always wonder what it was like to huddle around a shortwave radio and through the crackling static from space hear the faint beeps of the worlds first satellite - Sputnik. I also missed watching Neil Armstrong ste
20、p foot on the moon and the first space shuttle take off for the stars. Those events were way before my time.As a kid, I was fascinated with what goes on in the sky, and when NASA pulled the plug on the shuttle program I was heartbroken. Yet the privatized space race has renewed my childhood dreams t
21、o reach for the stars.As a meteorologist, Ive still seen many important weather and space events, but right now, if you were sitting next to me, youd hear my foot tapping rapidly under my desk. Im anxious for the next one: a space capsule hanging from a crane in the New Mexico desert.Its like the se
22、t for a George Lucas movie floating to the edge of space.You and I will have the chance to watch a man take a leap into an unimaginable free fall from the edge of space - live.The (lack of) air up there Watch man jump from 96,000 feet Tuesday, I sat at work glued to the live stream of the Red Bull S
23、tratos Mission. I watched the balloons positioned at different altitudes in the sky to test the winds, knowing that if they would just line up in a vertical straight line we would be go for launch.I feel this mission was created for me because I am also a journalist and a photographer, but above all
24、 I live for taking a leap of faith - the feeling of pushing the envelope into uncharted territory.The guy who is going to do this, Felix Baumgartner, must have that same feeling, at a level I will never reach. However, it did not stop me from feeling his pain when a gust of swirling wind kicked up a
25、nd twisted the partially filled balloon that would take him to the upper end of our atmosphere. As soon as the 40-acre balloon, with skin no thicker than a dry cleaning bag, scraped the ground I knew it was over.How claustrophobia almost grounded supersonic skydiverWith each twist, you could see the
26、 wrinkles of disappointment on the face of the current record holder and capcom (capsule communications), Col. Joe Kittinger. He hung his head low in mission control as he told Baumgartner the disappointing news: Mission aborted.The supersonic descent could happen as early as Sunday.The weather play
27、s an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-
28、day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause), he can expect a
29、lot of turbulence.The balloon will slowly drift to the edge of space at 120,000 feet (22.7 miles/36.53 kilometers). Here, Fearless Felix will unclip. He will roll back the door.Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes
30、 the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end.Skydiver preps for the big jumpWhen he jumps, he is ex
31、pected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely.If he goes too fast or spins out of control, he has a s
32、tabilization parachute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will have to slow to 172 mph (27
33、7 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 f
34、eet (7,620 meters).It might not be the moon, but Kittinger free fell from 102,800 feet in 1960 - at the dawn of an infamous space race that captured the hearts of many. Baumgartner will attempt to break that record, a feat that boggles the mind. This is one of those monumental moments I will always remember, because there is no way Id miss this.