Modifying Table Entries with autolisp in AutoCAD

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 LAYERNAME (tblobjname “LAYER” “Walls”))
<Entity name: 19505a8>

Command: (entget LAYERNAME)
((-1 . <Entity name: 19505a8>) (0 . “LAYER”) (5 . 35”)
(100 . “AcDbSymbolTableRecord”) (100 . “AcDbSymbolTableRecord”)
(2 . “WALLS”) (70 . 64) (62 . “BLUE”) (6 . “CONTINUOUS”))

  • Symbol Table entries may only be modified with (entmod) if they were obtained using (tblobjname). They cannot be modified if they were obtained using (tblnext) or (tblsearch).
  • You can create new Symbol Table entries using (entmake).

Practice

In this practice you will use (tblobjname) to obtain the entity name of a text style so that you can modify the style. Estimated time for completion: 10 minutes.

1. Open the drawing RATCHET.DWG. Make “Title” the current text style and place some text on your drawing.

2. Get the entity name of the text style “Standard” by using:

See also  Storing and Setting AutoCAD’s System Variables with Autolisp

(setq TXNAME (tblobjname “style” “standard”))

3. Get the entity definition list of the style using:

(setq TXL (entget TXNAME))

4. Change the font of the style to “romand.shx” by typing in the following expression:

(setq TXL2 (subst (cons 3 “romans.shx”) (assoc 3 TXL) TXL))

5. Update the style’s definition using:

(entmod TXL2)

6. REGEN to see the change.

7. Change the color of layer “OBJECT” to color 4 using the same process

8. If you have time: Create a standard versatile program that would do this according to the table and DXF information.

Back to top button