Learn AutoCAD for free

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...

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...

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...

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...

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...

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...

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...

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...

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...

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...

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...

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...

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...

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...

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...

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...

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...
Show Buttons
Hide Buttons
SUBSCRIBE TO OUR NEWSLETTER

It's FREE!

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