mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-16 10:34:31 +00:00
6bf4259298
ifcedit is a new command-line tool for executing ifcopenshell.api mutations from the shell. It wraps the entire API surface — any function callable via ifcopenshell.api can be invoked without writing Python.
Subcommands:
list [module] — list all API modules, or functions within a module
docs <module.function> — full documentation (params, types, descriptions)
run <file> <module.function> [--param value ...] — execute a mutation; overwrites input file by default, or use -o <output> to write elsewhere; --dry-run validates without executing
quantify list — list available QTO rules
quantify run <file> <rule> — run quantity take-off, writing IfcElementQuantity psets back to the file
Parameter coercion: entity references can be passed as step IDs (strings); lists, dicts, booleans, and None are handled automatically.
Usage:
python3 -m ifcedit run model.ifc root.remove_product --product 42
python3 -m ifcedit docs geometry.edit_object_placement
Generated with the assistance of an AI coding tool.
101 lines
3.3 KiB
Python
101 lines
3.3 KiB
Python
# This file was generated with the assistance of an AI coding tool.
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
|
|
def run_ifcedit(*args):
|
|
"""Run ifcedit as a subprocess and return (stdout, stderr, returncode)."""
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "ifcedit", *args],
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
return result.stdout, result.stderr, result.returncode
|
|
|
|
|
|
class TestListCommand:
|
|
def test_list_all_modules(self):
|
|
stdout, stderr, rc = run_ifcedit("list")
|
|
assert rc == 0
|
|
data = json.loads(stdout)
|
|
assert isinstance(data, list)
|
|
module_names = [m["module"] for m in data]
|
|
assert "root" in module_names
|
|
assert "spatial" in module_names
|
|
|
|
def test_list_module_functions(self):
|
|
stdout, stderr, rc = run_ifcedit("list", "root")
|
|
assert rc == 0
|
|
data = json.loads(stdout)
|
|
assert isinstance(data, list)
|
|
names = [f["name"] for f in data]
|
|
assert "create_entity" in names
|
|
|
|
def test_list_text_format(self):
|
|
stdout, stderr, rc = run_ifcedit("--format", "text", "list")
|
|
assert rc == 0
|
|
assert "root" in stdout
|
|
|
|
|
|
class TestDocsCommand:
|
|
def test_docs_create_entity(self):
|
|
stdout, stderr, rc = run_ifcedit("docs", "root.create_entity")
|
|
assert rc == 0
|
|
data = json.loads(stdout)
|
|
assert data["module"] == "root"
|
|
assert data["function"] == "create_entity"
|
|
assert "params" in data
|
|
|
|
def test_docs_invalid_path(self):
|
|
stdout, stderr, rc = run_ifcedit("docs", "invalid_path")
|
|
assert rc != 0
|
|
assert "module.function" in stderr
|
|
|
|
def test_docs_unknown_function(self):
|
|
stdout, stderr, rc = run_ifcedit("docs", "root.nonexistent")
|
|
assert rc != 0
|
|
|
|
|
|
class TestRunCommand:
|
|
def test_create_entity(self, model_file):
|
|
stdout, stderr, rc = run_ifcedit(
|
|
"run", model_file, "root.create_entity", "--ifc_class", "IfcWall", "--name", "CLIWall"
|
|
)
|
|
assert rc == 0, f"stderr: {stderr}"
|
|
data = json.loads(stdout)
|
|
assert data["ok"] is True
|
|
assert data["result"]["type"] == "IfcWall"
|
|
assert data["result"]["name"] == "CLIWall"
|
|
|
|
def test_dry_run(self, model_file):
|
|
stdout, stderr, rc = run_ifcedit("run", model_file, "root.create_entity", "--dry-run", "--ifc_class", "IfcWall")
|
|
assert rc == 0
|
|
data = json.loads(stdout)
|
|
assert data["ok"] is True
|
|
assert data["dry_run"] is True
|
|
|
|
def test_output_to_different_file(self, model_file, tmp_path):
|
|
output = str(tmp_path / "output.ifc")
|
|
stdout, stderr, rc = run_ifcedit(
|
|
"run", model_file, "root.create_entity", "-o", output, "--ifc_class", "IfcSlab"
|
|
)
|
|
assert rc == 0, f"stderr: {stderr}"
|
|
data = json.loads(stdout)
|
|
assert data["ok"] is True
|
|
|
|
import os
|
|
|
|
assert os.path.exists(output)
|
|
|
|
def test_run_error_bad_function(self, model_file):
|
|
stdout, stderr, rc = run_ifcedit("run", model_file, "root.nonexistent")
|
|
assert rc != 0
|
|
|
|
def test_run_invalid_function_path(self, model_file):
|
|
stdout, stderr, rc = run_ifcedit("run", model_file, "invalid_path")
|
|
assert rc != 0
|
|
assert "module.function" in stderr
|