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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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