a week ago - last edited a week ago by Laszlo Nagy
Hello everyone,
Is there any way to get the information stored in an element's "ID and Properties" field via Python's API?
I tried treating it as any other property and accessing it via either GetBuiltInPropertyId() or GetUserDefinedPropertyId(), but no luck. It doesn't seem to work like "normal" properties.
I found this discussion on the C++ forum, but I can't seem to apply it to Python.
Thanks in advance!
Solved! Go to Solution.
a week ago - last edited a week ago
Hi!
It should work with GetBuiltInPropertyID. Where did you get stuck?
Here's a commented example script I adapted from one of my other examples:
###############################################################################
# 0. GENERAL SETUP #
###############################################################################
from archicad import ACConnection
# Connect to a running Archicad instance
conn = ACConnection.connect()
assert conn, 'Communication Link is not available - timed out'
# Definitions for shorter access to API functionality
acc = conn.commands
act = conn.types
acu = conn.utilities
###############################################################################
# 1. List of Zone GUIDs #
###############################################################################
# Get all zones from the open Archicad Plan
zoneElems = acc.GetElementsByType('Zone')
# Make a list of Zone GUIDs from the list of zones
# (`.elementId` is a very confusing choice of name for the zone's GUID here.
# Don't confuse it with the Zones actual Element ID!)
zoneGuids = [zone.elementId for zone in zoneElems]
###############################################################################
# 2. Element IDs of Zones #
###############################################################################
# Get the ID for the built in property representing the Element Id
elemIdPropId = acu.GetBuiltInPropertyId('General_ElementID')
# Now obtain the actual Element ID of each zone
zoneElementIdValues = acc.GetPropertyValuesOfElements(zoneGuids, [elemIdPropId])
###############################################################################
# 3. Ouptut Zone GUIDs and Element IDs of Zones #
###############################################################################
# Now we iterate over both the zone GUIDs and Element ID property values which
# we obtained in step 2.
for zoneGuid, elemProp in zip(zoneGuids, zoneElementIdValues):
# The actual property value is a bit nested inside the result of step 2.
# (Detail: We can assume that there's only one value and thus use the 1st
# element with index 0, since we passed only one Property Id to
# `GetPropertyValuesOfElements` in step 2).
print(zoneGuid, elemProp.propertyValues[0].propertyValue.value)
Let me know if you have any questions about it!
Best,
Bernd
a week ago - last edited a week ago
Hi!
It should work with GetBuiltInPropertyID. Where did you get stuck?
Here's a commented example script I adapted from one of my other examples:
###############################################################################
# 0. GENERAL SETUP #
###############################################################################
from archicad import ACConnection
# Connect to a running Archicad instance
conn = ACConnection.connect()
assert conn, 'Communication Link is not available - timed out'
# Definitions for shorter access to API functionality
acc = conn.commands
act = conn.types
acu = conn.utilities
###############################################################################
# 1. List of Zone GUIDs #
###############################################################################
# Get all zones from the open Archicad Plan
zoneElems = acc.GetElementsByType('Zone')
# Make a list of Zone GUIDs from the list of zones
# (`.elementId` is a very confusing choice of name for the zone's GUID here.
# Don't confuse it with the Zones actual Element ID!)
zoneGuids = [zone.elementId for zone in zoneElems]
###############################################################################
# 2. Element IDs of Zones #
###############################################################################
# Get the ID for the built in property representing the Element Id
elemIdPropId = acu.GetBuiltInPropertyId('General_ElementID')
# Now obtain the actual Element ID of each zone
zoneElementIdValues = acc.GetPropertyValuesOfElements(zoneGuids, [elemIdPropId])
###############################################################################
# 3. Ouptut Zone GUIDs and Element IDs of Zones #
###############################################################################
# Now we iterate over both the zone GUIDs and Element ID property values which
# we obtained in step 2.
for zoneGuid, elemProp in zip(zoneGuids, zoneElementIdValues):
# The actual property value is a bit nested inside the result of step 2.
# (Detail: We can assume that there's only one value and thus use the 1st
# element with index 0, since we passed only one Property Id to
# `GetPropertyValuesOfElements` in step 2).
print(zoneGuid, elemProp.propertyValues[0].propertyValue.value)
Let me know if you have any questions about it!
Best,
Bernd
a week ago
Hi Bernd,
Thank you for your quick and detailed reply. I have since had a adjust your script to fit mine, and I'm pleased to say it works perfectly.
The problem was that I didn't know the Build In Property Name was General_ElementID. I ran GetAllPropertyNames() and then looked for "ID and Properties".
Thanks again,
Benjamin