




已阅读5页,还剩64页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
本科毕业论文本科毕业论文 设计设计 应用 Auto lisp 在南方 CASS 中批量处理图形数据 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 set ssget nPlease select objects to erase command erase erase set This example illustrates how a selection can be obtained stored and processed using only two lines of code Note The final is simply an extra ENTER which you d ordinarily have to hit manually to complete the erase command in AutoCAD More Sets Lets say that you wanted to author a program that would erase all text in a drawing automatically You will need to use the SSGET command but not for user input rather you ll need to filter the AutoCAD drawing for TEXT objects The example code here looks pretty nasty but you ll have to trust me when I tell you there isn t a better way in standard Autolisp setq text set ssget x list cons 0 TEXT Where the x parameter denotes the filter The 0 parameter is the entity type flag The TEXT parameter is the entity type you re selecting Another example where you would select only text that is on the layer called ANNOTATIONS would look like this setq text set ssget x list cons 0 TEXT cons 8 ANNOTATIONS I ll admit that this syntax isn t very user friendly but you will get used to it Now simply combine one of the above statements with an ERASE command and you have a program that deletes a give entity type from the drawing automatically setq text set ssget x list cons 0 TEXT command erase text set To be really thorough you may also want to trap MTEXT objects as well as TEXT objects by simply adding another SSGET function and modifying the ERASE function call like this setq text set ssget x list cons 0 TEXT setq mtext set ssget x list cons 0 MTEXT command erase text set mtext set As you can see you ve gained a lot of power in this example using only a few lines of code For more information on how to filter for more complex sets of objects consult the Developer s Help section of AutoCAD s electronic help files and search on the SSGET Autolisp function you ll find syntax examples a plenty there AutoAuto LISPLISP 的例子的例子 AutoAuto lisplisp 语言的基础知识语言的基础知识 Auto LISP 语言是 Auto CAD 编程工具中最大的一种工具 基于 Auto LISP 的编程 工具量之大会让人感到惊讶 将一些小知识嵌套于 AUTO LISP 内部 使 LISP 语 言和 AUTO CAD 有机结合 会有效地提高 AutoCAD 的功能 首先要明白的是 对于 Auto lisp 的启动操作有几个主要文件和一个主要功能 主要文件被称为 ACAD LSP 和 主要功能称为 S STARTUP 下面是对他们基本 功能的总结 ACAD LSP 此文件 AutoCAD 的启动时加载 添加到这个文件的任何程序将会在每 次 AutoCAD 开启时自动加载 而 ACAD LSP 文件通常是在 AutoCAD 的安装的 SUPPORT 目录下安装的 ACADDOC LSP 这个文件是在每一次载入新的绘图产品是加载的 是基于 AutoCAD 2000 2000i 或 2002 因此 添加到这个文件中的任何程序会在每次打开或启 动一个绘图的时自动加载 需要注意的事 只有在 ACADDOC LSP 文件加载了随后 的图纸 ACAD LSP 文件才能够载 AutoCAD2000 下的第一幅图形产品 AutoCAD R14 的不支持多图形会话 而对于 R14 的 ACADDOC LSP 文件你将不必担心这一点 正如 ACAD LSP 文件 ACADDOC LSP 通常是在 AutoCAD 的安装支持子目录上加载的 S STARTUP 的功能 此功能的实现通常是在 ACADDOC LSP 文件 或者是用于 Auto CAD R14 安装的 ACAD LSP 文件 其唯一的工作就是执行你需要初始化的 新的绘图环境下的定制命令 这个函数是设置像 DIMSCALE VIEWRES parameters 当前图层等系统变量的一个完美的地方 它的最完美的启动功能就 是 它会自动调用 并且可以人为控制 AutoCAD 环境究竟如何被初始化 简单的例子简单的例子 如果你在 AutoCAD
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 语音识别试题及答案
- 阿里定级面试题及答案
- 房地产销售策略与实战
- 2025年 道真自治县“特岗计划”教师招聘考试笔试试卷附答案
- 员工安全培训手册
- 2025年中国喷气背包行业市场全景分析及前景机遇研判报告
- 2025年中国内衣裤洗衣机行业市场全景分析及前景机遇研判报告
- 急救培训圆满毕业
- 住院患者护理风险评估制度
- 肿瘤晚期患者教育
- 燕秀工具箱模具设计快捷键一览表
- 物业承接查验标准及表格
- 灯箱广告投标方案(完整技术标)
- dzl213型锅炉低硫烟煤烟气袋式除尘湿式脱硫系统设计
- SOP标准作业指导书excel模板
- 《公路桥涵养护规范》(5120-2021)【可编辑】
- 新人教版一年级数学下册期末考试卷(附答案)
- 人教版三年级语文上册期末试卷及答案【完整】
- ptfe膜雨棚施工方案
- 人工智能伦理规则
- 米亚罗-孟屯河谷风景名胜区旅游基础设施建设项目环评报告
评论
0/150
提交评论