この記事には、Cintoo Connect CLIの機能を活用して地上スキャンデータをインポートすることを可能にする、コメント付きPythonスクリプトの例が含まれています。
スクリプトの例は添付ファイルにあります。
このスクリプトは、特定の作業エリアへのスキャンのインポートを自動化する方法の例です。 URIは必要ありませんが、いくつかのIDを指定する必要があります。
必要に応じて任意の修正を加えることができる関数 "import_file" の中でimport-static コマンドを呼び出します。
以下に、各部分へのコメント付きのスクリプトを示します。
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}"}ライブラリのインポート。 トークンとヘッダーの取得。 詳細はこちら:Cintoo Connect CLI API のガイダンス。
<WORKZONE_ID>/data
ACCOUNT_ID: Final[str] = ""
PROJECT_ID: Final[str] = ""
WORKZONE_ID: Final[str] = ""- ターゲットプロジェクトをホストするアカウントのアカウントID
- ターゲットプロジェクトに対応するプロジェクトID
- ターゲット作業エリアに対応する作業エリアID
HTTPSリクエストまたは作業エリア内のWebアプリケーションURLから取得できます。
https://aec.cintoo.com/accounts/<ACCOUNT_ID>/projects/<PROJECT_ID>/workzones/
詳細なガイダンス:Cintoo Connect CLI API のガイダンス。
DEFAULT_URL: Final[str] = "https://aec.cintoo.com"デフォルトのURLは、組織が構成に応じて専用ドメインを持つ場合はaec.cintoo.comやus.cintoo.comまたは[company].cintoo.comになることがあります。
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("Cintoo Connectのインストールが見つかりませんでした。"
"\nデフォルトパスにインストールされていない場合は、"
" このパス変数を正しいパスに設定してください")
cli = path / "cintooconnect-cli.exe"
if not cli.exists():
raise RuntimeError("cintooconnect-cli.exeが見つかりませんでした。"
" Cintoo Connectの最新バージョンをインストールしてください: "
"https://aec.cintoo.com/download/cintooconnect-setup-latest.exe")
return cli.as_posix()
CINTOO_CLI_EXE: Final[str] = get_cintoo_cli_exe()Cintoo Connect CLIの実行ファイルを探して実行しています。 実行ファイルはCintoo Connectがインストールされている場所にあります。 デフォルトでは、次にあります:
- Users/"ユーザー名"/AppData/Local /Programs/Cintoo
- 管理者権限でインストールされた場合はProgramFiles/Cintoo
def post_and_check_request(url: str,
headers: dict) -> dict:
logging.info(f"クエリ: 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"トークンを使用した際のjsonデコード中の例外: {exception}"
except requests.exceptions.RequestException as exception:
message = f"トークンの検証中の例外: {exception}"
except Exception as exception:
message = f"例外: {exception}"
logging.error(message)
raise RuntimeError(message)サーバーへの情報送信とサーバーの応答の検証を行います。
def validate_login():
url = f"{DEFAULT_URL}/api/isLogged"
response = post_and_check_request(url, GLOBAL_HEADERS)
if not response.get("success"):
raise ValueError("ログインが必要です: ログイン状態を確認できません。\n"
f"詳細: {response}.\n"
"ログインするには、ここにある指示に従ってください:\n"
"https://aec.cintoo.com/api/#section/API-Specification/Authentication")ログインの検証。
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"レスポンスにURLが見つかりませんでした: {response}")
return cintoo_uri先に定義したアカウント、プロジェクト、作業エリアのコンポーネントからCintoo URIを取得しています。
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}"])Cintoo Connect CLI実行ファイルによるインポートプロセスの実行。
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)定義されたディレクトリ内のすべてのファイルをインポートします。
def main(path: str):
assert TOKEN, "トークンを指定する必要があります。"
assert ACCOUNT_ID and PROJECT_ID and WORKZONE_ID, "IDを指定する必要があります。"
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("インポートするディレクトリまたはファイルへのパスを渡す必要があります。")
main(arguments[1])メイン関数の実行。
この記事は役に立ちましたか?
それは素晴らしい!
フィードバックありがとうございます
お役に立てず申し訳ございません!
フィードバックありがとうございます
フィードバックを送信しました
記事の改善におけるご協力ありがとうございます。