Import Script Example (Cintoo Connect CLI)

Modified on Tue, 4 Feb at 1:50 PM

This article contains an example of a Python script with comments that allows to leverage the Cintoo Connect CLI functionality to import terrestrial scan data.


An example of a script is provided in the attachment.


This script is an example for how to automate a scan's import to a specific work zone. It doesn't need an URI, but some IDs need to be specified. It calls the import-static command in the function "import_file", open to any modifications if needed.


Below please find the script with comments on each part.

from pathlib import Path
from typing import Final

import json
import logging
import os
import sys
import subprocess
import requests

TIMEOUT: Final[int] = 10

TOKEN: Final[str] = ""
GLOBAL_HEADERS: Final[dict] = {"Authorization": f"Bearer {TOKEN}"}

Import of libraries. Obtaining token and headers. For more details: Cintoo Connect CLI API guidance.



<WORKZONE_ID>/data
ACCOUNT_ID: Final[str] = ""
PROJECT_ID: Final[str] = ""
WORKZONE_ID: Final[str] = ""
  • Account ID for the account hosting the project targeted
  • Project ID corresponding to the target project with the targeted work zone is 
  • Work zone ID corresponding to the target work zone

They could be retrieved with HTTPS requests or from WebApplication URL inside a work zone.

https://aec.cintoo.com/accounts/<ACCOUNT_ID>/projects/<PROJECT_ID>/workzones/

More detailed guidance: Cintoo Connect CLI API guidance.



DEFAULT_URL: Final[str] = "https://aec.cintoo.com"

Default URL could be either aec.cintoo.com or us.cintoo.com or <company>.cintoo.com if organization has a dedicated domain depending on configuration. 



def get_cintoo_cli_exe() -> str:
    path = Path(os.environ['LOCALAPPDATA']) / "Programs" / "Cintoo"
    if not path.exists():
        path = Path(os.environ['ProgramFiles']) / "Cintoo"
    if not path.exists():
        raise RuntimeError("Could not find Cintoo Connect's installation."
                           "\nIf you did not installed it in the default path,"
                           " please set this path variable to the right path")
    cli = path / "cintooconnect-cli.exe"
    if not cli.exists():
        raise RuntimeError("Could not find cintooconnect-cli.exe."
                           " Please install the latest version of Cintoo Connect: "
                           "https://aec.cintoo.com/download/cintooconnect-setup-latest.exe")
    return cli.as_posix()


CINTOO_CLI_EXE: Final[str] = get_cintoo_cli_exe()

Finding and executing the Cintoo Connect CLI executable. Executable is located in the same place where CintooConnect is installed. By default it should be in:

  • Users/"YourUserName"/AppData/Local /Programs/Cintoo
  • ProgramFiles/Cintoo if installed with admin rights



def post_and_check_request(url: str,
                           headers: dict) -> dict:
    logging.info(f"Query: url={url}, headers={headers}")
    try:
        reply = requests.post(url, headers=headers, timeout=TIMEOUT)
        reply.raise_for_status()
        return reply.json()
    except json.JSONDecodeError as exception:
        message = f"Exception during decoding json when using token: {exception}"
    except requests.exceptions.RequestException as exception:
        message = f"Exception during validation of token: {exception}"
    except Exception as exception:
        message = f"Exception: {exception}"
    logging.error(message)
    raise RuntimeError(message)

Sending information to a server and getting a verification of the server response.



def validate_login():
    url = f"{DEFAULT_URL}/api/isLogged"
    response = post_and_check_request(url, GLOBAL_HEADERS)
    if not response.get("success"):
        raise ValueError("Login required: unable to verify your login status.\n"
                         f"Details: {response}.\n"
                         "Please log in by following the instructions here:\n"
                         "https://aec.cintoo.com/api/#section/API-Specification/Authentication")

Login validation.



def get_cintoo_uri(account_id: str,
                   project_id: str,
                   workzone_id: str):
    url = 
'{DEFAULT_URL}/api/accounts/{account_id}/projects/{project_id}/workzones/{workzone_id}/imports'
    response = post_and_check_request(url, GLOBAL_HEADERS)
    cintoo_uri = response.get("url")
    if not cintoo_uri:
        raise KeyError(f"Could not find url in response: {response}")
    return cintoo_uri

Getting the Cintoo URI out of account, project and workzone components defined earlier.



def import_file(cintoo_uri: str,
                file_path: str):
    return subprocess.call([CINTOO_CLI_EXE, "import-static",
                            f"--cintoo-uri={cintoo_uri}",
                            f"--file-ref={file_path}"])

Execution of the import process with the Cintoo Connect CLI executable.



def import_files_in_dir(cintoo_uri: str,
                        root_dir_path: str):
    for (dirpath, _, filenames) in os.walk(root_dir_path):
        for filename in filenames:
            file_path = os.path.join(dirpath, filename)
            import_file(cintoo_uri, file_path)

Importing all the files in the defined directory.



def main(path: str):
    assert TOKEN, "Token must be specified"
    assert ACCOUNT_ID and PROJECT_ID and WORKZONE_ID, "IDs must be specified"
    validate_login()
    cintoo_uri = get_cintoo_uri(ACCOUNT_ID, PROJECT_ID, WORKZONE_ID)
    if os.path.isfile(path):
        import_file(cintoo_uri, path)
    elif os.path.isdir(path):
        import_files_in_dir(cintoo_uri, path)

if __name__ == "__main__":
    arguments = sys.argv
    if len(arguments) != 2:
        raise RuntimeError("You need to pass the path to directory or file to import")
    main(arguments[1])

Execution of the main function.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article