Autolisp在CAD二次开发中的应用毕业论文.doc

上传人:jian****018 文档编号:9697306 上传时间:2020-04-07 格式:DOC 页数:67 大小:1.53MB
返回 下载 相关 举报
Autolisp在CAD二次开发中的应用毕业论文.doc_第1页
第1页 / 共67页
Autolisp在CAD二次开发中的应用毕业论文.doc_第2页
第2页 / 共67页
Autolisp在CAD二次开发中的应用毕业论文.doc_第3页
第3页 / 共67页
点击查看更多>>
资源描述
本科毕业论文 设计 题目 应用 Auto lisp 在南方 CASS 中批量处理图形数据 学院 山西大同大学煤炭工程学院 班级 07 测绘一班 姓名 付智华 指导教师 徐广翔 职称 副教授 完成日期 2011 年 6 月 15 日 山西大同大学 2011 届本科毕业论文 设计 选题审批表 学院 煤炭工程学院 系别 采矿工程系 专业 专业方向 测绘工 程 学生姓名 付智华 学号 070809011103 指导教师 徐广翔 职称 副教授 所选题目名称 应用 AUTO LISP 在南方 CASS 中批量处理图形数据 选题性质 A 理论研究 B 应用研究 C 应用理论研究 D 产品设计 E 工程技术开发 F 软件开发与应用 G 其它 选题的目的和意义 研究本课题的目的是通过 AUTO LISP 语言的学习和对 CASS 的进一步开发应用 更进一步提高对 CASS 绘图功能和应用的认识与掌握 随着科学技术的不断发展和社会的不断进步 计算机也越来越普遍的在各个 行业中得到推广和应用 实践证明在工程地质中引入 CAD 技术是岩土工程勘查的 计算和绘图在质量和速度上都产生了一个质的飞跃 使勘察设计工作上上了一个大 台阶 但是目前许多勘察设计单位的设计人员大多只能利用 AUTO CAD 软件 一 笔一画地挥出所需的设计图纸 是工程勘察设计人员大大部分时间都花费在繁琐的 计算和绘图中 设计工作的重复性较大 工作效率较低 如果设计人员能够对 AUTO CAD 进行二次开发 通过对 AUTO LISP 进行编程 在 CASS 中加入一些用 户需要的功能 从而使 CASS 在绘图中更具有实用化 指导教师意见 签字 年 月 日 学院意见 签字 年 月 日 备注 山西大同大学 2011 届本科毕业论文 设计 开题报告 学院 煤炭工程学院 系别 采矿工程系 专业 测绘工程 设计 题目 应用 AUTO LISP 在南方 CASS 中批量处理图形数据 指导 教师 徐广翔 职称 副教授 学生 姓名 付智华 学号 070809011103 一 研究目的 选题的意义和预期应用价值 研究本课题的目的是通过 AUTO LISP 语言的学习和对 CASS 的进一步开发应用 更进一步提高对 CASS 绘图功能和应用的认识与掌握 随着科学技术的不断发展和社会的不断进步 计算机也越来越普遍的在各个 行业中得到推广和应用 实践证明在工程地质中引入 CAD 技术是岩土工程勘查的计 算和绘图在质量和速度上都产生了一个质的飞跃 使勘察设计工作上上了一个大台 阶 但是目前许多勘察设计单位的设计人员大多只能利用 AUTO CAD 软件 一笔一 画地挥出所需的设计图纸 是工程勘察设计人员大大部分时间都花费在繁琐的计算 和绘图中 设计工作的重复性较大 工作效率较低 如果设计人员能够对 AUTO CAD 进行二次开发 通过对 AUTO LISP 进行编程 在 CASS 中加入一些用户需要的 功能 从而使 CASS 在绘图中更具有实用化 本课题研究利用 AUTO LISP 的二次开发功能 有效地提高 CASS 的功能 从而 提高 CASS 在工程中批量处理图形数据的应用 二 与本课题相关的国内外研究现状 预计可能有所突破和创新的方面 文献综述 AutoCAD 作为计算机辅助绘图的系列软件 界面友好 功能强大 其应用领 域十分宽广 诸如在机械设计 电子设计 土木建筑 地图绘制 石油化学 工商 业方面等 是设计人员广泛使用的CAD 绘图软件 随着现代工业工程技术的发展 对计算机辅助设计的要求是越来越高 嵌在AutoCAD 内部的AUTO LISP 语言为用户 开发出适合于本行业的用户应用程序提供了可能性 以下是实际工作中的二次开发 研究 一 马鞍山市测绘院有限责任公司利用AUTO LISP编程实现坐标点高程值批量修改 在外业碎部测量中由于种种原因有时会出现高程点数据发生错误的情况 这些情 况的出现虽然可以去重新测量 但是花费了更多的时间和人力 CAD的出现不仅使测 量内业工作量大大减轻 也使得外业的有些错误可以借助CAD得以改正 高程点数据 及高程点注记可以利用CAD 的属性修改命令用手工一一修改 但是碎部测量中的点 是非常多的 因而这是一件让人头疼的费时费力的事情 利用AUTO CAD自带的AUTO LISP语言编程便可以轻松解决这个问题 程序设计思路简述如下 程序中首先获得需要修改高程值的所有坐标点数据以 组成选择集 然后逐一取出各个坐标点的Z 值加上对应的高程差值以修改其Z值 即高程值 然后更新所有坐标点在CAD 对象数据库中的数据 这便解决了批量修 改坐标点高程值的问题 由选择集中逐一取出已修改了高程值的各个坐标点 取其高 程值 在Gc层中成批生成各点对应的高程注记 从而解决了高程注记成批生成的问题 二 广州市市政工程维修处利用AUTO LISP在测量内业工作中的应用 1 AUTO LISP在数字化测图方面的应用 在数字化测图的内业成图阶段 需要绘制陡坎 斜坡 围墙 铁丝网等线状地 物 也需要绘制排水井 消防栓 路灯等独立地物 依据地形图图例 这些地物都 是用特殊的线形或符号来表示的 使用AUTO CAD的原有功能 要绘制表示这些地物 的线形或符号是既困难又繁琐的 针对这样的问题 就可以通过编制AUTO LISP程 序进行解决 使每一个程序对应一定的线形或符号 在使用时 将程序加载到AUTO CAD中 便可以像AUTO CAD 命令一样进行使用 2 AUTOLISP在测量工作量统计中的应用 工作量统计是一项繁琐的工作 尤其是在市政管线探测工作中 需要统计各种管 线的长度作为测量工作收费的依据 过去这项工作基本上都是采用在打印好的图纸上 逐段量出长度 再求和的方法来进行 这种方法不仅效率低下 准确性也很难保证 三 山东科技大学测绘学院利用LISP语言实现等高线修改 地形等高线在地学研究中有重要意义 地形图上等高线的修改是地理系统中的一 个重要课题 引入LISP 语言 通过编写程序对获取的地形等高线进行批量赋值 最终 较好地解决了等高线提取中的间断 交叉和粘连问题 等高线的修改是利用AUTOCAD 的LISP 语言二次开发出的软件 该软件可以辨别 条件提取地形等高线 还可以方便地对提取结果进行修改 以纠正自动提取结果的 错误 1 三 分析研究的可能性 基本条件及能否取得实质性进展 方案论证 基于Auto CAD CASS 处理测绘图形的技巧和方法可归纳如下 1 数据 图形 的自动转换 1 1 间接转换 1 采用高级语言 Basic语言或C语言 编制程序调用原始数据文件生成SCR命令 文件 在Auto CAD的图形编辑环境下调用SCRIPT命令执行该文件 生成相应的图形 2 用高级语言生成DXF文件 在Auto CAD图形编辑环境下调用DXFIN命令打开文 件 即可得到相应的图形文件 3 用高级语言直接生成DWG图形文件 1 2 直接转换 利用 Auto LISP语言 编写相应程序 读取有关数据文件 进行处理 并调 Auto CAD绘图命令 直接生成图形 这种方法直接在Auto CAD下工作 不仅减少中 间环节 提高效率 且具有较强的通用性 对一些较复杂的图形 更直接方便 2 图形 数据 的自动转换 2 1 图纸资料数字化 用手扶式数字化仪 可以编制相应的LISP程序 完成图形的数字化 程序运行 时 将从数字化仪传递来的数据信息 点的坐标 连同交互式状态下输人的有关编码 合并以合理的数据结构存贮于数据文件中 同时 在屏幕上 采用不同的图层和颜 色进行同步显示 从而使数字化过程变得直观 形象 避免产生丢点或重复等各种 错误的发生 2 2 自动更新变更后的图形 在 Auto LISP语言中 有很多实体访问函数 实体名称函数 实体数据函数 运用上述函数编制一个LISP程序就可实现图形文件到数据文件的自动转换 具体过 程如下 用ssget函数构造一个选择集 在利用sslength函数求出选择集实体的个数 然后 sname函数依次求出每个实体的名称 通过entget函数就可获得实体的下列信 息 实体类型 所在层名和实体颜色号 一般图形的编码就隐含在图层和颜色中 如果原图形中某一范围需要修改 就可利用Auto CAD编辑命令完成 甚至将原图中 元素删除掉 重新绘制 修改完成后 运行上述LISP程序 给出变更范围 计算机 立即生成一个新的数据文件 重新纳人管理系统中去 从而保证图形与数据的统一 3 图形的批量编辑 在测量图形处理中 经常会遇到需要批量处理某类图素的情况 如地形图中些 专用符号及注记字符大小需要统一放大或缩小 图中的植被符号需要统一调整密度等 如果采用手工逐一编辑 工作量大 效率很低 则可以编制一段相应的LISP程序来 自动完成 具体作法是 首先是Auto CAD下构造一选择集 集内包含所有需要修改 的实体 然后逐一求出各个实体的名称 并对该实体有关数据做相应修改 4 开发新功能函数 Auto CAD虽然提供丰富的绘图和编辑命令 但有些测量方面常用的功能并不具 备 可利用LISP语言对Auto CAD作二次开发 开发出适应测量专业特点的新功能函 数 例如在地形测量中 加固陡坎 未加固陡坎 铁路 电力线路 围墙 界址线 等地貌符号和图式符号的绘制 Auto CAD没有提供相应的绘图命令 为此 可以编 制相应的LISP程序来自动处理完成 5 纠错技巧 在地形图测量中 会遇到这样的情况 图形已经测绘完毕 却发现坐标系统用 错 需要图形坐标还原 方位旋转或需要换带处理 怎么办 Auto CAD可化险为夷 具体办法是 对于坐标系统用错 在测图区域内找相距较远的2个已知点 计算确定 对的和错的两组坐标 分别计算两点之间边的方位 确定出需要扭转的角度 如果 是数字化地形图 直接在Auto CAD环境下调出所有图幅 关闭纯地形图以外的图层 利用MOVE命令移动整块图形 移动基点选取上述已知点中错误的一个 再利用 ROTATE命令旋转整块图形 旋转基点选择已知点中正确的一个 2 四 课题研究的主要方法 策略和步骤 1 程序设计的指导原则 1 采用模块化和参数化的设计方式 2 充分利用AUTO CAD的菜单工具条及对话框等交互界面设计工具 提供良好的 用户界面对所有的参数输入都采用下拉菜单和对话框的模式 3 容错处理功能 2 程序设计的技术和方法 2 1 AUTO LISP语言 LISP 语言是最早引入进行AUTO CAD二次开发的语言 是一种嵌入AUTO CAD内部的 LISP 编程语言 具有人工智能性 是LISP语言和AUTO CAD有机结合的产物 是一种适 合于进行CA D 项目开发的非结构化设计语言 是开发AUTO CAD图形软件的强有力工 具 实现参数化绘图程序设计是AUTO LISP的一个重要应用 2 2 程序设计方法 首先利用dcl程序编写一个对话框 在AUTO CAD下加载运行 然后利用AUTO LISP 语言将所需要的功能与dcl程序桥接起来 写成完整的lisp程序 最后制作成下拉菜 单 实现程序的自动加载 五 研究进度安排 第一阶段 1 2周 查阅相关文献和资料 制定合理的整体方案和计划 完成 开题报告 第二阶段 3 5周 学习并掌握各种开发语言与相关软件应用 如AUTO LISP 语言 DCL语言 CAD的学习 第三阶段 6 10周 利用LISP语言编程设计 用于在南方CASS中批量处理图 形数据 第四阶段 11 12周 写毕业论文和准备毕业论文答辩 六 指导教师意见 指导教师签字 2011 年 4 月 15 日 七 教学系意见 系主任签字 2011 年 4 月 15 日 八 学院意见 院长签字 2011 年 4 月 15 日 AutoLisp Examples Auto lisp Basics Auto lisp is the grand daddy of Auto CAD programming tools and you d be amazed at the amount of Auto lisp programming tools you can find on the Internet Given a little knowledge you can integrate existing Auto lisp routines into your own and gain tremendous power over your AutoCAD based installation The first thing to understand is that Auto lisp has a couple of key files and a key function that perform startup operations for you The key files are called ACAD LSP and ACADDOC LSP and the key function is called S STARTUP and their operations are as summarized here ACAD LSP This file loads when AutoCAD starts up Any programming you place within this file will be automatically loaded every time AutoCAD starts The ACAD LSP file is normally located in the SUPPORT subdirectory of the AutoCAD installation ACADDOC LSP This file loads every time a new drawing session is started in AutoCAD 2000 2000i or 2002 based products Therefore any programming you place in this file will be loaded automatically every time a drawing is opened or started Note that while the ACAD LSP file would load in the FIRST drawing of the AutoCAD 2000 type products only the ACADDOC LSP file will load with subsequent drawings Since AutoCAD R14 doesn t support multiple drawing sessions you won t have to worry about the ACADDOC LSP file with R14 Like the ACAD LSP file ACADDOC LSP is normally located in the SUPPORT subdirectory of the AutoCAD installation S STARTUP function This function is typically within the ACADDOC LSP file or ACAD LSP file for AutoCAD R14 installations and its sole job is to execute customized commands you need to initialize your new drawing environment This function is the perfect place to set system variables like DIMSCALE VIEWRES parameters current layers etc The most powerful aspect of the S STARTUP function is that it invokes automatically and it lets you control exactly how the AutoCAD environment is initialized Simple Examples If you created an ACADDOC LSP file in the SUPPORT subdirectory of your AutoCAD installation and placed the following text in it what do you think would happen Well the DEFUN statement simply DEfines a FUNction see where the DEFUN comes from called S STARTUP which we already know will run every time AutoCAD starts opens a drawing The contents of the function are simply an ALERT box notification which will say Hello there followed by a PRINC statement which is traditionally the last line of a function Save your new ACADDOC LSP file checking the syntax carefully to be sure that it s right and startup AutoCAD Do you understand the result you get Let s carry the example a bit further by trying this defun s startup setvar textsize 0 125 setvar dimtxt 0 125 princ This example sets the default text size and dimension text size to a value of 0 125 or 1 8 if you prefer every time a drawing opens or starts The reason I used the decimal value is that your drawing may not always be in the architectural or fractional coordinate system and thus the decimal value is the most generic way to input a value This example shows how the SETVAR statement can be used to set AutoCAD s system variables and also shows how to set values using a generic coordinate system Let s continue the example to a logical conclusion by saying that the TEXTSIZE value really should be 0 125 times the value of the DIMSCALE that is already set in the drawing To complete this task we ll need a new command called GETVAR that allows us to get variables rather than set them and a multiplication function the normal operator within a single statement Using a bit of imagination yields the following program defun s startup setvar textsize 0 125 getvar dimscale setvar dimtxt 0 125 princ Note that the statement that sets the text size first gets the DIMSCALE value then multiplies it by 0 125 and only then sets the TEXTSIZE value The order of the operations occurs from the inner most set of parenthesis out Please also note there are three sets of parenthesis and that they always balance LSP files and functions As you begin to write your own programs it becomes logical to keep your program code stored in files that can be edited individually These files always have the LSP file suffix and are typically edited in a Notepad WordPad session or in the Visual Lisp editor which we ll talk about more in an upcoming issue The location of the LSP files can be in any directory you want but the easiest way to assure the files will be located is to place them in the SUPPORT folder of your AutoCAD installation Within the LSP files you create you may store functions which are simply programming routines that you can run over and over A specific type of function the C function allows you to actually add commands to AutoCAD s vocabulary By adding new commands or C functions to AutoCAD s command set your users simply think they have a new AutoCAD command they can use Only you will know that they are actually using a custom AutoCAD function As you create your custom functions and save them as LSP files you ll need to load in the files to be sure that the functions work Once debugged the functions can be loaded from the ACAD LSP file we talked about in Newsletter 61 A Real World Example I love keyed in short cuts for commands like L for line or E for erase Some while back I wanted to create a command called FZ that would always give me a zero radius fillet command for creating sharp corners yet would still leave the default F fillet command at whatever value I last set it at Therefore the program I would write would have to do the following things remember the old fillet radius set in the FILLETRAD system variable set the new fillet radius to zero invoke the fillet command and let me select the objects set the fillet radius back to it s prior setting The way I programmed this function looks like this defun c fz line 1 setq old radius getvar filletrad line 2 setvar filletrad 0 line 3 command fillet pause pause line 4 setvar filletrad old radius line 5 line 6 Example Explained In the above example I ve added comments at the end of each line to assign line numbers You ll note that each comment is preceded by a semi colon character which means that the Autolisp interpreter will ignore everything after the semicolon This method of commenting the program function allows you to store programming notes Now I ll summarize what each line of the program is doing 1 Defines a command function called FZ using the DEFUN statement 2 Holds the default fillet radius value in a variable called OLD RADIUS using the SETQ and GETVAR statements 3 Sets the fillet radius in the AutoCAD session to 0 using the SETVAR statement 4 Invokes the FILLET command and has PAUSE statements to wait for input from the user in the form of selecting two lines Please note that AutoCAD commands are encased in quotation marks and that PAUSE instructions do not 5 Sets the fillet radius back to its old value using the OLD RADIUS value using the SETVAR statement 6 A final parenthesis closes out the DEFUN statement begun in line 1 Let s Test It Now you can create a file called FZ LSP that contains the programming code from above and save it into AutoCAD s support directory Be very sure you ve typed everything correctly before saving the file or get the code from my web site which I mention at the end of the newsletter Now start your AutoCAD session and type the following at your command prompt load fz lsp Once the file is loaded into AutoCAD you should receive confirmation at the command line that will say C FZ which is the name of the function You may now test the function by typing in FZ at the command line Before you try the new FZ command though use the standard fillet command and set the radius to some non zero value and fillet a couple of lines to be sure the command has been set properly Now you should be able to fillet with normal radius values by using the normal fillet command but using FZ will always invoke a zero radius fillet That wasn t so hard was it If you d like you can now add the LOAD instruction line of load fz lsp in your S STARTUP function mentioned earlier and your new FZ function will load automatically upon starting AutoCAD By loading the function from S STARTUP you ll take care of your users without them even knowing where the new FZ command came from The Command Set Some AutoCAD commands will require an addition of a leading character to invoke them from Autolisp commands because the command is normally manipulated via a dialog box The layer command is a prime example of this concept that you can verify simply by typing in LAYER at the command line Now type in LAYER at the command line and you ll get a very different result right Since AutoCAD commands pass through the Autolisp command interpreter with TYPED input you ll need to always invoke the command in Autolisp code like this command layer instead of command layer If you don t believe me try it at the AutoCAD command line and see how it works Other commands I frequently use the prefix with are STYLE for text style manipulation and PLOT for issuing plot commands via Autolisp You ll want to examine these commands simply by keying them in at the command line then making some notes about the prompts you can enter into the command line In almost all cases with Autolisp commands you ll need to know how the AutoCAD commands operate and understand the sequence of how to input parameters into the command to write successful functions If you already type in commands in AutoCAD you should be all set if not you ve got some exploring to do A nice way to document the various keyed in information you use in AutoCAD is to simply copy the text out of the text history window which you access using the F2 key Then simply use the COPY function to copy the history text into your Notepad programming session Errors When you inadvertently forget parenthesis quote marks or some other key piece of code in your LSP file you will experience a variety of problems To see these problems demonstrated try loading in the following programming examples and see what happens defun c fz setq old radius getvar filletrad setvar filletrad 0 command fillet pause pause setvar filletrad old radius The error here is a missing after the word FILLETRAD in the second line You should see the Autolisp interpreter asking for a mark defun c fz setq old radius getvar filletrad setvar filletrad 0 command fillet pause pause setvar filletrad old radius The error here is a missing at the end of the program to close the DEFUN statement You should see the Autolisp interpreter asking for a closing parenthesis defun c fz setq old radius getvar filletrad setvar filletrad 0 command filllet pause pause setvar filletrad old radius The error here is an extra L in the word FILLLET You ll notice that the function will actually run but will halt when the fillet command should run Input and Selection Sets In the first two installments of our programming series I covered how to store variables manipulate system variables and use the COMMAND statement to pass instructions to the AutoCAD editor While these skills are key to writing basic programs you ll find that to write truly flexible programs you ll need to be able to Prompt your users for input values numbers text points Prompt your users for sets of data using selection set identification Filter the AutoCAD database for certain entity types Work with entity points line endpoints circle centers etc The commands we ll be utilizing to achieve these goals are as follows GETREAL to GET a user defined REAL number GETINT to GET a user defined INTeger number GETSTRING to GET a user defined STRING of text GETPOINT to GET a user defined POINT SSGET to GET a user defined Selection Set SSGET with the X option to filter the database for objects CAR CADR and CADDR to break points into X Y and Z components As in past installments I ll use short pieces of programming code to illustrate the concepts and ramp up the level of complexity gradually until you can understand even complex examples Getting Values from the User Getting user supplied values is straightforward in Autolisp as can be seen with these statements setq var1 getreal nPlease input a REAL number setq var2 getint nPlease input an INTEGER number setq var3 getstring nPlease input a piece of text Try pasting these examples into your AutoCAD command line to run the statements interactively and you ll see immediately what s happening The interesting thing to note is that when using the GETINT statement that you can t input a real number or a piece of text You ll also notice that a prompt is generated by the command so the user knows what information to input Note The n character is simply a line feed that assures you that the prompt to the user will be placed on a new command prompt line in the AutoCAD session The result of these statements will be a stored variable VAR1 VAR2 or VAR3 that can be used in other programs Here s a simple example of a program you can run interactively that prompts the user then makes use of the stored variable setq dimtxt height getreal nDimension text height setvar dimtxt dimtxt height While this is a very simple example it illustrates the concept perfectly Just acquire a value from the user then use the variable name in other commands instead of fixed values See examples from the previous newsletter issues if you have any questions on the SETVAR statement Getting and Working with Points While getting a point from the AutoCAD user is very simple using this form setq point1 getreal nPlease select a POINT location Working with the points isn t easy because the point is actually three pieces of data that must be picked apart Point data is really a list of X Y and Z coordinates lumped together which can be decomposed using CAR CADR and CADDR functions as follows setq point1 x car point1 setq point1 y cadr point1 setq point1 z caddr point1 Note that an intermediate variable called POINT1 stored the point while variables POINT1 X POINT1 Y and POINT1 Z contact the actual values for the x y and z coordinates respectively This CAR CADR CADDR approach requires equal components of memorization and getting used to but you will find that you ll grow accustomed to its usage faster than you think Working with Sets Yet another component of AutoCAD programming is that AutoCAD tends to operate on sets AutoCAD calls them selection sets of objects AutoCAD users provide selection sets in commands like MOVE COPY ROTATE ERASE etc The rule of thumb is that if a command ever asks you to SELECT OBJECTS that command is making use of a selection set To make your programs acquire selection sets you ll need to use the SSGET command The most basic form of the command works like this setq set1 ssget or alternately setq set2 ssget nPlease select objects for your set the only difference being a user prompt in the second example The resulting set will be stored in a variable SET1 or SET2 in the above examples that you can manipulate with a COMMAND style instruction A simple program illustrates the trick setq erase
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑环境 > 建筑工程


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!