Count Attribute Values

Function Syntax cav
Current Version 1.1
Download CountAttributeValuesV1-1.lsp
View HTML Version CountAttributeValuesV1-1.html
Donate

Program Description

This program enables the user to count the number of occurrences of attribute values across all or specific attribute tags in a selection of attributed blocks, ideal perhaps for when compiling a Material Take Off (MTO) in which material/part references may be stored in block attributes, among other use cases.

Upon issuing the command syntax cav (Count Attribute Values) at the AutoCAD command line, the user is prompted for a selection of attributed blocks whose attribute values are to be counted. If multiple attribute tags are found in the selection, the user will be presented with a dialog from which they may select the tags of attributes whose values are to be counted.

The user is then prompted to specify an insertion point for the table displaying the results of the count, with values sorted ascending alphabetically.

Note that this program may only be run on CAD platforms which support table objects.

Predefined Attribute Tags

By default, the program will consider all attribute tags held by blocks in the selection, with the user prompted to select one or more tags whose values are to be counted if multiple attribute tags are encountered.

However, the user can optionally predefine the tag or set of tags to be counted (thereby avoiding the dialog prompt) by populating the tag list argument supplied to the main function - this argument is empty by default:

(defun c:cav ( )
    (cav:main
        ""                ;; Optional Table Title
       '("Value" "Count") ;; Optional Table Column Headings
       '( )               ;; Optional predefined tag list (may use wildcards)
    )
)

The tag list argument is case-insensitive and also supports the use of wildcard operators (e.g. specifying '("PART*" "*TAG") will cause the program to count the values of attributes whose tags either start with PART or end with TAG).

As indicated by the above code block, the user also has the option to specify a title for the table and revise (or even remove) the table column headings, depending on the output desired.

Demonstration

Count Attribute Values.gif

Instructions for Running

Please refer to How to Run an AutoLISP Program.

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010