Symbol Tables

Symbol table entries can also be manipulated by the following functions:

The tblnext function sequentially scans symbol table entries, and the tblsearch function retrieves specific entries. Table names are specified by strings. The valid names are LAYER, LTYPE, VIEW, STYLE, BLOCK, UCS, VPORT, DIMSTYLE, and APPID. 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 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, 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.

(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 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 table, but the second argument is a string that names a particular symbol in the table. If the symbol 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 table entry following the 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 TILEMODE 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:

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