CAD- Manager. com » Blog Archive » Auto. Lisp Examples. Autolisp Basics. Autolisp is the grand daddy of Auto. CAD programming tools and you’d be amazed at the amount of Autolisp programming tools you can find on the Internet. Given a little knowledge you can integrate existing Autolisp routines into your own and gain tremendous power over your Auto. CAD based installation. The first thing to understand is that Autolisp has a couple of key files and a key function that perform startup operations for you. Robert has provided CAD management consulting, programming and training services for clients throughout the United States and Canada since 1991. Reach Robert at: [email protected]. CADTutor provides free video tutorials, articles, downloads and a busy community forum for users of AutoCAD and associated software. Forum: AutoLISP, Visual LISP & DCL. Questions from beginner to advanced. Tell us about good sources of free lisp and post your own routines for testing. Code posting guidelines. Dec 2013, Success of antech SHOPlink at MSS india, Nasik. June 16,2012 Grand opening of our CAD CAM training centre at Autocluster. April 10,2012 Admission notice - Read more. A collection of AutoLISP routines for AutoCAD. Here we have a vast collection of AutoCAD programs going all they way back to the early days of CAD software. Some real retro classics here. Please enjoy these free downloads. 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 Auto. CAD starts up. Any programming you place within this file will be automatically loaded every time Auto. CAD starts. The ACAD. LSP file is normally located in the SUPPORT subdirectory of the Auto. CAD installation. ACADDOC. LSP This file loads every time a new drawing session is started in Auto. CAD 2. 00. 0, 2. 00. 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 Auto. CAD 2. 00. 0 type products only the ACADDOC. LSP file will load with subsequent drawings. Since Auto. CAD R1. ACADDOC. LSP file with R1. Like the ACAD. LSP file, ACADDOC. LSP is normally located in the SUPPORT subdirectory of the Auto. CAD installation. S: :STARTUP function This function is typically within the ACADDOC. LSP file (or ACAD. LSP file for Auto. CAD R1. 4 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 Auto. CAD environment is initialized. Simple Examples. If you created an ACADDOC. LSP file in the SUPPORT subdirectory of your Auto. CAD installation and placed the following text in it what do you think would happen?(defun s: :startup ()(alert “Hello there!”)(princ))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 Auto. CAD 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 Auto. CAD. Do you understand the result you get? Let’s carry the example a bit further by trying this: (defun s: :startup ()(setvar “textsize” 0. This example sets the default text size and dimension text size to a value of 0. 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 Auto. CAD’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. 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. Note that the statement that sets the text size first gets the DIMSCALE value then multiplies it by 0. 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/Word. Pad 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 Auto. CAD 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 Auto. CAD’s vocabulary. By adding new commands, or C: functions, to Auto. CAD’s command set your users simply think they have a new Auto. CAD command they can use. Only you will know that they are actually using a custom Auto. CAD 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 6. A Real World Example. I love keyed in shortcuts 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 zeroinvoke the fillet command and let me select the objectsset 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. 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: Defines a command function called FZ using the DEFUN statement. Holds the default fillet radius value in a variable called OLD. Please note that Auto. CAD commands are encased in quotation marks and that PAUSE instructions do not. Sets the fillet radius back to its old value using the OLD. 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 Auto. CAD session and type the following at your command prompt: (load “fz. Once the file is loaded into Auto. CAD 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. S: :STARTUP function (mentioned earlier) and your new FZ function will load automatically upon starting Auto. CAD. 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 . The layer command is a prime example of this concept that you can verify simply by typing in . Now type in LAYER at the command line and you’ll get a very different result right? Since Auto. CAD commands pass through the Autolisp command interpreter with TYPED input you’ll need to always invoke the . Other commands I frequently use the “- ” prefix with are . 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 Auto. CAD 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 Auto. CAD 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 Auto. CAD 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. You should see the Autolisp interpreter asking for a ” mark.(defun c: fz ()(setq old. You should see the Autolisp interpreter asking for a closing parenthesis.(defun c: fz ()(setq old. 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 Auto. CAD 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 Auto. CAD database for certain entity types.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |