Skip to content

Work with commands and Python data models

A command sends a request to Archicad. The generated client checks your inputs and converts the response into Pydantic objects with named, typed fields. These generated objects are one of the library's main benefits: you can discover the API in your editor and use returned data without remembering nested JSON keys. Pydantic is the Python library that parses and validates these records.

Discover the API as you write

With api: UnifiedApi, your editor can show command groups, method signatures, parameter descriptions, and return types. Type api.tapir. or api.official. and use completion to explore the available groups.

Feature Why it helps
Function signatures See required arguments, optional arguments, and their types before running a command.
Enum choices Choose ElementType.WALL from completion instead of remembering an exact string.
Editor warnings Catch unknown methods, misspelled fields, and incompatible argument types while writing.
Dot access Read wall.elementId.guid rather than wall["elementId"]["guid"].
Runtime validation Check command inputs and parse returned structures even when the editor cannot check your data.

Editor warnings depend on your editor's type-checking settings. Search for Python type checking if you see completion but no warnings.

Keep types when passing data between functions

This read-only example passes each returned Pydantic object from print_wall_labels() to wall_label(). Both functions know the object's type:

from multiconn_archicad import UnifiedApi
from multiconn_archicad.models.official.types import ElementIdArrayItem, ElementType


def wall_label(wall: ElementIdArrayItem) -> str:
    return f"Wall GUID: {wall.elementId.guid}"


def print_wall_labels(api: UnifiedApi) -> None:
    walls = api.official.element_listing.get_elements_by_type(ElementType.WALL)
    for wall in walls:
        print(wall_label(wall))


print_wall_labels(UnifiedApi())

get_elements_by_type() returns ElementIdArrayItem objects. print_wall_labels() passes each object directly to wall_label() without converting it to a dictionary. The receiving function's annotation keeps completion and type checking available for wall.elementId and then .guid. You do not need to annotate each local variable yourself.

Example output, depending on the project:

Wall GUID: 12345678-1234-1234-1234-123456789abc

This returns element identifiers, not complete Archicad elements. Request geometry or properties with the commands intended for those values.

Build and validate data records

Pydantic records can also be constructed directly. They give a name and a type to each field instead of relying on dictionary keys throughout the script:

from multiconn_archicad.models.tapir.types import Coordinate2D

point = Coordinate2D(x=1.5, y=2.0)
print(point.x)
print(point.model_dump(mode="json"))

Output:

1.5
{'x': 1.5, 'y': 2.0}

Constructing this Python record does not create anything in Archicad. If an input cannot be parsed, Pydantic raises ValidationError with the affected field. Generated commands validate inputs before sending a request and validate returned data before giving it to your script.

This catches data-shape and type problems. A valid record still needs meaningful project-specific values; validation cannot decide which project you intended to edit.

Use the matching model namespace

Official models live under multiconn_archicad.models.official; Tapir models live under multiconn_archicad.models.tapir. Import enums from the provider used by the command. Even when names match, the two providers have separate model definitions.

Use enums for fixed choices, such as ElementType.WALL. Use strings for project names, paths, GUIDs, and other free-form inputs. A model's Literal discriminator, such as type="BuiltIn", is a fixed tag and may have no corresponding enum.

Read properties

For a complete property-read example that retains individual errors, see batch results. For queries combining properties, classifications, and element types, see element queries.

Convert a model to a dictionary

Use model_dump(mode="json") when you need a JSON-compatible dictionary. Use model_dump_json() when you need JSON text. These are Pydantic methods; search for Pydantic serialization for the full options.

Generated requests omit None and values equal to their Python defaults, including defaults you supplied explicitly. Required direct Literal tags are preserved. Omitting a field can mean something different from clearing it or setting the server's default, especially across Tapir versions.

Use raw JSON commands when the exact payload matters. See model configuration for application-wide validation and serialization options.

For quick scripts that are clearer with square-bracket access, the core client and TypedDicts provide a dictionary workflow with editor assistance but without Pydantic runtime validation.