MultiConn ArchiCAD is a connection object for ArchiCAD’s JSON API and its Python wrapper, designed to manage multiple open instances of ArchiCAD simultaneously.
Project description
MultiConn ArchiCAD is a Python-based connection object for ArchiCAD's JSON API and its Python wrapper. It is designed to manage multiple open instances of Archicad simultaneously, making it easier to execute commands across multiple instances.
Features
- Multi-connection Support: Connect to one, multiple, or all open instances of Archicad.
- Seamless Integration: Utilizes ArchiCAD's official Python package.
- Tapir Add-On Support: Run commands from the Tapir Archicad Add-On.
- Efficient I/O Operations: Handles connection management using concurrent or asynchronous code.
- Project Management: Find and open ArchiCAD projects programmatically.
Installation
You can install the latest version of the package from the following link using pip:
pip install https://github.com/SzamosiMate/multiconn_archicad/releases/latest/download/multiconn_archicad-0.1.2-py3-none-any.whl
The package depends on the Tapir Archicad Add-On. It is recommended to install the latest version of Tapir to access all features. While some functionality may work without the add-on, all tests have been conducted with it installed.
Usage
Disclaimer: The connection object is functional but in the early stages of development. It is not thoroughly tested, and its interfaces may change in future updates.
Actions - managing the connection
Actions allow you to manage the state of the connection object. You can connect to or disconnect from Archicad instances, quit instances, or refresh ports. All actions can have multiple types of inputs. For each type of input you have to call the corresponding method of the action. To connect to all available ArchiCAD instances, you have to call the .all() method on .connect ( e.g. conn.connect.all()). The aim of this method is to provide better autocompletion.
Example: Connection Management
from multiconn_archicad import MultiConn, Port
conn = MultiConn()
# connect all ArchiCAD instances that were running at instantiation / the last refresh
conn.connect.all()
# disconnect from the instance at port 19723
conn.disconnect.from_ports(Port(19723))
# refresh all closed ports - ports with no running archicad instance
conn.refresh.closed_ports()
# close, and remove from the dict of open port headers the archicad instance specified by ConnHeader
conn.quit.from_headers(conn.open_port_headers[Port(19735)])
Project Management
The MultiConn object provides actions to find and open ArchiCAD projects programmatically.
Finding ArchiCAD Instances
You can use the find_archicad action to locate a specific ArchiCAD instance from a ConnHeader.
from multiconn_archicad import MultiConn, ConnHeader
conn = MultiConn()
conn_header = ConnHeader(Port(19723))
# Find the port for a specific connection header
port = conn.find_archicad.from_header(conn_header)
if port:
print(f"Found ArchiCAD instance at port: {port}")
Opening Projects
The open_project action allows you to programmatically open ArchiCAD projects.
from multiconn_archicad import MultiConn, ConnHeader, TeamworkCredentials
conn = MultiConn()
# Open a project using a connection header
conn_header = ConnHeader.from_dict(saved_header_data)
port = conn.open_project.from_header(conn_header)
# For teamwork projects, you can provide credentials
credentials = TeamworkCredentials("username", "password")
port = conn.open_project.with_teamwork_credentials(conn_header, credentials)
Dialog Handling
MultiConn can automatically handle most dialog windows that appear when opening ArchiCAD projects. This is particularly useful for batch operations and automation scripts.
from multiconn_archicad import MultiConn, WinDialogHandler, win_int_handler_factory
# Create a MultiConn instance with a dialog handler
conn = MultiConn(dialog_handler=WinDialogHandler(win_int_handler_factory))
# Dialog windows will be automatically handled when opening projects
conn.open_project.from_header(conn_header)
The current implementation includes:
EmptyDialogHandler: Does nothing (default)WinDialogHandler: Waits for ArchiCAD to start, and monitors appearing dialogs. If dialog appears, searches for appropriate handler in win_int_handler factory. Only works on windows.win_int_handler_factory: Provides dialog handleing logic on a dialog by dialog basis for the INT language version. It is an example you should customize for your specific project needs. Even if you end up not modifying it, you should definitely know what it does for what dialog.
Serialization
The MultiConn package allows you to save and load connection configurations, making it easier to work with specific projects across multiple sessions.
Saving Connection Headers
from multiconn_archicad import MultiConn, Port
conn = MultiConn()
conn.connect.all()
# Get a connection header
conn_header = conn.open_port_headers[Port(19723)]
# Convert to dictionary for serialization
header_dict = conn_header.to_dict()
# Save to file using your preferred method
import json
with open('conn_header.json', 'w') as f:
json.dump(header_dict, f)
Loading Connection Headers
from multiconn_archicad import ConnHeader, TeamworkCredentials
# Load from file
import json
with open('conn_header.json', 'r') as f:
header_dict = json.load(f)
# Create a header from the dictionary
conn_header = ConnHeader.from_dict(header_dict)
# For teamwork projects, you need to provide credentials
if isinstance(conn_header.archicad_id, TeamworkProjectID):
credentials = TeamworkCredentials("username", "password")
# Use the credentials when opening the project
port = conn.open_project.with_teamwork_credentials(conn_header, credentials)
Note: Passwords are not stored in serialized connection headers for security reasons. You must provide them when loading teamwork projects.
Running Commands
Single Archicad Instance
To run commands on one chosen ArchiCAD instance the MultiConn object has a connection called primary. Calling a command directly from the MultiConn object will send it to the primary instance. The primary connection can be changed by assigning any valid Port, or ConnHeader object to MultiConn.primary.
Example: Running Commands on a Single Archicad Instance
from multiconn_archicad import MultiConn, Port
# After instantiation the primary connection will be the instance with the lowest port number (probably 19723)
conn = MultiConn()
# Set the primary connection to the instance running on port 19725
conn.primary = Port(19725)
# Prints project info from the instance on port 19725
print(conn.core.post_tapir_command("GetProjectInfo"))
Multiple Archicad Instances
The MultiConn object stores references to ConnHeaders for all open ports (ports, with a running ArchiCAD instance). The references are stored in a dictionary at .open_port_headers. This dictionary maps each port to its corresponding connection. Each ConnHeader object has its own command objects for each used command namespace. The MultiConn objects has properties to access 3 subsets of open ports based on the status of the ConnHeaders:
active: Successfully connected instances.failed: Instances where the connection attempt failed.pending: Instances with no connection attempt made or disconnected.
Example: Running Commands on Multiple Archicad Instances
from multiconn_archicad import MultiConn
conn = MultiConn()
conn.connect.all()
# Explicit loop to gather elements from all active connections
elements = {}
for port, conn_header in conn.active.items():
elements[port] = conn_header.standard.commands.GetAllElements()
# Using dictionary comprehension
elements = {
port: conn_header.standard.commands.GetAllElements()
for port, conn_header in conn.active.items()
}
Namespaces
The aim of the module is to incorporate all solutions that let users automate ArchiCAD from python. The different solutions are separated into namespaces, accessed from properties of the connection object. One of the planned features is letting users supply a list of namespaces they want to use when creating the connections. At the moment there are only two namespaces:
standard: The official ArchiCAD python wrappercore: A simple JSON based module that lets the users post official and tapir commands based on Tapir's "aclib"
Example: Using two namespaces together
def run(conn: MultiConn | ConnHeader) -> dict[str, Any]:
elements = conn.standard.commands.GetAllElements()
command_parameters = {
"elements": [element.to_dict() for element in elements],
"highlightedColors": [[50, 255, 100, 100] for _ in range(len(elements))],
"wireframe3D": True,
"nonHighlightedColor": [0, 0, 255, 128],
}
return conn.core.post_tapir_command('HighlightElements', command_parameters)
Contributing
Contributions are welcome! Feel free to submit issues, feature requests, or pull requests to help improve MultiConn ArchiCAD.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file multiconn_archicad-0.2.0.tar.gz.
File metadata
- Download URL: multiconn_archicad-0.2.0.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ac24d3963b61c8f6d37044cca6cc2963e70f22aeb110ce1ff9a3508d68d80d6
|
|
| MD5 |
8dd62a43853da9c5708d369782d68f68
|
|
| BLAKE2b-256 |
8c388fcfbb954ad7331914a998c8394d9ca810c3518eb3e67202a2645f0b2250
|
File details
Details for the file multiconn_archicad-0.2.0-py3-none-any.whl.
File metadata
- Download URL: multiconn_archicad-0.2.0-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17c36e9f42f33370bdff0eaf111955d9e154583ebc7a4c765940deabd1e3cc33
|
|
| MD5 |
32fa56144261500fde9945013a72fa11
|
|
| BLAKE2b-256 |
91efb1e8ee51be027452e93fbe468643fcb8e56072dd30b1d9726f0db0bacbf9
|