mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-14 03:14:23 +00:00
7cd40bf8cb
ifcquery is a new command-line tool for querying and inspecting IFC models. All output is JSON.
Subcommands:
summary — schema version, entity counts, project metadata
tree — full spatial hierarchy (Project → Site → Building → Storeys → Spaces → Elements)
info <id> — deep inspection of any entity by step ID (attributes, psets, placement matrix, type, material)
select <query> — filter elements using ifcopenshell selector syntax
relations <id> — relationships for an element; --traverse up walks to IfcProject
clash <id> — geometric intersection and clearance detection
validate — schema/constraint validation; --rules adds EXPRESS checks
schedule — work schedules with nested task trees
cost — cost schedules with nested cost item trees
schema <class> — IFC class documentation from the model's schema version
plot — SVG plan drawing
render — 3D geometry rendering
contexts — geometric representation contexts
materials — material assignments
Usage:
python3 -m ifcquery <file.ifc> <subcommand> [args]
Generated with the assistance of an AI coding tool.
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
import ifcopenshell.api.context
|
|
import ifcopenshell.api.project
|
|
import ifcopenshell.api.root
|
|
import ifcopenshell.api.unit
|
|
|
|
from ifcquery.contexts import contexts
|
|
|
|
|
|
class TestContexts:
|
|
def test_empty_model(self):
|
|
f = ifcopenshell.api.project.create_file()
|
|
result = contexts(f)
|
|
assert isinstance(result, list)
|
|
assert len(result) == 0
|
|
|
|
def test_model_context(self, model):
|
|
import ifcopenshell.api.context
|
|
|
|
ifcopenshell.api.context.add_context(model, context_type="Model")
|
|
result = contexts(model)
|
|
assert len(result) == 1
|
|
entry = result[0]
|
|
assert entry["type"] == "IfcGeometricRepresentationContext"
|
|
assert entry["context_type"] == "Model"
|
|
assert "id" in entry
|
|
assert "context_identifier" in entry
|
|
|
|
def test_subcontext(self, model):
|
|
import ifcopenshell.api.context
|
|
|
|
model_ctx = ifcopenshell.api.context.add_context(model, context_type="Model")
|
|
ifcopenshell.api.context.add_context(
|
|
model,
|
|
context_type="Model",
|
|
context_identifier="Body",
|
|
target_view="MODEL_VIEW",
|
|
parent=model_ctx,
|
|
)
|
|
result = contexts(model)
|
|
assert len(result) == 2
|
|
subctx = next(e for e in result if e["type"] == "IfcGeometricRepresentationSubContext")
|
|
assert subctx["context_identifier"] == "Body"
|
|
assert subctx["target_view"] == "MODEL_VIEW"
|
|
assert subctx["parent_context_id"] == model_ctx.id()
|
|
|
|
def test_ids_are_integers(self, model):
|
|
import ifcopenshell.api.context
|
|
|
|
ifcopenshell.api.context.add_context(model, context_type="Model")
|
|
result = contexts(model)
|
|
for entry in result:
|
|
assert isinstance(entry["id"], int)
|