Discover instances and select a project¶
Use MultiConn when your application needs project discovery, metadata, or more
than one Archicad instance. Create it at application startup and pass it to the
shell or runner. For a one-project script, start with UnifiedApi.
from multiconn_archicad import MultiConn, is_session_ready
conn = MultiConn()
for port, header in conn.open_port_headers.items():
if is_session_ready(header):
print(f"{port}: {header.archicad_id.projectName}")
else:
print(f"{port}: project metadata is not ready")
MultiConn() normally defers discovery until you access connections. Discovery
probes the configured ports and starts background metadata reads. In normal
script mode, reading a header's metadata can wait for those reads.
See lifecycle and events for GUI behavior.
Select one connection¶
The manager's primary is the application's selected connection. It is not
necessarily the frontmost Archicad window. Initially, the lowest discovered port
is selected when no primary already exists.
from multiconn_archicad import MultiConn, Port
conn = MultiConn()
target_port = Port(19725) # Replace with a discovered instance's port.
if target_port not in conn.open_port_headers:
raise RuntimeError(f"No discovered instance at port {target_port}.")
conn.primary = target_port
header = conn.primary
You can assign a Port or a ConnHeader. A script launched by the shell should
receive the selected header. Its implementation functions can receive
header.unified, header.core, or header.standard.
Understand the connection lists¶
| Property | Meaning |
|---|---|
open_port_headers |
Managed headers indexed by discovered listening port. |
pending |
Headers whose metadata fetch is still pending. |
ready |
Headers whose discovery completed with ready status. Check task-specific requirements too. |
failed |
Headers whose metadata discovery failed. |
active |
Headers explicitly added to the batch worklist with connect. |
active is a chosen worklist, not a readiness check. connect.all() adds all
managed headers to it; disconnect removes them from that worklist. Neither
operation opens or closes an Archicad project.
conn.connect.all()
conn.disconnect.from_ports(Port(19725))
for port, header in conn.active.items():
print(f"Queued: {port}")
These snippets continue the selection example. Use readiness guards before
running commands. To find newly opened instances or refresh existing metadata,
call conn.refresh.all_ports().
Close an instance deliberately¶
The quit action closes Archicad, unlike disconnect. Finish any current work
and handle unsaved changes before using it. For a known managed header:
conn.quit.from_headers(header)
This is an action example, not part of discovery. See project workflows for opening and switching.