Author Topic: About Symbol tables  (Read 2808 times)

0 Members and 1 Guest are viewing this topic.

QuestionEverything

  • Guest
About Symbol tables
« on: January 05, 2017, 02:03:16 PM »
Hello everyone,
Not sure what to ask, but here goes:
1. What are symbol tables? Is that some kind of dictionaries with easier access - if so then are they presented by dictionaries aswell - if so how to access them?
2. If they have nothing to do with the dictionaries then how do you delete/remove/erase table objects from there (simulating the PURGE command)

Tried the following and no effect:
Code - Auto/Visual Lisp: [Select]
  1. ; (mapcar 'entdel (mapcar '(lambda (x) (tblobjname "LAYER" (cdr (assoc 2 x)))) (SymbolTable->List "LAYER")))
  2. (defun SymbolTable->List ( tblnm / def Lst )
  3.   (while (setq def (tblnext tblnm (not def)))
  4.     (setq Lst (cons def Lst))
  5.   )
  6.   (reverse Lst)
  7. )

Although this works:
Code - Auto/Visual Lisp: [Select]

But I'm curious about the pure Vanilla method.

Any answer to my questions is appreciated! :)

tombu

  • Bull Frog
  • Posts: 289
  • ByLayer=>Not0
Re: About Symbol tables
« Reply #1 on: January 05, 2017, 02:20:50 PM »
https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-AutoLISP/files/GUID-7B91F774-B0CD-4F5B-9FFA-1130443E659B-htm.html
About Symbol Tables (AutoLISP)
 
Add to Collection
Symbol tables are used to store non-graphical information in a drawing’s database.

The symbol tables that exist in a drawing database are:

Symbol tables in each drawing database

Symbol table name

Description

APPID

Registered applications

BLOCK

Blocks (named and anonymous)

DIMSTYLE

Dimension styles

LAYER

Layers

LTYPE

Linetypes

STYLE

Text styles

UCS

Named User Coordinate Systems (UCSs)

VIEW

Named views

VPORT

Named viewports

Symbol table entries can be manipulated using the following functions:

tblobjname - Returns the entity name of a specified symbol table entry.
tblsearch - Searches a symbol table for a symbol name.
tblnext - Returns the next item in a symbol table.
entdel - Deletes objects (entities) or restores previously deleted objects.
entget - Retrieves an object's (entity's) definition data list.
entmake - Creates a new entity in the drawing.
entmod - Modifies the definition data of an object (entity).
handent - Returns an object (entity) name based on its handle.
Symbol Table Limitations
The following rules apply to symbol tables:

Symbol table entries can be created using entmake with a few restrictions, other than being valid record representations, and name conflicts can only occur in the VPORT table. *ACTIVE entries cannot be created.
Renaming symbol table entries to duplicate names is not acceptable, except for the VPORT symbol table.
Symbol table entries cannot be deleted with entdel.
The object states of symbol tables and symbol table entries may be accessed with entget by passing the entity name. The tblobjname function can be used to retrieve the entity name of a symbol table entry.
Symbol tables themselves cannot be created with entmake; however, symbol table entries can be created with entmake.
Handle group codes (5, 105) cannot be changed in entmod, nor specified in entmake.
Symbol table entries that are not in the APPID symbol table can have many of their fields modified with entmod. Modifying a symbol table record list must include its entity name, which can be obtained from entget but not from the tblsearch and tblnext functions. The 70 group code of symbol table entries is ignored in entmod and entmake operations.
Accessing Symbol Table Entries
The tblnext function sequentially scans symbol table entries, and the tblsearch function retrieves specific entries. Symbol table names are specified by strings. Both functions return lists with DXF group codes that are similar to the entity data returned by entget.

The first call to tblnext returns the first entry in the specified symbol table. Subsequent calls that specify the same table return successive entries, unless the second argument to tblnext (rewind) is nonzero, in which case tblnext returns the first entry again.

In the following example code, the function GETBLOCK retrieves the symbol table entry for the first block (if any) in the current drawing, and then displays it in a list format.

Code: [Select]
(defun C:GETBLOCK (/ blk ct)
  (setq blk (tblnext "BLOCK" 1))      ; Gets the first BLOCK entry.
  (setq ct 0)                         ; Sets ct (a counter) to 0.
  (textpage)                          ; Switches to the text screen.
  (princ "\nResults from GETBLOCK: ")
  (repeat (length blk)                ; Repeats for the number of
                                      ; members in the list.
    (print (nth ct blk))              ; Prints a new line, then each
                                      ; list member.
    (setq ct (1+ ct))                 ; Increments the counter by 1.
  )
 (princ)                              ; Exits quietly.
)
Entries retrieved from the BLOCK table contain a -2 group code that contains the name of the first entity in the block definition. If the block is empty, this is the name of the block's Endblk entity, which is never seen on occupied blocks. In a drawing with a single block named BOX, a call to GETBLOCK displays the following. (The name value varies from session to session.)

Results from GETBLOCK:
(0 . "BLOCK")
(2 . "BOX")
(70 . 0)
(10 9.0 2.0 0.0)
(-2 . <Entity name: 40000126>)
As with tblnext, the first argument to tblsearch is a string that names a symbol table, but the second argument is a string that names a particular symbol table entry in the table. If the symbol table entry is found, tblsearch returns its data. This function has a third argument, setnext, that you can use to coordinate operations with tblnext. If setnext is nil, the tblsearch call has no effect on tblnext, but if setnext is non-nil, the next call to tblnext returns the symbol table entry following the symbol table entry found by tblsearch.

The setnext option is useful when you are handling the VPORT symbol table, because all viewports in a particular viewport configuration have the same name (such as *ACTIVE). If the VPORT symbol table is accessed when the AutoCAD TILEMODE system variable is turned off, any changes have no visible effect until TILEMODE is turned on. Do not confuse VPORTS, which is described by the VPORT symbol table with paper space viewport entities.

The following processes all viewports in the 4VIEW configuration:

Code: [Select]
(setq v (tblsearch "VPORT" "4VIEW" T))         ; Finds first VPORT entry.
  (while (and v (= (cdr (assoc 2 v)) "4VIEW"))
  ..
                                               ; ... Processes entry ...
  .
  (setq v (tblnext "VPORT"))                   ; Gets next VPORT entry.
)
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

QuestionEverything

  • Guest
Re: About Symbol tables
« Reply #2 on: January 05, 2017, 04:01:20 PM »
I've read the help and my questions are out of the box. Thanks anyway Tom!

Digged into the soft-pointer of an tblobjname and I think I found the "layers dictionary":
Code - Auto/Visual Lisp: [Select]
  1. (setq LayersDictionary (entget (cdr (assoc 330 (entget (tblobjname "LAYER" "0"))))))
  2. _$
  3. ((-1 . <Entity name: 7ff6b2903820>)
  4.   (0 . "TABLE")
  5.   (2 . "LAYER")
  6.   (5 . "2")
  7.   (102 . "{ACAD_XDICTIONARY")
  8.   (360 . <Entity name: 7ff6b29048f0>)
  9.   (102 . "}")
  10.   (330 . <Entity name: 0>)
  11.   (100 . "AcDbSymbolTable")
  12.   (70 . 32)
  13. )
  14. ; Bonus:
  15. (setq LayersFiltersAndStatesDictionary (entget (cdr (assoc 360 LayersDictionary))))
  16. _$
  17. ((-1 . <Entity name: 7ff6b29048f0>)
  18.   (0 . "DICTIONARY")
  19.   (330 . <Entity name: 7ff6b2903820>)
  20.   (5 . "1FF")
  21.   (100 . "AcDbDictionary")
  22.   (280 . 1)
  23.   (281 . 1)
  24.   (3 . "ACAD_LAYERFILTERS")
  25.   (360 . <Entity name: 7ff6b2907110>)
  26.   (3 . "ACAD_LAYERSTATES")
  27.   (360 . <Entity name: 7ff6b2904900>)
  28.   (3 . "ACLYDICTIONARY")
  29.   (360 . <Entity name: 7ff6b2907100>)
  30. )
  31.  
The group code 70 represents the count of the layers, but suprisingly theres no gc -2 in there, for being potentially collected and erased (purged).
« Last Edit: January 06, 2017, 03:15:23 AM by QuestionEverything »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: About Symbol tables
« Reply #3 on: January 05, 2017, 04:34:28 PM »
@QuestionEverything:
What you write about gc -2 is new to me. Where do you see this behavior?

QuestionEverything

  • Guest
Re: About Symbol tables
« Reply #4 on: January 05, 2017, 04:46:06 PM »
@Roy:
I think you are familiar with the entnext iteration (example):
Code - Auto/Visual Lisp: [Select]
  1. (defun CollectEnamesInBlockDef ( BlockName / e Lst )
  2.   (setq e (cdr (assoc -2 (tblsearch "BLOCK" BlockName))))
  3.   (while (and e (/= "ENDBLK" (cdr (assoc 0 (entget e)))))
  4.     (setq Lst (cons e Lst))
  5.     (setq e (entnext e))
  6.   )
  7.   (reverse Lst)
  8. )
  9.  
This is from my previous thread https://www.theswamp.org/index.php?topic=52429.msg573715#msg573715

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: About Symbol tables
« Reply #5 on: January 05, 2017, 05:41:05 PM »
The tblnext function will return nil when the end of a table is reached.

Keep in mind that these tables are collections. So vlax-for and vlax-map-collection can also be used. The generic function below can be used on a block definition object but also on the layers object or the blocks object.
Code - Auto/Visual Lisp: [Select]
  1. (defun KGA_Conv_Collection_To_List (coll / ret)
  2.   (vlax-for a coll
  3.     (setq ret (cons a ret))
  4.   )
  5. )
« Last Edit: January 05, 2017, 05:47:43 PM by roy_043 »

mailmaverick

  • Bull Frog
  • Posts: 493
Re: About Symbol tables
« Reply #6 on: January 05, 2017, 11:31:37 PM »
It may sound dummy, but can anyone explain difference between SymbolTable, Dictionary and Collection ?
Thanks.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: About Symbol tables
« Reply #7 on: January 06, 2017, 03:51:55 PM »
Google search brought us back HOME LOL.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

QuestionEverything

  • Guest
Re: About Symbol tables
« Reply #8 on: January 06, 2017, 04:01:25 PM »
Google search brought us back HOME LOL.
I did not expect the existance of such thread, thanks!  :-D

Jeff H

  • Needs a day job
  • Posts: 6150
Re: About Symbol tables
« Reply #9 on: January 06, 2017, 04:17:03 PM »
One note about symbol tables......
Dictionaries are much better for searching, insertion, etc...
The legacy symbol tables require iterating through them opening the symbol table records and reading its name property vs dictionaries which are keyed by its name.