mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 10:06:47 +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.
98 lines
3.5 KiB
Python
98 lines
3.5 KiB
Python
# This file was generated with the assistance of an AI coding tool.
|
|
import ifcopenshell
|
|
import ifcopenshell.api.project
|
|
import ifcopenshell.api.pset
|
|
import ifcopenshell.api.root
|
|
|
|
from ifcedit.run import run_api, serialize_result
|
|
|
|
|
|
class TestRunApi:
|
|
def test_create_entity(self, model):
|
|
result = run_api(model, "root", "create_entity", {"ifc_class": "IfcWall", "name": "NewWall"})
|
|
assert result["ok"] is True
|
|
assert result["result"]["type"] == "IfcWall"
|
|
assert result["result"]["name"] == "NewWall"
|
|
assert isinstance(result["result"]["id"], int)
|
|
|
|
def test_create_entity_default_class(self, model):
|
|
result = run_api(model, "root", "create_entity", {})
|
|
assert result["ok"] is True
|
|
assert result["result"]["type"] == "IfcBuildingElementProxy"
|
|
|
|
def test_assign_container(self, model):
|
|
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall", name="TestWall2")
|
|
storey = model.by_type("IfcBuildingStorey")[0]
|
|
result = run_api(
|
|
model,
|
|
"spatial",
|
|
"assign_container",
|
|
{"products": str(wall.id()), "relating_structure": str(storey.id())},
|
|
)
|
|
assert result["ok"] is True
|
|
assert result["result"]["type"] == "IfcRelContainedInSpatialStructure"
|
|
|
|
def test_add_pset(self, model):
|
|
wall = model.by_type("IfcWall")[0]
|
|
result = run_api(model, "pset", "add_pset", {"product": str(wall.id()), "name": "Pset_WallCommon"})
|
|
assert result["ok"] is True
|
|
assert result["result"]["type"] == "IfcPropertySet"
|
|
|
|
def test_unknown_function(self, model):
|
|
result = run_api(model, "root", "nonexistent", {})
|
|
assert result["ok"] is False
|
|
assert "Cannot find" in result["error"]
|
|
|
|
def test_unknown_parameter(self, model):
|
|
result = run_api(model, "root", "create_entity", {"bogus_param": "value"})
|
|
assert result["ok"] is False
|
|
assert "Unknown parameter" in result["error"]
|
|
|
|
def test_bad_entity_reference(self, model):
|
|
result = run_api(model, "pset", "add_pset", {"product": "999999", "name": "Pset_WallCommon"})
|
|
assert result["ok"] is False
|
|
assert "not found" in result["error"]
|
|
|
|
|
|
class TestAppendAsset:
|
|
def test_append_asset_from_library(self, model, library_file):
|
|
lib = ifcopenshell.open(library_file)
|
|
wall_type = lib.by_type("IfcWallType")[0]
|
|
result = run_api(
|
|
model,
|
|
"project",
|
|
"append_asset",
|
|
{"library": library_file, "element": str(wall_type.id())},
|
|
)
|
|
assert result["ok"] is True
|
|
assert result["result"]["type"] == "IfcWallType"
|
|
assert model.by_type("IfcWallType"), "wall type should have been appended to the model"
|
|
|
|
|
|
class TestSerializeResult:
|
|
def test_none(self):
|
|
assert serialize_result(None) is None
|
|
|
|
def test_string(self):
|
|
assert serialize_result("hello") == "hello"
|
|
|
|
def test_int(self):
|
|
assert serialize_result(42) == 42
|
|
|
|
def test_entity(self, model):
|
|
wall = model.by_type("IfcWall")[0]
|
|
result = serialize_result(wall)
|
|
assert result["id"] == wall.id()
|
|
assert result["type"] == "IfcWall"
|
|
assert result["name"] == "Wall001"
|
|
|
|
def test_list(self, model):
|
|
walls = model.by_type("IfcWall")
|
|
result = serialize_result(walls)
|
|
assert isinstance(result, list)
|
|
assert all(isinstance(r, dict) for r in result)
|
|
|
|
def test_dict(self):
|
|
result = serialize_result({"key": "value"})
|
|
assert result == {"key": "value"}
|