Save project identity for later runs¶
Serialize a header when your tool needs to remember which project and Archicad executable to use later. This saves project identity and metadata; it is not a live connection or a copy of the Archicad project.
Save the selected project¶
This writes project.json in the current folder, replacing it if it exists:
import json
from pathlib import Path
from multiconn_archicad import MultiConn, has_project_identity
conn = MultiConn()
header = conn.primary
if header is None or not has_project_identity(header):
raise RuntimeError("Select a project with complete saved identity first.")
Path("project.json").write_text(
json.dumps(header.to_dict(), indent=2), encoding="utf-8"
)
An untitled project can be ready for API commands without having the identity needed for this workflow. Use the specific identity check, rather than assuming that all ready headers can be serialized.
Load the identity¶
import json
from pathlib import Path
from multiconn_archicad import ConnHeader
saved_data = json.loads(Path("project.json").read_text(encoding="utf-8"))
target = ConnHeader.from_dict(saved_data)
Loading does not start Archicad or establish a ready live session. Pass target
to the find/open workflow.
Provide teamwork credentials when needed¶
Passwords are not stored in serialized headers. For a loaded teamwork target, this continuation prompts for credentials and starts the opening workflow:
from getpass import getpass
from multiconn_archicad import MultiConn, TeamworkCredentials, TeamworkProjectID
if isinstance(target.archicad_id, TeamworkProjectID):
credentials = TeamworkCredentials(
username=input("Teamwork username: "),
password=getpass("Teamwork password: "),
)
conn = MultiConn()
conn.open_project.with_teamwork_credentials(target, credentials)
This opens a project and can show dialogs. Keep it in the application shell or runner, and get fresh metadata before starting operations.