Autolisp – Visual Lisp lessons

Lesson 1 – why AutoLISP?

Learning AutoLISP is radically different from learning AutoCAD. AutoLISP is a programming language with its own commands, its own structure, and its own syntax. However, with a knowledge of AutoLISP, AutoCAD operators can amplify their powers with AutoCAD. AutoLISP puts new tools at your fingertips: Mathematical calculations Creating variables to hold values Reading and changing AutoCAD system variables Creating reusable functions Accessing and changing entity properties Accessing drawing file properties Reading and writing ASCII files But why AutoLISP? Why not Read More...

Lesson 2 – AutoCAD and AutoLISP are Two Separate Programs

Though AutoLISP is an inherent part of AutoCAD, it is in fact an entirely separate program with different executable files, its own set of commands and syntax. AutoLISP expressions, however, can be typed in directly at the AutoCAD Command: prompt, and hence there needs to be a means of differentiating AutoLISP expressions from AutoCAD expressions. To initiate an AutoLISP expression, it must begin with either an open parenthesis “(” or an exclamation point “!”. When AutoCAD sees an expression that Read More...

Lesson 3 – AutoLISP Evaluates every Expression

The LISP part of AutoLISP stands for list processing, which describes what happens when you run a routine: AutoLISP processes lists or, as we say here, evaluates expressions. If you type in an AutoLISP expression at the Command line it will return the results of the processed list. Command: (+ 18 6) 24  Expressionresults Each AutoLISP expression is enclosed in parentheses. Expressions are made up of a function followed by arguments. The function is analogous to the “verb” or action Read More...

Lesson 4 – Every List is Evaluated in the Same Specific Manner

AutoLISP assumes that a list is an expression that needs to be evaluated. The function must be the first element in a list and its arguments must immediately follow it. A generalized AutoLISP function would look this way: AutoLISP evaluates the expression depending on the function definition and the explicit arguments that are designated. Some functions have required arguments and some have both required and optional arguments. In this book we will designate optional arguments in brackets, [optional argument]. Read More...

Lesson 5 – AutoLISP Distinguishes among Several Data Types

The bulk of this class will concentrate on learning the functions of AutoLISP. But, each of these functions requires certain types of arguments for the AutoLISP expression to make sense. For example, a function that adds two numbers together would require that its arguments be numbers. We need to be able to distinguish among five different data types: integers, reals, strings, lists, and symbols. We will learn about additional data types when we discuss AutoCAD entities and selection sets in Read More...

Lesson 6 – Assigning Values to Symbols

One of the most powerful features of AutoLISP is the ability to store a variable and then use it again later. In AutoLISP, these variables are called symbols, and they may be assigned a value using the (setq) function. Explanation: the (setq) function (setq symbol expression) The (setq) function must have two arguments, the symbol name and an expression assigned to the symbol name. Command: (setq A 12.0) A single (setq) command can set any number of variables. (setq symbol1 expression1 symbol2 expression2 symbol3 expression3 );end Read More...

Lesson 7 – Executing AutoCAD Commands through AutoLISP

Rather than have an entirely new set of drawing and editing commands, AutoLISP permits the user to tap all of AutoCAD's existing commands from within AutoLISP using the (command) function. Explanation: the (command) function (command [command_name] [argument...]) The first argument to the (command) function is always the command name. It is followed by the command’s options input in the same order they would be typed at the AutoCAD “Command:” prompt. AutoCAD commands and options are typed in as strings. DO NOT use Read More...

Lesson 8 – Storing and Setting AutoCAD’s System Variables

AutoCAD's SETVAR function, when used in conjunction with a system variable name, will display the current value and permit the user to input a new value. In AutoLISP, the user can read the value of any AutoCAD system variable using the (getvar) function, and can set any non-read-only system variable using the (setvar) function. Explanation: the (getvar) function (getvar) reads the value of any AutoCAD system variable: (getvar variable_name) The variable name is always a string. You should store the system Read More...

Lesson 9 – Setting Up an AutoLISP Routine

Section 1:
Setting Up an AutoLISP Routine In this section you will learn how to: Divide a LISP routine into parts Prompt for user input Create an AutoLISP file using Visual LISP Typical Structure of a Routine AutoLISP routines can become very complicated. Like any complex problem, it helps to “divide and conquer” in order to understand the steps that will be necessary for the solution. Considering one part at a time will help you figure out what else you need in other Read More...

Lesson10 – Loading an AutoLISP File

Once an AutoLISP file is created, it must be loaded in AutoCAD with the (load) function in order to be used. The (load) function (load filename) Loads the specified LISP file, where filename is the AutoLISP file name without the “.LSP” extension (“.LSP” can be included, but why type more than you have to?). The filename is a string so don’t forget to include quotes “ ” around it. Command: (load “box1”) Dialog Box Access (APPLOAD) You can also load AutoLISP files and other programs Read More...

Lesson11 – Using the Visual LISP Console Window

Another way to load and test routines is to use the Visual LISP console window. This lets you run certain lines or complete programs while giving you feedback in Visual LISP if you are using debugging tools. To run selected lines of code 1. In the edit window, highlight the text (from parenthesis to parenthesis) by double-clicking in front of the opening or behind the closing parenthesis. 2. Press the Load selection button on the Tools toolbar in Visual LISP. To run the Read More...

Lesson12 – Troubleshooting AutoLISP Files

Whenever you work with AutoLISP you will come across errors. Sometimes this is nothing more than a misspelling of a function or, very often, the wrong number of parentheses. Below are some common errors and some possible solutions. Explanation: the (type) function The “error: bad argument” message means that you have used the wrong data type. Quite often the arguments will be stored in a symbol so you will not be able to see what type of data it is. You Read More...

Lesson13 – Defining AutoLISP Functions

So far we have saved a series of AutoLISP expressions in a *.LSP file. Every time we load the *.LSP file, all expressions contained within it are executed. What would be more useful is to be able to create new AutoLISP functions and use them as many times as desired without loading each time. Such user-defined AutoLISP functions are created using the (defun) function. Explanation: the (defun) function (defun name ( [arguments] ) [the AutoLISP routine(s)...] );close defun The name is a Read More...

Lesson14 – Creating AutoCAD Command Functions

Not only can you create new AutoLISP functions, but in a similar manner, you can also create new AutoCAD commands! That is, the function name can be typed directly at the Command: prompt without using AutoLISP syntax. Creating a command-line function is simply a modified form of (defun). Explanation: the (defun C: ) function (defun C:name () <expression1> ... <expressionn> );end defun Notes The function name argument must have a name that starts with “C:” . The function must be defined with a nil argument Read More...

Lesson15 – Automatic Loading of LISP Files

Before a function can be used, the file which contains its code must be loaded using AutoLISP's (load) function. By combining a series of similar functions into a single file with a .LSP extension, you can create a library of LISP files. For example, if all the code for the BOX1, MIDPT, and TAG functions were stored in one file called CLASS.LSP, you could load all those functions at once by typing: (load “class”) Special Files: ACAD.LSP and ACADDOC.LSP If a group Read More...

Lesson16 – Utility Functions to Improve Performance

You may have noticed that our BOX1 program still doesn’t run as cleanly as most AutoCAD commands or other LISP routines that you may have previously used. After getting the core of a routine to work, you can add several simple functions to make it run more smoothly. Explanation: Utility Functions Each of these special commands returns nil except (princ). The expression (princ) displays the null character ASCII 00. Example “cmdecho” Command: (setvar “cmdecho” 1) Command: (command “line” “0,0” “1,5” “”) line From point: Read More...

Lesson17A – Telling AutoLISP Not to Evaluate an Expression

Besides specifying AutoLISP functions themselves, lists will be used for two key purposes in AutoCAD: specifying coordinates in space (“point” lists) or describing a specific AutoCAD entity (“entity definition” lists). To explicitly type in a point list, a list of three real numbers, creates a problem: AutoLISP will try to evaluate the list as a function. Command: (setq PT1 (1.0 2.0 0.0)) error: bad function (1.0 2.0 0.0) (setq PT1 (1.0 2.0 0.0)) Command: When typing in an explicit point list, the (quote) function will Read More...

Lesson17b – Creating a Point List from Symbols

Many times you will want to create a point list but the coordinate values are contained in AutoLISP symbols such as X, Y, and Z. What happens if we type ... Command: (setq PT4 '(X Y Z)) (X Y Z) But we didn't want an un-evaluated list (X Y Z), we wanted a list of the values of X, Y, and Z. What if we type: Command: (setq PT4 (X Y Z)) ERROR: null FUNCTION (X Y Z) (SETQ PT4 (X Y Z)) To solve our dilemma, Read More...

Lesson17C – Extracting Elements from a List

Extracting Elements from a List There are times when you will want to create a list from other lists. For example, you may want to get a point midway between two other points. To do this you would need the x coordinate of one point and the y coordinate of the other, and then do a bit of math. Two key functions, (car) and (cdr), are the essential tools in extracting elements from a list. The others, (cadr), (caddr) and (last) Read More...

Lesson18 – Using Additional Point List Functions

In the previous module we learned two AutoLISP functions that asked for user input and returned a point list: (getpoint) and (getcorner). You can also use (list), (quote), and a new function, (polar), to return a point list. Use these point lists with an AutoCAD command to place objects or to generate other lists. Two other functions also use points to give us information: (distance) and (angle). Angles in AutoLISP are always measured in radians relative to the X-axis Read More...

Lesson19 – Restricting Acceptable Input Values

One of the most tedious tasks for the AutoLISP programmer is error trapping, making sure the routine can handle all varied inputs from the user. By restricting the acceptable input values with the (initget) function, you can control information supplied by the user. Explanation: the (initget) function (initget [bits]) The bits is an integer that refers to the following restrictions to input: The (initget) function affects only the next (getxxx) function that is encountered. None of the initget bits affect the (getstring) Read More...

Lesson20 – Limiting Acceptable String Input Values

In addition to the bit option that restricts input, there is a keyword option of (initget) that expands the acceptable responses to include specific keyword strings. String input can be limited to selected responses by using keywords along with the (getkword) function. Explanation: (initget) with keyword (initget [bit] [keyword]) The keyword string is a single string that contains all acceptable keywords separated by spaces. (initget 1 “Red White Blue”) By capitalizing the minimum input required for each keyword, the user only needs to Read More...

Lesson21 – Good AutoLISP Programming Techniques

When creating AutoLISP routines, the programmer should keep in mind not only correct syntax, but also a well-structured program that is easy to comprehend, forgiving of mistakes, easy to debug, and easy to edit. Formatting You can format manually while you type. But Visual LISP includes helpful formatting tools. They automatically insert tabs and spaces where needed to give you added clarity and help you track parentheses. You can either Format edit window or Format selection. AutoLISP ignores spaces and carriage Read More...

Lesson22a – The Simplest Looping Function (repeat)

Programs frequently need to perform the same series of expressions multiple times. Rather than copy the same line a given number of times, the (repeat) function simplifies the process. Explanation: the (repeat) function (repeat number                  ... expression ... ) The number is the number of times, in integers, to repeat the enclosed expressions. Provided you can predetermine the number of loops desired, the (repeat) function is the simplest choice. Example (defun c:MCIRCLE () (setq NUMBER (getint "\nEnter number of circles: Read More...

Lesson22b – Processing the Elements of a List.

When we are working with a list of data, we frequently need to work with each individual element rather than the list as a whole. For instance, if we wanted to create a point, PT2, which is twice as far from the origin as PT1, then we will want to increase each of its coordinates separately by a factor of 2. By use of the (foreach) function, we are able to act on each element in a list. Explanation: the Read More...

Lesson22c – Creating a List of Points

Now that we have seen how useful the (foreach) function is in working with a list of data, we need to be able to easily gather data into lists. We already know one function, (list), that can be used to create a list. The (cons) function can help add data to a list, especially when used in a loop. Explanation: the (cons) function (cons new_first_element list) The (cons) function creates a new list by adding new_first_element to the beginning of list. For example, Read More...

Lesson22d- Conditional Expressions

Sometimes you will want a program to do different things depending on different conditions. This is called branching. In order to create program branches, we need to construct “test conditions.” If the test is true, then we do one result; if false, a different result. Conditional expressions can be used with several functions to achieve branching in AutoLISP routines. 1. Any expression can be used as a conditional. In AutoLISP, any expression is true if it evaluates to a non-nil value. Any Read More...

Lesson23 – A More Versatile Loop : the while Function

The (repeat) function is limited to situations where the programmer (or the user) can determine beforehand the number of loops desired. The more common looping situation is to continue to execute a series of expressions until a certain changing condition is met. This is exactly the use of the (while) function. Explanation: the (while) function (while expression1 expression2... expressionn ) where expressionx is a conditional statement. The (while) function first evaluates the expression1. As long as it is non- nil, the remaining expressions are evaluated and Read More...

Lesson24 – The Simplest Program Branch- the (if) Function

Branching is a fundamental part of programming. Based on the conditional statements from the previous topic, the (if) function creates a two-pronged branch: “if the condition is true, then do this; otherwise, do that.” The structure of the (if) function permits only one test. To evaluate multiple expressions, use the (progn) function. Explanation: the (if) function (if test-expression then-expression [else-expression]) The test-expression is the conditional expression; if it is non-nil, the then- expression is evaluated. If it is nil, the optional else-expression Read More...

Lesson25 – A More Versatile Program Branch- the (cond) Function

Many decision branches are multi-forked—that is, there are several possible outcomes, each with a unique result. Rather than nest a series of (if) statements, a single (cond) function can handle a multi-fork branch extremely well. Explanation: the (cond) function (cond                    (test1 expression11 ...                         expression1n )                 (test2 expression21 ...                         Read More...

Lesson27 – What an entity definition list looks like

Every object in AutoCAD has specific information associated with it that is stored in a database. This includes such information as layer, color, and linetype, as well as the points that define its specific geometry. This is known as the entity definition list, also called the entity association list. Since we cannot directly read the database we will need special AutoLISP functions to access the database and tell us about the entity. Once we have the entity name of Read More...

Lesson28 – How to interpret and manipulate an entity definition list (association list)

To see an entity definition list is fine, but our ultimate goal is to be able to use the values associated with certain DXF codes, and often to change the properties of an entity. To do that, we will need to understand the unique properties of an association list so that we can extract an object’s properties and change its definition list. Explanation: the (assoc) function Extracting association pairs (assoc code list) The (assoc) function searches the association list list for the Read More...

Lesson29 – How to change entity properties through AutoLISP

In the previous section we looked at methods that allows us to use DXF code data. Now we will examine how to change DXF code data. We could just continue to call AutoCAD’s CHANGE command using the (command) function to change the properties of an object. But, there is an old AutoLISP adage that states, “Real programmers don’t use the (command) function!” First we need to create new association pairs, then substitute one association pair for another, and finally update Read More...

Lesson30 – How to create entities

Entity definition lists can also be used to create an entity from scratch. To create an entity, you must define its properties. Supplying an association list or creating the list by asking for information from the user can do this. Explanation: the (entmake) function (entmake list) The (entmake) function creates a new entity defined by the list. The data in the list must be association lists and must contain the minimum information required to define the entity. Different entity types require different Read More...

Lesson31 – Creating a Selection Set in AutoLISP

Rather than work with a single entity, it is frequently more useful to work with groups of entities. By creating an appropriate selection set each entity within that selection set can be changed accordingly. Explanation: the (ssget) function (ssget [mode] [pt1] [pt2] [filter-list]) If no options are specified, (ssget) prompts the user through AutoCAD's general "Select objects:" prompt. Command: (setq SS1 (ssget)) Select objects: . . . <select interactively> . . . Select objects: <enter> <Selection set 1> The (ssget) function returns a selection set. This Read More...

Lesson32 – Manipulating Selection Sets

Once a selection set is created, a variety of functions can be used to make changes to the selection set or to give you information about it. Explanation: the (ssxxx) functions PRACTICE In this practice you will modify the previous Move and Rotate routine to make sure that you have selected or deselected all the desired objects. Estimated time for completion: 10 minutes. Steps to the solution 1. Use (ssadd) to add any additional items to the selection set. 2. Use (ssdel) to remove any Read More...

Lesson33 – Processing Entities within a Selection Set

Once we have created a selection set, the next step is to access each object in the set and apply the rest of the routine to it. But, we cannot use the (foreach) function we used earlier. Selection sets are a special data type called a pickset and need specific functions to access the data. The function to process the elements of a selection set is (ssname). Explanation: the (ssname) function (ssname selection_set position) The selection_set is a selection set and the Read More...

Lesson34 – Creating Selection Sets Using Filters

Besides using the standard selection set tools analogous to AutoCAD (Window, Crossing, Previous, Last, etc.), AutoLISP provides a mechanism, through the (ssget) filter, to select all entities within a drawing that have specific properties. Explanation: the (ssget “X”) function (ssget "X" filter-list) The "X" mode of the (ssget) function scans the entire drawing and creates a selection set containing the names of all main entities that match the criteria specified in the filter-list. The filter-list is an association list that contains a series Read More...

Lesson35 – Additional Filter Options for (ssget)

Filter lists for (ssget) can include a variety of options, including relational tests for numerical values and Boolean expressions that look for information such as “this and that,” “this or that,” or “not this and that.” Relational Tests For numeric groups (integers, reals, points, and vectors) you can use relational test operators. To apply a relational test to the value of a numeric group within a filter-list, place a -4 group code along with the operator in a sub-list immediately preceding Read More...

Lesson36 – Accessing Symbol Tables

Certain information about each drawing is contained in symbol tables. Specifically, there are tables that contain the properties of all layers, linetypes, named views, text styles, block definitions, UCSs, and viewports within the drawing. Explanation: the (tblnext) function (tblnext table_name [T]) The (tblnext) function is used to scan an entire symbol table. For example: (tblnext "layer"). Valid tables that can be scanned include: Each time the (tblnext) function is executed, it returns information on the next item in the given table. If the optional Read More...

Lesson37 – Modifying Table Entries

While you cannot modify table entries that were accessed using (tblnext) or (tblsearch), a more powerful function, (tblobjname), is included that makes it easier to access table entry information and, more importantly, allows you to modify the information. Explanation: the (tblobjname) function (tblobjname table_name symbol_name) The (tblobjname) function returns an entity name for the specified table entry. Using (entget) with the entity name returns an entity definition list that can be modified, and the table can then be updated using (entmod). Example Command: (setq Read More...

Lesson38 – Working with String Data

To create “clean” and effective displays and prompts, we will need to manipulate string data as shown in the functions below. Explanation: the (strxxx) functions Grouping strings and symbols: (setq LASTFILE “tryme.txt”) (setq PS (strcat "\nEnter file name or [” LASTFILE “]:“)) Command: Enter file name or [tryme.txt]: the system variable DWGNAME holds the extension as well as the name. To remove the extension you can use (strlen) and (substr) to remove the last four characters (the dot and three-letter extension). (setq NAME (getvar "dwgname")) (setq Read More...

Lesson39 – Formatting Strings with Control Codes

Some simple formatting of text can be handled through the use of expanded ASCII codes or control codes. We have already seen one of these, “\n”, which generates a new line. Here are some others that may be useful. Note that multiple control codes can be used within the same string. The control codes must be within the double quotes. The control codes must be lowercase. Example Command: (prompt “This text \nis on \nthree lines with a \ttab.”) This text is on three lines with Read More...

Lesson40 – Converting Data Types

Since the (prompt) function must be a string, you will frequently need to convert information in a different data type to a string. We have done this repeatedly with the (itoa) function from an integer to a string. There are also functions that convert reals and angles to strings. Of course you may also need to change strings back to integers, reals, or angles. Explanation Remember, real numbers are calculated and stored using at least 14 significant digits, although only Read More...

Lesson41 – Advanced List Functions

Another common task is processing lists so you can come up with the correct item to prompt or convert. You should become familiar with as many list functions as possible. These are the fundamental tools for storing, retrieving, and processing information with AutoLISP. Explanation: List functions Examples (setq LISTX '("jan" "feb" "mar" "apr" "may" "jun" "jul" )) (setq LISTZ '("aug" "sep" "oct" "nov" "dec")) Command: (reverse LISTX) ("jul" "jun" "may" "apr" "mar" "feb" "jan") Command: (length LISTX) 7 Command: (nth 4 LISTX) "apr" Command: (member "apr" LISTX) ("apr" "may" "jun" Read More...

Lesson42 – Working with External Files

We are not restricted to the AutoCAD drawing as the only place to store and retrieve information. AutoLISP provides the capability to use external files. In order to use a file you must first open it, giving it a symbol name and designating whether it is to be read from, written to, or appended. After use, the file must be closed. Explanation: the (open) and (close) functions (setq file_symbol (open filename mode)) (close file_symbol) The file_symbol is any symbol name you want to use Read More...

Lesson43 – Dialog File Access

Sometimes it helps to bring up a dialog box instead of having the user type in information. The (getfiled) function brings up a file dialog where you can specify the default extension. Other dialog boxes that might help in your work are the color dialog, (acad_colordlg), and alert box, (alert). The (getfiled) function This function displays the standard AutoCAD file dialog box. It returns the name of the file selected by the user, or nil if no file was selected. (getfiled title Read More...

Lesson44 – Converting Lists to Strings Using an External File

There is no predefined function to convert either a list or a symbol to a string. But we can create on using an inverse (read) function that converts data of any type to a string. Noting that (princ) will write any data type to a file, and that (read-line) returns a string, we can use a temporary file for conversion. (defun XTOS (ARG / FILE) (setq FILE (open "$temp" "w")) (princ ARG FILE) (close FILE) (setq FILE (open "$temp" "r")) (setq ARG (read-line FILE)) (close FILE) ) Example Command: Read More...

Lesson45 – Searching the AutoLISP File

Searching the AutoLISP File Throughout this class we have used these tools found in the Visual LISP editor to help us process the code: Parentheses matching Color coding Formatting Loading partial and full functions Checking the function in the console window Commenting We are now going to look at other debugging functions in the Visual LISP editor. These are not all the tools that come with Visual LISP but will give you a good start. The ones we will cover in Read More...

Lesson46a – Halting the Program

To use most of the other debugging tools, you need to stop the program in the middle of the process and then walk through it step by step. To do this, put a breakpoint in front of the parenthesis where you want to start. Then you can use the step buttons to proceed as needed. You can add as many breakpoints as you want in a routine. Toggle Breakpoint The Toggle Breakpoint command places a “stop” in your program or turns Read More...

Lesson46b – inspecting values

Inspect windows show information about AutoLISP objects and AutoCAD objects stored in symbols in your program. You can inspect AutoLISP entities such as strings, numbers, lists and symbols as well as AutoCAD objects such as a polyline, block definition, or selection set. For example, if you inspect the number 360, you will see the following window showing the value of the integer in binary, octal, decimal, hexadecimal and character formats. To inspect an object 1. Highlight the object you want to inspect. 2. Read More...

Lesson47 – Watching Evaluations

The Watch Window allows you to follow the current value of symbol variables as they are run through the program. If you are having a problem with incorrect data types being passed to a function you could see the actual information process as it is happening. Adding Symbols to the Watch Window To add a symbol to the window, highlight the symbol name in the program, right-click, and pick Add Watch. You can also use the Add Watch button and type Read More...

Lesson48 – Angles in AutoLISP

If you are using angles other than the default measured counter-clockwise from the positive X-axis, you will need to know the difference between two related commands: (getangle) and (getorient). The (getangle) function measures with the zero-angle at the current base angle setting in the Units dialog (system variable ANGBASE). The (getorient) function always measures with the zero-angle to the right (east, or positive X-axis), regardless of the ANGBASE setting. The system variable ANGBASE controls the zero (0) direction for Read More...

Lesson49- Accessing Subentities

When we execute the (entget) function with the name of a polyline as the argument, we get a list similar to the following: ((-1 . <entity name: 60000018>) (0 . "Polyline") (8."0")(66.1)(10.0.00.00.0)(70.0)(40.0.0) (41.0.0)(210.0.00.01.0)(71.0)(72.0)(73.0) (74.0)(75.0)) Notice that this list contains no information on the vertices of the polyline, while AutoCAD’s LIST command returns information on each vertex of a polyline. A similar situation applies to the attributes associated with a block insertion. Block inserts and polylines are considered complex entities because they consist Read More...

Lesson50 – Extracting Subentity Names

Since there are times when we need to access parts of polylines and blocks, we will need to get to the subentities using (entnext) and (nentsel). Explanation: (entnext) with polylines (entnext [entity name]) (entnext) takes as its argument an entity name and returns the entity name of the next entity or subentity. If we execute the following function and pick a polyline, the entity name returned refers to the main entity: Command: (setq PNAME (GETNAME)) <Entity name: <60000018> Executing (entnext) with the entity name Read More...

Lesson51 – Extracting Block Entities

Just as (entnext) works with old style polylines and attributes in a block, it may also be used to extract the entities that make up a block. This is done through the block definition table. Explanation: (entnext) with blocks Command:(setq B1 (tblnext "BLOCK" T)) ((0 . "BLOCK") (2 . "PART99") (70 . 64) (10 0.0 0.0 0.0) (-2 . <Entity name:40000018>)) The entity name associated with DXF code -2 is the first subentity of the block. Command: (setq SE1 (cdr (assoc -2 B1))) (Entity name: <40000018>) The Read More...

Lesson52 – Accessing Subentities (Alternate)

An alternative method of accessing subentities is through the (nentsel) function, “nested entity selection.” (nentsel) is similar to (entsel), except that when a complex entity is selected information on a subentity is returned. Explanation: the (netsel) function Polylines Command: (nentsel [prompt]) Select object: Pick on a pline ((<Entity name: 60000088>) (5.4532 7.20987 0.0)) The Entity name is that of the nearest vertex to the selection point. Blocks (nentsel) also lets us directly extract information about the entities that make up a block without accessing the block Read More...

Lesson53 – Accessing Subentities without User Input

While (nentsel) is very useful in accessing subentities, it does have the drawback of requiring user input. For instances in which the point selecting the subentity is already defined, the (nentselp) function is provided. Explanation: the (nentselp) function Command: (nentselp [prompt] point ) ((<Entity name: 60000093>) (10.50000 11.43533 0.0)) (nentselp) returns the same lists as (nentsel). When a PLINE is selected, it returns a two-element list similar to the one shown above. When a subentity of a BLOCK is selected, (nentselp) returns the same Read More...

Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons
SUBSCRIBE TO OUR NEWSLETTER

It's FREE!

Sign up and receive an email every time a new tutorial is published