Skip to content

Use dictionaries with the core client

CoreCommands sends JSON commands and returns dictionaries. It is the transport used by the generated API, and you can use it directly in your own scripts.

For a short script, result["elements"] may be all you need. The core client skips building and validating the generated Pydantic records. TypedDicts let you keep that dictionary workflow while giving your editor information about keys and value types.

Read wall identifiers

Follow the quick-start setup. This read-only example uses an official command and prints the GUIDs of walls from the current plan:

from typing import cast

from multiconn_archicad import CoreCommands
from multiconn_archicad.dicts.official.commands import (
    GetElementsByTypeParameters,
    GetElementsByTypeResult,
)
from multiconn_archicad.models.official.types import ElementType

core = CoreCommands()
params: GetElementsByTypeParameters = {"elementType": ElementType.WALL.value}
raw = core.post_command("API.GetElementsByType", dict(params))
result = cast(GetElementsByTypeResult, raw)

print(f"Walls found: {len(result['elements'])}")
for wall in result["elements"]:
    print(wall["elementId"]["guid"])

Example output; the count and GUID depend on the project:

Walls found: 1
12345678-1234-1234-1234-123456789abc

The raw JSON payload needs the enum's string value, so this example uses ElementType.WALL.value. Generated client methods accept the enum itself. dict(params) supplies the ordinary dictionary expected by the core method.

cast(...) tells the editor which response shape you expect. It does not convert or check the response. Enable type checking in your editor to see warnings for misspelled keys, missing required keys, or incompatible values.

What TypedDict adds

A TypedDict describes an ordinary dictionary. You still use square brackets, and the data can go directly into normal dictionary-processing code.

In your script What your editor can help with
params: GetElementsByTypeParameters Required parameter names and their types.
result: GetElementsByTypeResult Available response keys and nested structures.
A function parameter annotated with a TypedDict The dictionary shape expected by that function.

Type checking happens in your editor or a tool such as mypy or Pyright. Python does not validate a dictionary merely because it has a TypedDict annotation. Use the generated Pydantic API when you want runtime validation and returned objects with dot access.

Send official or Tapir commands

  • core.post_command("API.GetElementsByType", ...) sends an official command.
  • core.post_tapir_command("GetElementsByType", ...) sends a Tapir command.

The command names and response shapes are provider-specific. Import request and response TypedDicts from the matching provider's commands module. Shared records live in its types module:

multiconn_archicad.dicts.official.commands
multiconn_archicad.dicts.official.types
multiconn_archicad.dicts.tapir.commands
multiconn_archicad.dicts.tapir.types

The core methods unwrap the command response and raise for reported command or request failures. Nested per-element errors can still be present in a successful response. Check them before treating every item as usable.

Mix dictionaries and generated clients

Both clients can share one endpoint. This complete example reads project metadata as a dictionary and uses a generated command for walls:

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

core = CoreCommands()
api = UnifiedApi(core)
project = core.post_tapir_command("GetProjectInfo")
walls = api.official.element_listing.get_elements_by_type(ElementType.WALL)
print(f"{project['projectName']}: {len(walls)} walls")

Use dictionaries when they make a small task clearer or when exact payload control matters. Use generated objects when named fields, reusable functions, and validation help the workflow. You can combine them within the same script.