Files
IfcOpenShell/src/ifcquery/tests/test_materials.py
T
Bruno Postle 7cd40bf8cb Add ifcquery CLI tool for IFC model interrogation (#7845)
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.
2026-03-23 23:29:32 +00:00

53 lines
2.2 KiB
Python

import ifcopenshell.api.material
import ifcopenshell.api.project
from ifcquery.materials import materials
class TestMaterials:
def test_empty_model(self, model):
result = materials(model)
assert isinstance(result, list)
assert len(result) == 0
def test_single_material(self, model):
ifcopenshell.api.material.add_material(model, name="Concrete", category="concrete")
result = materials(model)
assert len(result) == 1
m = result[0]
assert m["type"] == "IfcMaterial"
assert m["name"] == "Concrete"
assert m["category"] == "concrete"
assert isinstance(m["id"], int)
def test_material_layer_set(self, model):
mat = ifcopenshell.api.material.add_material(model, name="Brick")
layer_set = ifcopenshell.api.material.add_material_set(model, name="BrickSet", set_type="IfcMaterialLayerSet")
ifcopenshell.api.material.add_layer(model, layer_set=layer_set, material=mat)
result = materials(model)
layer_sets = [e for e in result if e["type"] == "IfcMaterialLayerSet"]
assert len(layer_sets) == 1
ls = layer_sets[0]
assert ls["name"] == "BrickSet"
assert isinstance(ls["layers"], list)
assert len(ls["layers"]) == 1
layer = ls["layers"][0]
assert layer["material"] == "Brick"
def test_material_constituent_set(self, model):
mat = ifcopenshell.api.material.add_material(model, name="Steel")
cs = ifcopenshell.api.material.add_material_set(model, name="CompSet", set_type="IfcMaterialConstituentSet")
ifcopenshell.api.material.add_constituent(model, constituent_set=cs, material=mat)
result = materials(model)
constituent_sets = [e for e in result if e["type"] == "IfcMaterialConstituentSet"]
assert len(constituent_sets) == 1
entry = constituent_sets[0]
assert entry["name"] == "CompSet"
assert isinstance(entry["constituents"], list)
def test_ids_are_integers(self, model):
ifcopenshell.api.material.add_material(model, name="Wood")
result = materials(model)
for entry in result:
assert isinstance(entry["id"], int)