(I revised this code)
The block image is an interesting aspect of tables.
I wrote some generalized functions to convert a table column to and from block images.
I also included a test function that allows the user to select a table and convert one column (0 indexed) to symbols
given the block name is the text in the cell.
I also added some errortrapping (stability is important) and the toobjectconvert function is a simplified version of a toolbox
function I use ALL the time...
P=
Code:
;___________________________________________________________________________________________________________|
;
; Written By: Peter Jamtgaard C.E., P.E., S.E. copyright 2018 All Rights Reserved
;___________________________________________________________________________________________________________|
;
; Any use by unauthorized person or business is strictly prohibited.
;___________________________________________________________________________________________________________|
;
; Abstract: This library provides functions to convert cells in tables to block symbols
;___________________________________________________________________________________________________________|
;
; Command Line Function Header List
;___________________________________________________________________________________________________________|
;* C:TableCellSymbol
;* Command Line Function to test function to convert a cell in a table to a block symbol
;___________________________________________________________________________________________________________|
;
; General Function Header List
;___________________________________________________________________________________________________________|
; Function, Arguments and Description
;* (ErrorTrap symFunction)
;* Function to trap errors. Returns value or T for success and nil for failure
;* (TableCellBlockNameToSymbol objTable intRow intColumn)
;* Function to change a cell in a table to a block symbol (given the text in the cell is a valid block name)
;* (TableCellBlockSymbolToName objTable intRow intColumn)
;* Function to change a cell in a table from a block symbol to a block name
;* (TableColumnToSymbol objTable intColumn)
;* Function to change a column in a table to block symbols (given the text in the table is a valid block name)
;* (ToObject value)
;* Function to convert a vla-object, entitynames, entsels, elists, handles or objectid's to a vla-object.
;$ Header End
; Function Headers
;___________________________________________________________________________________________________________|
;
; Command Line Function to text Table Column To Symbol function
;___________________________________________________________________________________________________________|
(defun C:TableSymbolColumn ()
(if (and (setq lstSelection (entsel "\nSelect Table: "))
(setq objTable (ToObject lstSelection))
(= (vla-get-objectname objTable) "AcDbTable")
(setq intColumn (getint "\nEnter Column to convert (0 indexed): "))
(< -1 intColumn (vla-get-columns objTable))
)
(TableColumnToSymbol objTable intColumn)
)
)
;___________________________________________________________________________________________________________|
;
; Function to trap errors. Returns value or T for success and nil for failure.
;___________________________________________________________________________________________________________|
(defun ErrorTrap (symFunction / objError result XYZ)
(if (vl-catch-all-error-p
(setq objError (vl-catch-all-apply
'(lambda (XYZ)(set XYZ (eval symFunction)))
(list 'result))))
nil
(if result result 'T)
)
)
;___________________________________________________________________________________________________________|
;
; Function to change a cell in a table to a block symbol (given the text in the cell is a valid block name)
;___________________________________________________________________________________________________________|
(defun TableCellBlockNameToSymbol (objTable ; Object Table
intRow ; Integer Row Index
intColumn ; Integer Column Index
/
intObjectID ; Integer Block Definition Object ID
strBlockName) ; String Block Name
(and
(setq colBlocks (vla-get-blocks (vla-get-document objTable)))
(Errortrap (quote (setq strBlockName (vla-getText objTable intRow intColumn))))
(Errortrap (quote (setq intObjectID (vla-get-objectID (vla-item colBlocks strBlockName)))))
(Errortrap (quote (vla-setcelltype objTable intRow intColumn acBlockCell)))
(Errortrap (quote (vla-setblocktablerecordID objTable intRow intColumn intObjectID :vlax-true)))
(Errortrap (quote (vla-SetCellAlignment objTable intRow intColumn acMiddleCenter)))
)
)
;___________________________________________________________________________________________________________|
;
; Function to change a cell in a table from a block symbol to a block name
;___________________________________________________________________________________________________________|
(defun TableCellBlockSymbolToName (objTable ; Object Table
intRow ; Integer Row Index
intColumn ; Integer Column Index
/
intObjectID ; Integer Block Definition Object ID
strBlockName) ; String Block Name
(and
(setq objTable (toobject objTable))
(setq colBlocks (vla-get-blocks (vla-get-document objTable)))
(Errortrap (quote (vla-setcelltype objTable intRow intColumn acTextCell)))
(Errortrap (quote (vla-setblocktablerecordID objTable intRow intColumn intObjectID :vlax-false)))
(Errortrap (quote (vla-SetCellAlignment objTable intRow intColumn acBottomLeft)))
)
)
;___________________________________________________________________________________________________________|
;
; Function to change a column in a table to block symbols (given the text in the table is a valid block name)
;___________________________________________________________________________________________________________|
(defun TableColumnToSymbol (objTable ; Object Table
intColumn ; Integer Column Index
/
intRow ; Integer Row Index
intObjectID ; Integer Block Definition Object ID
strBlockName) ; String Block Name
(if (and
(setq objTable (toobject objTable))
(= (vla-get-objectname objTable) "AcDbTable")
(setq colBlocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
(errortrap '(vla-put-RegenerateTableSuppressed objTable 0))
)
(progn
(repeat (- (setq intRow (vla-get-rows objTable)) 2)
(setq intRow (1- intRow ))
(TableCellBlockNameToSymbol objTable intRow intColumn)
)
(errortrap '(vla-put-RegenerateTableSuppressed objTable 0))
)
)
)
;___________________________________________________________________________________________________________
;
; Function to convert a vla-object, entitynames, entsels, elists, handles or objectid's to a vla-object.
;___________________________________________________________________________________________________________
(defun ToObject (value / symType)
(if (and
(setq symType (type value))
(or objDocument
(setq objDocument (vla-get-activedocument (vlax-get-acad-object)))
)
(or (= symType 'vla-object)
(and (= symType 'ENAME)
(setq value (vlax-ename->vla-object value))
)
(and (= symType 'STR)
(setq value (handent value))
(entget value)
(setq value (toobject value))
)
(and (= symType 'LIST)
(= (type (car value)) 'ENAME)
(setq value (toobject (car value)))
)
(and (= symType 'LIST)
(= (type (car value)) 'LIST)
(= (type (cdar value)) 'ENAME)
(setq value (toobject (cdar value)))
)
(and (= symType 'INT)
(= (strlen (itoa value)) 10)
objDocument
(setq value (errortrap (quote (vla-objectidtoobject objDocument value))))
)
)
)
value
)
)
(vl-load-com)