List All Properties of Selected Elements

Last week I showed how to get a list of all available properties in the Archicad Python API. But how do you get from this list of properties to actually evaluating them on e.g. selected elements? This was requested by Stefan Boeykens in the LinkedIn comments of the post.

Code Example

I’ve adapted the previous example of How to Use Property GUIDs to achieve this. One tough part is to handle the several layers of indirection to get the the actual values. An understanding of Python List Comprehensions is necessary to follow the proposed solution.

from archicad import ACConnection

# Connect to a running Archicad instance
conn = ACConnection.connect()
acc = conn.commands
acu = conn.utilities

# Get GUIDs of all selected elements and prepare a list of the Element IDs
selectedElementGUIDs = acc.GetSelectedElements()
elemIDs = [x.propertyValues[0].propertyValue.value for x in
    acc.GetPropertyValuesOfElements(selectedElementGUIDs, [acu.GetBuiltInPropertyId('General_ElementID')])]

# Get GUIDs of all properties and prepare a list of their names
propertyGUIDs = [x.propertyId for x in acc.GetAllPropertyIds()]
propNames = [ for x in acc.GetDetailsOfProperties(propertyGUIDs)]

# Finally get all property values of the selected elements
propertyValues = [x.propertyValues for x in acc.GetPropertyValuesOfElements(selectedElementGUIDs, propertyGUIDs)]

# CSV Header
print('Element ID, Property Name, Value')

# Iterate through elements and the matching retrieved property values
for elemId, propValuesOfElem in zip(elemIDs, propertyValues):

    # Iterate through properties of one element
    for propName, propertyGUID, propertyValueWrapper in zip(propNames, propertyGUIDs, propValuesOfElem):
        res = acu.GetValueFromPropertyValue(propertyGUID, propertyValueWrapper.propertyValue)
        if res == 'notAvailable' or res == 'notEvaluated' or res == 'userUndefined':
            print(elemId, propName, res, sep=', ')

Example Output

Here’s a (truncated) example output for a single chair.

Element ID, Property Name, Value
FU - 002, Length (A), 0.7
FU - 002, Rotation Angle, 0.0
FU - 002, Area, 0.42
FU - 002, Element ID, FU - 002
FU - 002, Hotlink and Element ID, FU - 002
FU - 002, Height, 0.8
FU - 002, Library Part Name, Armchair 04 26
FU - 002, Unique ID, D540CF73-6B54-4064-91F5-D7FBD40BC676
FU - 002, Volume (Net), 0.072488952
FU - 002, Width, 0.6
FU - 002, Elevation to Project Zero, 0.1
FU - 002, Elevation to 1st Reference Level, 0.1
FU - 002, Elevation to 2nd Reference Level, 0.1
FU - 002, Elevation to Sea Level, 0.1

How to Run this Yourself

  1. Save the above script as e.g.
  2. Open Archicad and the Python Palette (I think the palette also guides you through installing Python in case you don’t have it)
  3. Navigate to the saved script and execute it


Leave a Reply

Your email address will not be published. Required fields are marked *