Skip to content

Element queries

Use element queries to find matching Archicad elements or filter IDs you already have. Start here for scripts. The query reference defines the detailed contracts; query editing covers field-driven editors and unfinished drafts.

Requirements and current limits

  • Install MultiConn Archicad in your Python project and Tapir 2.0.0 or newer in the target Archicad instance. Query discovery and execution check this requirement.
  • The default search covers the main/floor-plan database, regardless of the active window. It covers all stories and adds no visibility/editability filter. This is the supported first-release search scope.
  • Property tests currently support scalar text, integer/real numbers, and Boolean values. Classification, element-type, layer and saved layer-combination predicates are also available.
  • Numeric query reads request precise, locale-independent strings from Tapir. Quantity operands use SI units, except angles use degrees. IntegerTest compares integers exactly. RealTest uses relative and absolute tolerances of 1e-10; values within tolerance match equality and inclusive ordering, and fail strict ordering. See the numeric comparison contract.

Searches are read-only and do not change selection. Supplied-population filters evaluate their input IDs without listing a new floor-plan population.

Find elements

This complete example finds walls and doors in the default scope. It needs an open Archicad project with the required Tapir version; it needs no property GUIDs.

from multiconn_archicad import UnifiedApi
from multiconn_archicad.models.tapir.types import ElementType
from multiconn_archicad.utilities.queries import (
    ElementTypePredicate,
    ElementTypeTest,
    Query,
)

api = UnifiedApi()

query = Query(where=ElementTypePredicate(test=ElementTypeTest(types=(ElementType.WALL, ElementType.DOOR))))
matches = api.utilities.element.find_elements(query)
print(f"Matches: {len(matches)}")
for element in matches:
    print(element.elementId.guid)

Follow the quick-start setup and run this as a Python script. The following live examples continue with api from this setup. A query's type tuple means membership in any listed type. find_elements() returns unique matching IDs and omits ordinary per-element evaluation errors. Use diagnostic search when an empty result needs explanation.

Combine conditions

Use AllOf for AND and AnyOf for OR. Groups can be nested:

from multiconn_archicad.models.tapir.types import ElementType
from multiconn_archicad.utilities.queries import AllOf, AnyOf

query = Query(
    where=AllOf(
        items=(
            ElementTypePredicate(test=ElementTypeTest(types=(ElementType.WALL, ElementType.DOOR, ElementType.SLAB))),
            AnyOf(
                items=(
                    ElementTypePredicate(test=ElementTypeTest(types=(ElementType.WALL,))),
                    ElementTypePredicate(test=ElementTypeTest(types=(ElementType.DOOR,))),
                )
            ),
        )
    )
)
matches = api.utilities.element.find_elements(query)  # Walls or doors; slabs fail.

Negative comparisons belong to individual tests, such as is not and does not contain. Their behavior for unavailable properties is described in the comparison reference.

Enumeration and GUID fields use EnumTest, MultiEnumTest, and GuidTest inside the same PropertyPredicate. For example, after discovering the appropriate field:

from multiconn_archicad.utilities.queries import CollectionOperator, MultiEnumTest

# Compare the complete multi-choice selection, ignoring order:
selection = MultiEnumTest(operator=CollectionOperator.IS, value=("Red", "Blue"))
# Require every selected choice, using whole-label membership:
membership = MultiEnumTest(operator=CollectionOperator.CONTAINS, value=("Red", "Blue"))  # Requires both choices.

Use the exact labels offered by the field's metadata. This initial implementation assumes enum labels contain no semicolons; see the comparison reference for limits.

List fields use StringListTest, IntegerListTest, or RealListTest, selected from property metadata. They use the same collection operators:

from multiconn_archicad.utilities.queries import CollectionOperator, IntegerListTest, RealListTest, StringListTest

ordered_values = IntegerListTest(operator=CollectionOperator.IS, value=(1, 2, 1))
has_material = StringListTest(
    operator=CollectionOperator.CONTAINS, value=("GENERIC - STRUCTURAL", "CONCRETE")
)  # Requires both.
has_pitch = RealListTest(operator=CollectionOperator.CONTAINS, value=(30,))  # Degrees for angle properties.

List equality preserves order and duplicates. String items use casefold matching; numeric items retain the scalar Integer/Real comparison policies. String-list items also assume no semicolons; an empty read is interpreted as an empty list.

Query layers and saved layer combinations

Discover the Layer fields to obtain project-specific dropdown choices:

from multiconn_archicad.utilities.queries import (
    GuidOperator,
    LayerCombinationNamePredicate,
    LayerInfo,
    LayerNamePredicate,
    LayerPredicate,
    TextOperator,
    TextTest,
)
from multiconn_archicad.utilities.queries.editing import QueryRow

fields = api.utilities.element.discover_query_fields(
    [
        QueryRow(predicate={"kind": "layer"}),
    ]
)
layer_field = fields.resolve({"kind": "layer"})
assert isinstance(layer_field, LayerInfo)
for attribute in layer_field.attributes:
    print(attribute.guid, attribute.index, attribute.name)

# Select the intended attribute from the choices above:
chosen_layer = next(item for item in layer_field.attributes if item.name == "A-Walls")
query = Query(
    where=LayerPredicate(
        test=layer_field.create_test(operator=GuidOperator.IS, value=chosen_layer.guid),
    )
)
matches = api.utilities.element.find_elements(query)

# Match current layer names with ordinary text operators:
query = Query(
    where=LayerNamePredicate(
        test=TextTest(operator=TextOperator.STARTS_WITH, value="A-"),
    )
)

# Visible in at least one saved combination whose name contains Documentation:
query = Query(
    where=LayerCombinationNamePredicate(
        test=TextTest(operator=TextOperator.CONTAINS, value="Documentation"),
    )
)

LayerCombinationPredicate(test=LayerCombinationTest(operator=GuidOperator.IS, value=guid)) selects one combination by GUID, using the same discovery pattern with kind="layer_combination". Both dropdown tests offer is and is not. The name variants use all TextTest operators. Combination tests inspect saved layer visibility without activating a combination. See the layer contract for negative-name semantics, missing references, and batched reads.

Discover properties and classifications

Property labels are project-dependent. Discover the fields and retain their GUIDs rather than treating a display name as an identifier:

properties = api.utilities.property.discover_query_fields()
for field in properties.search("description", supported_only=True):
    print(field.property_id, field.qualified_name, field.operators())

classifications = api.utilities.classification.discover_query_fields()
for system in classifications:
    print(system.system_id, system.name)
    for item in system.items:
        print(" ", item.item_id, item.code, item.name)

Adapt the search text to your project/language. Different GUIDs can share the same name. This example requires exactly one supported text match; if there are several, select the intended field by a discovered GUID instead:

from multiconn_archicad.models.tapir.types import ElementType
from multiconn_archicad.utilities.queries import PropertyPredicate, TextOperator, TextTest

choices = [field for field in properties.search("description", supported_only=True) if field.test_model is TextTest]
if len(choices) != 1:
    raise ValueError("Choose the intended text property by its discovered GUID.")
description = choices[0]

query = Query(
    where=AllOf(
        items=(
            ElementTypePredicate(test=ElementTypeTest(types=(ElementType.WALL,))),
            PropertyPredicate(
                field_id=description.property_id,
                test=description.create_test(operator=TextOperator.STARTS_WITH, value="External"),
            ),
        )
    )
)
matches = api.utilities.element.find_elements(query)

Classification predicates use the system GUID as field_id and an item GUID as the operand when required. See classification operators and examples.

Use element-type presets

The presets are immutable type tuples usable directly in ElementTypeTest:

from multiconn_archicad.utilities.queries import TYPES_3D_WITH_COMPONENTS

query = Query(where=ElementTypePredicate(test=ElementTypeTest(types=TYPES_3D_WITH_COMPONENTS)))
matches = api.utilities.element.find_elements(query)
Constant Contents Editor label
TYPES_ALL All 2D and 3D preset types, including components All Types
TYPES_3D Main model types used by get_3d_elements() 3D Types
TYPES_2D Drafting, annotations, markers, drawings, and individual cameras 2D Types
TYPES_3D_COMPONENTS Stair, railing, curtain-wall, beam, and column component types 3D Component Types
TYPES_3D_WITH_COMPONENTS Main types plus component types 3D Types with Components

The editor lists these groups first, followed by individual types. All Types is the union of the 2D and 3D sets, including components; Unknown, Group, Hotlink, and CamSet are outside all presets. Individual Camera is in TYPES_2D. See the constant definitions for complete membership. Presets save their concrete types, not a preset name. Type membership is separate from independence filtering: explicit components remain eligible under the default filters.

Filter IDs you already have

from multiconn_archicad.models.tapir.types import ElementType

selected = api.tapir.element.get_selected_elements()
query = Query(where=ElementTypePredicate(test=ElementTypeTest(types=(ElementType.WALL,))))
result = api.utilities.element.filter_elements_by_query_result(selected, query)
matching_selected = result.successes

Filter results preserve the supplied order and duplicate positions. The plain-list companion, filter_elements_by_query(selected, query), raises if any element has an evaluation error. This differs from concise search, which omits ordinary per-element errors. Neither filter method changes the selection.

Inspect failures

diagnostic = api.utilities.element.find_elements_result(query)
print("Candidates:", len(diagnostic.candidates))
print("Matches:", len(diagnostic.outcomes.successes))
for candidate, slot in zip(diagnostic.candidates, diagnostic.outcomes.slots):
    if slot.is_error:
        print(candidate.elementId.guid, slot.error.message)

SUCCESS contains a match, FILTERED means a non-match, and ERROR retains a per-element failure. Invalid queries, failed listings, and whole-command or transport errors raise from both search methods. An empty match list therefore does not by itself establish that every candidate was successfully evaluated. See results and failures.

Save and load queries

saved_query = query.model_dump_json(indent=2)
restored = Query.model_validate_json(saved_query, context={"require_schema_version": True})
assert restored == query

Keep schema_version in saved data. Parsing checks structure and version presence; execution checks compatibility and current project references. Property and classification GUIDs are project-specific. Saving a query does not save a metadata snapshot or its matches. See serialization and editable drafts.

Runnable offline examples

These examples use synthetic metadata or a fake transport and require no Archicad instance. Run them from the repository environment, for example python examples/element_query_execution.py.

Example Demonstrates
Execution Concise/diagnostic search and strict/aligned filtering through the generated client
Query schema Construction, JSON, and validation
Fields Field descriptors and compatible tests
Discovery Catalogue lookup and unsupported metadata
Classifications Classification trees and assignments
Editable rows Draft repair, persistence, and compilation
Property evaluation Comparisons and property conditions
Predicate evaluation Nested groups and batched context data