In last weeks post I showed an easy way to get GUIDs of properties. Now how do you use these GUIDs? One particular question I got was how to use them with the Archicad Python API. So I’ve made a sample script to demonstrate how to obtain specific property values for a list of elements.
Prerequisites
- Python 3.7+ and Archicad Python Package installed
- For details check the Archicad-Python Connection Guide from Graphisoft
- Running Archicad instance
Code Example
from archicad import ACConnection # Connect to a running Archicad instance conn = ACConnection.connect() acc = conn.commands act = conn.types # Define the properties you are interested in via their GUIDs properties = [ act.PropertyId ('13A61253-66A9-4494-9393-9E8F2E19D55E'), act.PropertyId ('BCB5813F-2115-4B8B-A12F-16CFE37C7B7F'), act.PropertyId ('0A33C71A-FEFB-4346-B1E2-4177D28333A2t'), ] # Get list of walls from Archicad elementIds = acc.GetElementsByType('Wall') # Obtain the property values for given elements from Archicad propertyValues = acc.GetPropertyValuesOfElements(elementIds, properties) # Print header of CSV output print('Element GUID, Property GUID, Property Value') # Iterate through elements and the matching responses for elemIdWrapper, valuesWrapperOfElem in zip(elementIds, propertyValues): elementGuid = elemIdWrapper.elementId.guid propValuesOfElem = valuesWrapperOfElem.propertyValues # Iterate through properties of one element for propertyId, propertyValueWrapper in zip(properties, propValuesOfElem): propertyStatus = propertyValueWrapper.propertyValue.status # Print csv line for different possible property responses # (not available, undefined and value) if propertyStatus == 'notAvailable': print(elementGuid, propertyId.guid, 'N/A', sep=', ') elif propertyStatus == 'userUndefined': print(elementGuid, propertyId.guid, 'UNDEFINED', sep=', ') else: value = propertyValueWrapper.propertyValue.value # Would need to properly handle different value types here print(elementGuid, propertyId.guid, value, sep=', ')
Never miss Add-On updates, special price offers or an article! Sign up for the newsletter and you’ll receive roughly one mail per week from me (occasionally more when there’s a special price upcoming).
Sample Output
Element GUID, Property GUID, Property Value c4c5bfc4-5805-47ef-bd58-d4a69dfbe1a4, 13a61253-66a9-4494-9393-9e8f2e19d55e, False c4c5bfc4-5805-47ef-bd58-d4a69dfbe1a4, bcb5813f-2115-4b8b-a12f-16cfe37c7b7f, UNDEFINED c4c5bfc4-5805-47ef-bd58-d4a69dfbe1a4, 0a33c71a-fefb-4346-b1e2-4177d28333a2, N/A 3c352137-fce9-4f8c-9a06-44a0872ed918, 13a61253-66a9-4494-9393-9e8f2e19d55e, False 3c352137-fce9-4f8c-9a06-44a0872ed918, bcb5813f-2115-4b8b-a12f-16cfe37c7b7f, UNDEFINED 3c352137-fce9-4f8c-9a06-44a0872ed918, 0a33c71a-fefb-4346-b1e2-4177d28333a2, N/A
Leave a Reply