If found, it replaces every occurrence of old_ item with new_item and returns a new list with the changes made. The (subst) function searches the list for old_ item. To switch association pairs we will need to use a new command, the (subst) function. See also Accessing Subentities (Alternate) with autolisp in AutoCAD
Substituting one Association Pair for Another Command: (cdr (cons 8 “WALLS”)) “WALLS” But, when a list is its argument, the (cdr) function returns the second element as a list. The (cdr) function, when a dotted pair is its argument, returns the second element as an element, not a list.
This is the only way to create a dotted pair.įor example, if we wanted to create a new association pair that represented the layer WALLS: The (cons) function creates a new list by adding new_first_element to the beginning of list.įor example, if we wanted to create a new association pair that represented the start point of a line, where PT1 is (1.0 1.0 0.0) and 10 is the DXF code:īut, the ( cons) function will create a dotted pair if the second argument is an atom instead of a list. To add information to a list, we use the (cons) function.Įxplanation: the (cons) function with DXF codes To create a new association pair we must connect the DXF code with the proper information. But, there is an old AutoLISP adage that states, “Real programmers don’t use the (command) function!”įirst we need to create new association pairs, then substitute one association pair for another, and finally update the object in the drawing database.
We could just continue to call AutoCAD’s CHANGE command using the (command) function to change the properties of an object.
#Autocad lisp assoc 8 how to
Now we will examine how to change DXF code data. In the previous section we looked at methods that allows us to use DXF code data.