Count walls in an open project¶
Use UnifiedApi to send commands to Archicad from a Python script. This example
counts walls returned from the current plan. It does not change the model.
Before you start¶
- Install the Tapir Add-On in Archicad. Tapir is a required part of the MultiConn Archicad setup: it provides most of the available commands, as well as the script palette.
- Install uv, which runs Python scripts and manages their dependencies.
- Open a project in Archicad. For this first example, keep only one Archicad instance open so the target project is clear.
Add the library to your Python project:
uv add multiconn_archicad
See the uv documentation for creating and managing a Python project. This guide focuses on the Archicad commands.
Run the script¶
Save this as count_walls.py:
from multiconn_archicad import UnifiedApi
from multiconn_archicad.models.official.types import ElementType
api = UnifiedApi()
walls = api.official.element_listing.get_elements_by_type(ElementType.WALL)
print(f"Walls found: {len(walls)}")
Run it from the folder containing the file:
uv run count_walls.py
The output looks like this; the number depends on your project:
Walls found: 42
api is your client: the Python object you use to send commands to Archicad.
api.official contains official Archicad commands. The command returns a list
of wall identifiers; len(walls) counts that list. These are identifiers, not
wall geometry or property values.
You can also prepare this file for the Tapir palette. The palette supplies the port of its Archicad instance, so you can use it even when several instances are open.
Choose a specific Archicad instance¶
With no connection arguments or command-line overrides, UnifiedApi() uses the
lowest listening port in the local API range, 19723–19743. It does not choose a
project by name or follow the frontmost Archicad window.
If you know the port of the instance you want, replace the client creation line:
api = UnifiedApi(port=19724) # Replace 19724 with your instance's port.
If it does not work¶
APIConnectionError: check that Archicad is running with a project open. If you supplied a port, check that it belongs to the intended instance.uvis not recognized: install uv and reopen your terminal.
Where to go next¶
Try element queries when you need to combine conditions such as element type, property values, or classification. Check that guide's Tapir requirements before running its examples.
For an application that discovers projects or switches between them, see structure scripts and applications.