【正文】
ty type from the drawing automatically:(setq text_set (ssget “x” (list (cons 0 “TEXT”))))(mand “.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”))))(mand “.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 plex 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.Auto LISP 的例子 Auto lisp 語(yǔ)言的基礎(chǔ)知識(shí) Auto LISP 語(yǔ)言是 Auto CAD 編程工具中最大的一種工具,基于 Auto LISP 的編程工具量之大會(huì)讓人感到驚訝。 line 4(setvar “filletrad” old_radius) 。 line 2(setvar “filletrad” 0) 。本科畢業(yè)論文 (設(shè)計(jì) )應(yīng)用 Auto lisp 在南方 CASS 中批量處理圖形數(shù)據(jù)AutoLisp ExamplesAuto lisp BasicsAuto 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 Inter. 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 and and the key function is called S::STARTUP and their operations are as summarized here: – This file loads when AutoCAD starts up. Any programming you place within this file will be automatically loaded every time AutoCAD starts. The file is normally located in the SUPPORT subdirectory of the AutoCAD installation. – This file loads every time a new drawing session is started in AutoCAD 2022, 2022i or 2022 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 file would load in the FIRST drawing of the AutoCAD 2022 type products only the file will load with subsequent drawings. Since AutoCAD R14 doesn’t support multiple drawing sessions you won’t have to worry about the file with R14. Like the file, is normally located in the SUPPORT subdirectory of the AutoCAD installation.S::STARTUP function – This function is typically within the file (or file for AutoCAD R14 installations) and its sole job is to execute customized mands 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 ExamplesIf you created an 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 es 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 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” )(setvar “dimtxt” )(princ))This example sets the default text size and dimension text size to a value of (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 times the value of the DIMSCALE that is already set in the drawing. To plete this task we’ll need a new mand 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” (* (getvar “dimscale”)))(setvar “dimtxt” )(princ))Note that the statement that sets the text size first gets the DIMSCALE value then multiplies it by 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 functionsAs you begin to write your own programs it bees 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 uping 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 mands to AutoCAD’s vocabulary. By adding new mands, or C: functions, to AutoCAD’s mand set your users simply think they have a new AutoCAD mand they can use. Only you will know that they