Archicad Python API
About automating tasks in Archicad using the Python API.

Selecting elements with Python

Anonymous
Not applicable
Hey,
is there an easy way to get all Zone elements in the same classification system or all walls in the same branch?
16 REPLIES 16
poco2013
Mentor
You can get the wall and zone elements by using the function: GetElementsByType(Zone or Wall)
Use GetClassificationsOfElements() to get the classifications of each of the above elements.

You will then have to iterate through the list to isolate the elements with the desired classification.

There is no direct method but the above is only a few lines
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
Boling1
Contributor
I guess code like this:
------------------------------------------------------------------------
from archicad import ACConnection
conn = ACConnection.connect()       #连接AC Application对象
assert conn
acc = conn.commands                 #赋值acc为AC的commands命令对象
act = conn.types                    #赋值act为AC的types类型对象
acu = conn.utilities                #赋值act为AC的utility实用工具对象

lstElements1 = acc.GetElementsByType("Zone")
and then? how to use GetClassificationsOfElements,can you give a code example?
like foreach item in lstElements1 :
.....
......
ArchiCAD 25
poco2013
Mentor
Sorry -- Picked the wrong function!!

space_classification_item = acu.FindClassificationItemInSystem( 'ARCHICAD Classification', 'Space')

element_ids = acc.GetElementsByClassification(space_classification_item.classificationItemId)
print(element_ids)

Once you have your element list, you can iterate through to find the element with the properties you want or match them to a specific element type?
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
Anonymous
Not applicable
It is possible to find just elements with Archicad Classification (root system)?
poco2013
Mentor
You are not clear as to what information you want based on classification? Are you seeking a list of element identifiers (guid), ids (names) ,or types, etc.?

The Archicad classification system is a tree structure with a root (system) name at the top and a item id (s) which may be branches, sub-branches or leaves.

Elements are classified based on the classification system name (root) and a item id which could be a branch, sub-branch or leaf name. You need both names (system & item) to retrieve a element Id. This is because there can be several different classification systems in Archicad with duplicate item names between each. How you retrieve a element depends on how it was classified in the "classifications and Properties" Tab. Elements can be classified at any level and by multiple class system structures.

Using: "GetElementsByClassification" returns a list of elements (guids) that have that classification.You then can use other functions to find or sort through the properties of each element.
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
Boling1
Contributor
sorry I'm new in Python, I runned

space_classification_item = acu.FindClassificationItemInSystem( "ARCHICAD Classification", "Wall")


and the result is :

Exception has occurred: StopIteration
File "C:\software\Python\Excel file exporter\toExcel-1.py", line 27, in <module>
space_classification_item = acu.FindClassificationItemInSystem("RCHICAD Classification", "Wall")

1>"ARCHICAD Classification" 'ARCHICAD Classification' which is right?
2>Wall Column Beam Window Door Object Lamp Slab Roof Mesh Zone CurtainWall Shell Skylight Morph Stair Railing Opening, I don't know what "Space" means?
3>Can you give a whole code, if I can run that code, I can get what you mean.

thx a lot
ArchiCAD 25
poco2013
Mentor
You are not clear as to what information you want based on classification? Are you seeking a list of element identifiers (guid), ids (names) ,or types, etc.? What information do you want to do what?
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
Boling1
Contributor
I just want to takeoff all walls's area,thickness,story_number,building_material,How can I do by python?
ArchiCAD 25
poco2013
Mentor
You might start by reviewing the videos and examples on Graphisoft's Python site.

For wall properties, the procedure is to obtain the IDs of both the element (wall) and the property, then use the Get Value function to obtain the property value. Story level and Building Material are not directly available but can be obtained by making a custom expression property referencing those properties, Then reference the custom properties.

The examples illustrate this.
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27