### Archicad JSON Interface - Basic Connection and Command Source: https://archicadapi.graphisoft.com/JSONInterfaceDocumentation/index.html This section outlines the basic connection parameters and provides an example of sending a simple command ('API.IsAlive') to Archicad using Python. ```APIDOC ## Archicad JSON Interface - Basic Connection and Command ### Description This endpoint allows external applications to communicate with Archicad using JSON messages over HTTP. It details the host, port, method, and expected body format for sending commands. ### Method POST ### Endpoint `http://localhost:` (where is between 19723 and 19743) ### Parameters #### Request Body - **command** (string) - Required - The command to be sent to Archicad, encoded as a UTF-8 JSON string. ### Request Example ```json { "command": "API.IsAlive" } ``` ### Response #### Success Response (200) - **result** (object) - The response from Archicad indicating the status of the command. #### Response Example ```json { "result": true } ``` ``` -------------------------------- ### Get Element IDs and Property Values using Archicad Python Package (Python) Source: https://archicadapi.graphisoft.com/JSONInterfaceDocumentation/index.html This Python script utilizes the official 'archicad' package to connect to Archicad, retrieve all element IDs, and fetch specific property values (General_ElementID) for these elements. It showcases how to interact with Archicad's API for element data retrieval. ```python from archicad import ACConnection conn = ACConnection.connect() assert conn acc = conn.commands act = conn.types elementIdBuiltInPropertyUserId = act.BuiltInPropertyUserId('General_ElementID') elementIdPropertyId = acc.GetPropertyIds([elementIdBuiltInPropertyUserId])[0].propertyId elementIds = acc.GetAllElements() propertyValuesForElements = acc.GetPropertyValuesOfElements(elementIds, [elementIdPropertyId]) elementIdPropertyValues = set() for propertyValuesForElement in propertyValuesForElements: elementIdPropertyValue = propertyValuesForElement.propertyValues[0].propertyValue.value if elementIdPropertyValue in elementIdPropertyValues: print(f"Conflict: multiple elements have '{elementIdPropertyValue}' as element ID.") elementIdPropertyValues.add(elementIdPropertyValue) ``` -------------------------------- ### Connect to Archicad and Check Connection Status (Python) Source: https://archicadapi.graphisoft.com/JSONInterfaceDocumentation/index.html This Python script demonstrates how to establish a connection to Archicad using the basic HTTP JSON interface and send a command to check if the connection is alive. It uses the `urllib.request` library for HTTP communication and the `json` library for data serialization/deserialization. ```python import json import urllib.request as rq request = rq.Request ('http://localhost:19723') response = rq.urlopen (request, json.dumps ({ "command" : "API.IsAlive" }).encode ("UTF-8")) result = json.loads (response.read ()) print (result) ``` -------------------------------- ### Archicad JSON Interface - Using Official Python Binding Source: https://archicadapi.graphisoft.com/JSONInterfaceDocumentation/index.html Demonstrates how to use the official Archicad Python package to connect to Archicad and retrieve property values of elements, such as the General Element ID. ```APIDOC ## Archicad JSON Interface - Using Official Python Binding ### Description This example showcases the usage of the official `archicad` Python package for seamless interaction with the Archicad JSON Interface. It covers connecting to Archicad, retrieving element IDs, and fetching their property values. ### Method POST (handled by the `archicad` library) ### Endpoint (Managed by the `archicad` library's connection mechanism) ### Parameters (Managed by the `archicad` library's functions) ### Request Example ```python from archicad import ACConnection conn = ACConnection.connect() assert conn acc = conn.commands act = conn.types elementIdBuiltInPropertyUserId = act.BuiltInPropertyUserId('General_ElementID') elementIdPropertyId = acc.GetPropertyIds([elementIdBuiltInPropertyUserId])[0].propertyId elementIds = acc.GetAllElements() propertyValuesForElements = acc.GetPropertyValuesOfElements(elementIds, [elementIdPropertyId]) elementIdPropertyValues = set() for propertyValuesForElement in propertyValuesForElements: elementIdPropertyValue = propertyValuesForElement.propertyValues[0].propertyValue.value if elementIdPropertyValue in elementIdPropertyValues: print(f"Conflict: multiple elements have '{elementIdPropertyValue}' as element ID.") elementIdPropertyValues.add(elementIdPropertyValue) ``` ### Response #### Success Response (The script prints information about element IDs and potential conflicts.) #### Response Example (Output will vary based on the Archicad project. Example: `Conflict: multiple elements have '123' as element ID.` or no output if no conflicts.) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.