replace api.run with static methods

This commit is contained in:
Andrej
2025-06-09 10:59:22 +05:00
parent 02d359d0e6
commit 8b4683aef1
122 changed files with 1334 additions and 1370 deletions
+3 -2
View File
@@ -18,10 +18,11 @@
import bpy
import ifcopenshell
import ifcopenshell.api.context
import ifcopenshell.api.geometry
import ifcopenshell.api.root
import ifcopenshell.api.spatial
import ifcopenshell.api.unit
import ifcopenshell.api.context
import ifcopenshell.util.shape_builder
import bonsai.core.tool
import bonsai.tool as tool
@@ -140,5 +141,5 @@ class TestGetContainer(NewFile):
tool.Ifc.set(ifc)
element = ifc.createIfcWall()
container = ifc.createIfcBuildingStorey()
ifcopenshell.api.run("spatial.assign_container", ifc, products=[element], relating_structure=container)
ifcopenshell.api.spatial.assign_container(ifc, products=[element], relating_structure=container)
assert subject.get_container(element) == container
+7 -5
View File
@@ -23,6 +23,8 @@ import brickschema.persistent
from brickschema.namespaces import REF, A
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.aggregate
import ifcopenshell.api.root
import ifcopenshell.guid
import bonsai.core.tool
import bonsai.tool as tool
@@ -325,11 +327,11 @@ class TestGetConvertableBrickSystems(NewFile):
class TestGetParentSpace(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcBuildingStorey")
subelement = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcSpace")
project = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[subelement], relating_object=element)
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[element], relating_object=project)
element = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcBuildingStorey")
subelement = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcSpace")
project = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.aggregate.assign_object(ifc, products=[subelement], relating_object=element)
ifcopenshell.api.aggregate.assign_object(ifc, products=[element], relating_object=project)
assert subject.get_parent_space(subelement) == element
assert subject.get_parent_space(element) is None
+6 -5
View File
@@ -19,6 +19,7 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.document
import bonsai.core.tool
import bonsai.tool as tool
from test.bim.bootstrap import NewFile
@@ -170,7 +171,7 @@ class TestImportProjectDocuments(NewFile):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
ifc.createIfcProject()
document = ifcopenshell.api.run("document.add_information", ifc)
document = ifcopenshell.api.document.add_information(ifc)
subject.import_project_documents()
props = tool.Document.get_document_props()
assert len(props.documents) == 1
@@ -185,8 +186,8 @@ class TestImportReferences(NewFile):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
ifc.createIfcProject()
document = ifcopenshell.api.run("document.add_information", ifc)
reference = ifcopenshell.api.run("document.add_reference", ifc, information=document)
document = ifcopenshell.api.document.add_information(ifc)
reference = ifcopenshell.api.document.add_reference(ifc, information=document)
subject.import_references(document)
props = tool.Document.get_document_props()
assert len(props.documents) == 1
@@ -201,8 +202,8 @@ class TestImportSubdocuments(NewFile):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
ifc.createIfcProject()
document = ifcopenshell.api.run("document.add_information", ifc)
subdocument = ifcopenshell.api.run("document.add_information", ifc, parent=document)
document = ifcopenshell.api.document.add_information(ifc)
subdocument = ifcopenshell.api.document.add_information(ifc, parent=document)
subject.import_subdocuments(document)
props = tool.Document.get_document_props()
assert len(props.documents) == 1
+17 -14
View File
@@ -22,6 +22,9 @@ import numpy as np
import bpy
import mathutils
import ifcopenshell
import ifcopenshell.api.drawing
import ifcopenshell.api.group
import ifcopenshell.api.pset
import ifcopenshell.api.root
import ifcopenshell.guid
import ifcopenshell.util.element
@@ -341,9 +344,9 @@ class TestGetDrawingGroup(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcAnnotation()
group = ifcopenshell.api.run("group.add_group", ifc)
group = ifcopenshell.api.group.add_group(ifc)
group.ObjectType = "DRAWING"
ifcopenshell.api.run("group.assign_group", ifc, products=[element], group=group)
ifcopenshell.api.group.assign_group(ifc, products=[element], group=group)
assert subject.get_drawing_group(element) == group
@@ -352,8 +355,8 @@ class TestGetDrawingTargetView(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcAnnotation()
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="EPset_Drawing")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"TargetView": "PLAN_VIEW"})
pset = ifcopenshell.api.pset.add_pset(ifc, product=element, name="EPset_Drawing")
ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"TargetView": "PLAN_VIEW"})
assert subject.get_drawing_target_view(element) == "PLAN_VIEW"
@@ -362,8 +365,8 @@ class TestGetGroupElements(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcAnnotation()
group = ifcopenshell.api.run("group.add_group", ifc)
ifcopenshell.api.run("group.assign_group", ifc, products=[element], group=group)
group = ifcopenshell.api.group.add_group(ifc)
ifcopenshell.api.group.assign_group(ifc, products=[element], group=group)
assert subject.get_group_elements(group) == (element,)
@@ -515,7 +518,7 @@ class TestGetAssignedProduct(NewFile):
tool.Ifc.set(ifc)
wall = ifc.createIfcWall()
label = ifc.createIfcAnnotation()
ifcopenshell.api.run("drawing.assign_product", ifc, relating_product=wall, related_object=label)
ifcopenshell.api.drawing.assign_product(ifc, relating_product=wall, related_object=label)
assert subject.get_assigned_product(label) == wall
@@ -524,8 +527,8 @@ class TestImportDrawings(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
drawing = ifc.createIfcAnnotation(Name="FOOBAR", ObjectType="DRAWING")
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=drawing, name="EPset_Drawing")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"TargetView": "PLAN_VIEW"})
pset = ifcopenshell.api.pset.add_pset(ifc, product=drawing, name="EPset_Drawing")
ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"TargetView": "PLAN_VIEW"})
subject.import_drawings()
props = tool.Drawing.get_document_props()
for d in props.drawings:
@@ -635,7 +638,7 @@ class TestImportAssignedProduct(NewFile):
tool.Ifc.set(ifc)
wall = ifc.createIfcWall()
label = ifc.createIfcAnnotation()
ifcopenshell.api.run("drawing.assign_product", ifc, relating_product=wall, related_object=label)
ifcopenshell.api.drawing.assign_product(ifc, relating_product=wall, related_object=label)
wall_obj = bpy.data.objects.new("Object", None)
label_obj = bpy.data.objects.new("Object", None)
tool.Ifc.link(wall, wall_obj)
@@ -794,7 +797,7 @@ class TestUpdateTextValue(NewFile):
ifc = tool.Ifc.get()
wall = ifc.createIfcWall(Name="Baz")
label = ifc.by_type("IfcAnnotation")[0]
ifcopenshell.api.run("drawing.assign_product", ifc, relating_product=wall, related_object=label)
ifcopenshell.api.drawing.assign_product(ifc, relating_product=wall, related_object=label)
ifc.by_type("IfcTextLiteralWithExtent")[0].Literal = "Foo {{Name}} Bar"
@@ -808,10 +811,10 @@ class TestUpdateTextValue(NewFile):
obj = bpy.data.objects["Object"]
ifc = tool.Ifc.get()
wall = ifc.createIfcWall()
pset = ifcopenshell.api.run("pset.add_pset", ifc, name="Custom_Pset", product=wall)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Key": "Baz"})
pset = ifcopenshell.api.pset.add_pset(ifc, name="Custom_Pset", product=wall)
ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"Key": "Baz"})
label = ifc.by_type("IfcAnnotation")[0]
ifcopenshell.api.run("drawing.assign_product", ifc, relating_product=wall, related_object=label)
ifcopenshell.api.drawing.assign_product(ifc, relating_product=wall, related_object=label)
ifc.by_type("IfcTextLiteralWithExtent")[0].Literal = "Foo {{Custom_Pset.Key}} Bar"
+9 -8
View File
@@ -21,6 +21,7 @@ import math
import numpy as np
import ifcopenshell
import ifcopenshell.api.geometry
import ifcopenshell.api.root
import ifcopenshell.api.type
import bonsai.core.tool
import bonsai.tool as tool
@@ -202,7 +203,7 @@ class TestGetElementType(NewFile):
ifc = tool.Ifc.get()
element = ifc.createIfcWall()
type = ifc.createIfcWallType()
ifcopenshell.api.run("type.assign_type", ifc, related_objects=[element], relating_type=type)
ifcopenshell.api.type.assign_type(ifc, related_objects=[element], relating_type=type)
assert subject.get_element_type(element) == type
@@ -212,7 +213,7 @@ class TestGetElementsOfType(NewFile):
ifc = tool.Ifc.get()
element = ifc.createIfcWall()
type = ifc.createIfcWallType()
ifcopenshell.api.run("type.assign_type", ifc, related_objects=[element], relating_type=type)
ifcopenshell.api.type.assign_type(ifc, related_objects=[element], relating_type=type)
assert subject.get_elements_of_type(type) == (element,)
@@ -328,9 +329,9 @@ class TestRemoveConnection(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
element1 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
element2 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
rel = ifcopenshell.api.run("geometry.connect_path", ifc, relating_element=element1, related_element=element2)
element1 = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
rel = ifcopenshell.api.geometry.connect_path(ifc, relating_element=element1, related_element=element2)
subject.remove_connection(rel)
assert not tool.Ifc.get().by_type("IfcRelConnectsPathElements")
@@ -445,17 +446,17 @@ class TestSelectConnection(NewFile):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
element1 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
element1 = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
obj1 = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj1)
tool.Ifc.link(element1, obj1)
element2 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
element2 = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
obj2 = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj2)
tool.Ifc.link(element2, obj2)
rel = ifcopenshell.api.run("geometry.connect_path", ifc, relating_element=element1, related_element=element2)
rel = ifcopenshell.api.geometry.connect_path(ifc, relating_element=element1, related_element=element2)
subject.select_connection(rel)
assert obj1 in bpy.context.selected_objects
+39 -35
View File
@@ -20,6 +20,10 @@ import bpy
import math
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.context
import ifcopenshell.api.georeference
import ifcopenshell.api.root
import ifcopenshell.api.unit
import bonsai.core.tool
import bonsai.tool as tool
from mathutils import Vector
@@ -36,8 +40,8 @@ class TestImportProjectedCRS(NewFile):
def test_importing_nothing_with_no_georeferencing(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
subject.import_projected_crs()
props = tool.Georeference.get_georeference_props()
assert len(props.projected_crs) == 0
@@ -45,9 +49,9 @@ class TestImportProjectedCRS(NewFile):
def test_importing_projected_crs(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
ifcopenshell.api.georeference.add_georeferencing(ifc)
projected_crs = ifc.by_type("IfcProjectedCRS")[0]
projected_crs.Name = "Name"
projected_crs.Description = "Description"
@@ -55,7 +59,7 @@ class TestImportProjectedCRS(NewFile):
projected_crs.VerticalDatum = "VerticalDatum"
projected_crs.MapProjection = "MapProjection"
projected_crs.MapZone = "MapZone"
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="LENGTHUNIT")
unit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="LENGTHUNIT")
projected_crs.MapUnit = unit
subject.import_projected_crs()
props = tool.Georeference.get_georeference_props()
@@ -79,8 +83,8 @@ class TestImportCoordinateOperation(NewFile):
def test_importing_nothing_with_no_georeferencing(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
subject.import_coordinate_operation()
props = tool.Georeference.get_georeference_props()
assert len(props.coordinate_operation) == 0
@@ -88,9 +92,9 @@ class TestImportCoordinateOperation(NewFile):
def test_importing_coordinate_operation(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
ifcopenshell.api.georeference.add_georeferencing(ifc)
map_conversion = ifc.by_type("IfcMapConversion")[0]
map_conversion.Eastings = 1
map_conversion.Northings = 2
@@ -120,8 +124,8 @@ class TestImportTrueNorth(NewFile):
def test_detecting_no_true_north(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
subject.import_true_north()
props = tool.Georeference.get_georeference_props()
assert props.true_north_abscissa == "0"
@@ -131,8 +135,8 @@ class TestImportTrueNorth(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
context = ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
context = ifcopenshell.api.context.add_context(ifc, context_type="Model")
context.TrueNorth = ifc.createIfcDirection((1.0, 2.0, 0.0))
subject.import_true_north()
props = tool.Georeference.get_georeference_props()
@@ -216,10 +220,10 @@ class TestGetCursorLocation(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
unit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc, units=[unit])
assert bpy.context.scene
bpy.context.scene.cursor.location = (1.0, 2.0, 3.0)
assert subject.get_cursor_location() == [1000.0, 2000.0, 3000.0]
@@ -228,13 +232,13 @@ class TestGetCursorLocation(NewFile):
class TestXyz2Enh(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
tool.Ifc.set(ifc)
assert subject.xyz2enh((0.0, 0.0, 0.0)) == (0.0, 0.0, 0.0)
def test_using_the_blender_offset(self):
ifc = ifcopenshell.file()
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
tool.Ifc.set(ifc)
props = tool.Georeference.get_georeference_props()
props.has_blender_offset = True
@@ -244,9 +248,9 @@ class TestXyz2Enh(NewFile):
def test_using_the_map_conversion(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
ifcopenshell.api.georeference.add_georeferencing(ifc)
map_conversion = ifc.by_type("IfcMapConversion")[0]
map_conversion.Eastings = 1.0
assert subject.xyz2enh((0.0, 0.0, 0.0)) == (1.0, 0.0, 0.0)
@@ -257,9 +261,9 @@ class TestXyz2Enh(NewFile):
props.blender_offset_x = "1.0"
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
ifcopenshell.api.georeference.add_georeferencing(ifc)
map_conversion = ifc.by_type("IfcMapConversion")[0]
map_conversion.Northings = 1.0
assert subject.xyz2enh((0.0, 0.0, 0.0)) == (1.0, 1.0, 0.0)
@@ -268,13 +272,13 @@ class TestXyz2Enh(NewFile):
class TestEnh2Xyz(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
tool.Ifc.set(ifc)
assert subject.enh2xyz((0.0, 0.0, 0.0)) == (0.0, 0.0, 0.0)
def test_using_the_blender_offset(self):
ifc = ifcopenshell.file()
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
tool.Ifc.set(ifc)
props = tool.Georeference.get_georeference_props()
props.has_blender_offset = True
@@ -284,9 +288,9 @@ class TestEnh2Xyz(NewFile):
def test_using_the_map_conversion(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
ifcopenshell.api.georeference.add_georeferencing(ifc)
map_conversion = ifc.by_type("IfcMapConversion")[0]
map_conversion.Eastings = 1.0
assert subject.enh2xyz((0.0, 0.0, 0.0)) == (-1.0, 0.0, 0.0)
@@ -297,9 +301,9 @@ class TestEnh2Xyz(NewFile):
props.blender_offset_x = "1.0"
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
ifcopenshell.api.run("georeference.add_georeferencing", ifc)
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
ifcopenshell.api.context.add_context(ifc, context_type="Model")
ifcopenshell.api.georeference.add_georeferencing(ifc)
map_conversion = ifc.by_type("IfcMapConversion")[0]
map_conversion.Northings = 1.0
assert subject.enh2xyz((0.0, 0.0, 0.0)) == (-1.0, -1.0, 0.0)
+4 -3
View File
@@ -21,6 +21,7 @@ import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.material
import ifcopenshell.api.pset
import ifcopenshell.api.root
import ifcopenshell.api.style
import bonsai.core.tool
import bonsai.tool as tool
@@ -64,9 +65,9 @@ class TestGetElementsByMaterial(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
material = ifcopenshell.api.run("material.add_material", ifc)
ifcopenshell.api.run("material.assign_material", ifc, products=[element], material=material)
element = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
material = ifcopenshell.api.material.add_material(ifc)
ifcopenshell.api.material.assign_material(ifc, products=[element], material=material)
assert subject.get_elements_by_material(material) == {element}
+18 -15
View File
@@ -20,6 +20,9 @@ import bpy
import math
import numpy
import ifcopenshell
import ifcopenshell.api.aggregate
import ifcopenshell.api.spatial
import ifcopenshell.api.unit
import test.bim.bootstrap
import bonsai.core.tool
import bonsai.tool as tool
@@ -39,7 +42,7 @@ class TestGetObjectStorey(test.bim.bootstrap.NewFile):
wall = ifc.createIfcWall()
tool.Ifc.link(wall, obj)
storey = ifc.createIfcBuildingStorey()
ifcopenshell.api.run("spatial.assign_container", ifc, products=[wall], relating_structure=storey)
ifcopenshell.api.spatial.assign_container(ifc, products=[wall], relating_structure=storey)
assert subject.get_object_storey(obj) == storey
def test_only_returning_a_building_storey(self):
@@ -49,7 +52,7 @@ class TestGetObjectStorey(test.bim.bootstrap.NewFile):
wall = ifc.createIfcWall()
tool.Ifc.link(wall, obj)
building = ifc.createIfcBuilding()
ifcopenshell.api.run("spatial.assign_container", ifc, products=[wall], relating_structure=building)
ifcopenshell.api.spatial.assign_container(ifc, products=[wall], relating_structure=building)
assert subject.get_object_storey(obj) is None
def test_returning_nothing_if_uncontained(self):
@@ -65,8 +68,8 @@ class TestGetStoreyElevation(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
ifc.createIfcProject()
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
unit = ifcopenshell.api.unit.add_si_unit(ifc, prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc, units=[unit])
storey = ifc.createIfcBuildingStorey()
storey.Elevation = 3000
tool.Ifc.set(ifc)
@@ -77,23 +80,23 @@ class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
def test_run(self):
ifc = ifcopenshell.file()
ifc.createIfcProject()
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
unit = ifcopenshell.api.unit.add_si_unit(ifc, prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc, units=[unit])
tool.Ifc.set(ifc)
building = ifc.createIfcBuilding()
storey = ifc.createIfcBuildingStorey()
storey.Elevation = 3000
storey2 = ifc.createIfcBuildingStorey()
storey2.Elevation = 5000
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey], relating_object=building)
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey2], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey2], relating_object=building)
assert subject.get_storey_height_in_si(storey, 1) == 2.0
def test_getting_a_double_storey_height(self):
ifc = ifcopenshell.file()
ifc.createIfcProject()
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
unit = ifcopenshell.api.unit.add_si_unit(ifc, prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc, units=[unit])
tool.Ifc.set(ifc)
building = ifc.createIfcBuilding()
storey = ifc.createIfcBuildingStorey()
@@ -102,9 +105,9 @@ class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
storey2.Elevation = 5000
storey3 = ifc.createIfcBuildingStorey()
storey3.Elevation = 9000
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey], relating_object=building)
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey2], relating_object=building)
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey3], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey2], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey3], relating_object=building)
assert subject.get_storey_height_in_si(storey, 2) == 6.0
def test_only_considering_storeys_in_the_same_building(self):
@@ -115,7 +118,7 @@ class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
storey.Elevation = 3000
storey2 = ifc.createIfcBuildingStorey()
storey2.Elevation = 5000
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey], relating_object=building)
assert subject.get_storey_height_in_si(storey, 1) is None
def test_returning_none_if_the_storey_height_is_undefined(self):
@@ -123,7 +126,7 @@ class TestGetStoreyHeight(test.bim.bootstrap.NewFile):
tool.Ifc.set(ifc)
building = ifc.createIfcBuilding()
storey = ifc.createIfcBuildingStorey()
ifcopenshell.api.run("aggregate.assign_object", ifc, products=[storey], relating_object=building)
ifcopenshell.api.aggregate.assign_object(ifc, products=[storey], relating_object=building)
assert subject.get_storey_height_in_si(storey, 1) is None
+2 -1
View File
@@ -18,13 +18,14 @@
import bpy
import ifcopenshell
import ifcopenshell.api.geometry
import ifcopenshell.api.material
import ifcopenshell.api.root
import ifcopenshell.api.style
import ifcopenshell.api.type
import ifcopenshell.util.element
import ifcopenshell.util.representation
import ifcopenshell.util.unit
import ifcopenshell.util.shape_builder
import bonsai.core.tool
import bonsai.tool as tool
import numpy as np
+3 -1
View File
@@ -18,6 +18,8 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.spatial
import bonsai.core.tool
import bonsai.tool as tool
from test.bim.bootstrap import NewFile
@@ -72,5 +74,5 @@ class TestGetContainer(NewFile):
tool.Ifc.set(ifc)
element = ifc.createIfcWall()
container = ifc.createIfcBuildingStorey()
ifcopenshell.api.run("spatial.assign_container", ifc, products=[element], relating_structure=container)
ifcopenshell.api.spatial.assign_container(ifc, products=[element], relating_structure=container)
assert subject.get_container(element) == container
+1
View File
@@ -36,5 +36,6 @@ class TestRunMigratePatch(NewFile):
infile = os.path.join(cwd, "..", "files", "ifc2x3.ifc")
outfile = os.path.join(cwd, "..", "files", "temp", "ifc2x3-migrated.ifc")
subject.run_migrate_patch(infile, outfile, "IFC4")
ifc: ifcopenshell.file
ifc = ifcopenshell.open(outfile)
assert ifc.schema == "IFC4"
+5 -4
View File
@@ -18,8 +18,10 @@
import bpy
import ifcopenshell
import ifcopenshell.api.context
import ifcopenshell.api.document
import ifcopenshell.api.root
import ifcopenshell.api.unit
import bonsai.core.tool
import bonsai.tool as tool
import tempfile
@@ -106,9 +108,8 @@ class TestSetDefaultContext(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifc.createIfcProject()
model = ifcopenshell.api.run("context.add_context", ifc, context_type="Model")
body = ifcopenshell.api.run(
"context.add_context",
model = ifcopenshell.api.context.add_context(ifc, context_type="Model")
body = ifcopenshell.api.context.add_context(
ifc,
parent=model,
context_type="Model",
@@ -125,7 +126,7 @@ class TestSetDefaultModelingDimensions(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
ifc.createIfcProject()
ifcopenshell.api.run("unit.assign_unit", ifc)
ifcopenshell.api.unit.assign_unit(ifc)
subject.set_default_modeling_dimensions()
props = tool.Model.get_model_props()
assert props.extrusion_depth == 3
+6 -4
View File
@@ -18,6 +18,8 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.pset
import bonsai.core.tool
import bonsai.tool as tool
from bonsai.tool.pset import Pset as subject
@@ -34,7 +36,7 @@ class TestGetElementPset(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcWall()
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo")
pset = ifcopenshell.api.pset.add_pset(ifc, product=element, name="Foo")
assert subject.get_element_pset(element, "Foo") == pset
@@ -43,9 +45,9 @@ class TestIsPsetEmpty(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcWall()
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo")
pset = ifcopenshell.api.pset.add_pset(ifc, product=element, name="Foo")
assert subject.is_pset_empty(pset) is True
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Bar"})
ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"Foo": "Bar"})
assert subject.is_pset_empty(pset) is False
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": None})
ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"Foo": None})
assert subject.is_pset_empty(pset) is True
+15 -12
View File
@@ -19,6 +19,11 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.context
import ifcopenshell.api.cost
import ifcopenshell.api.pset
import ifcopenshell.api.root
import ifcopenshell.api.unit
import ifcopenshell.util.pset
import test.bim.bootstrap
import bonsai.core.tool
@@ -58,7 +63,7 @@ class TestGetCalculatedObjectQuantities(test.bim.bootstrap.NewFile):
self.ifc = ifcopenshell.file()
tool.Ifc.set(self.ifc)
ifcopenshell.api.run("root.create_entity", self.ifc, ifc_class="IfcProject", name="My Project")
ifcopenshell.api.root.create_entity(self.ifc, ifc_class="IfcProject", name="My Project")
ifc_import_settings = import_ifc.IfcImportSettings.factory(
bpy.context, tool.Ifc.get_path(), logging.getLogger("ImportIFC")
)
@@ -67,12 +72,12 @@ class TestGetCalculatedObjectQuantities(test.bim.bootstrap.NewFile):
ifc_importer.create_project()
def setup_units(self, units):
ifcopenshell.api.run("unit.assign_unit", self.ifc, **units)
ifcopenshell.api.unit.assign_unit(self.ifc, **units)
def calculate_quantities(self, obj):
import ifc5d.qto
context = ifcopenshell.api.run("context.add_context", self.ifc, context_type="Model")
context = ifcopenshell.api.context.add_context(self.ifc, context_type="Model")
bpy.ops.mesh.primitive_cube_add(location=(0.0, 0.0, 0.0), size=2)
obj = bpy.context.active_object
element = bonsai.core.root.assign_class(
@@ -183,7 +188,7 @@ class TestGetBaseQto(test.bim.bootstrap.NewFile):
wall_obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
tool.Ifc.link(wall, wall_obj)
product = tool.Ifc.get_entity(wall_obj)
pset_qto = ifcopenshell.api.run("pset.add_qto", ifc, product=wall, name="Qto_Basefoo")
pset_qto = ifcopenshell.api.pset.add_qto(ifc, product=wall, name="Qto_Basefoo")
assert subject.get_base_qto(product).id() == pset_qto.get_info()["id"]
assert subject.get_base_qto(product).Name == pset_qto.Name
@@ -202,14 +207,12 @@ class TestGetRelatedCostItemQuantities(test.bim.bootstrap.NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
wall = ifc.createIfcWall()
schedule = ifcopenshell.api.run("cost.add_cost_schedule", ifc)
item = ifcopenshell.api.run("cost.add_cost_item", ifc, cost_schedule=schedule)
ifcopenshell.api.run("cost.edit_cost_item", ifc, cost_item=item, attributes={"Name": "Foo"})
qto = ifcopenshell.api.run("pset.add_qto", ifc, product=wall, name="Qto_WallBaseQuantities")
ifcopenshell.api.run("pset.edit_qto", ifc, qto=qto, properties={"NetVolume": 42.0})
ifcopenshell.api.run(
"cost.assign_cost_item_quantity", ifc, cost_item=item, products=[wall], prop_name="NetVolume"
)
schedule = ifcopenshell.api.cost.add_cost_schedule(ifc)
item = ifcopenshell.api.cost.add_cost_item(ifc, cost_schedule=schedule)
ifcopenshell.api.cost.edit_cost_item(ifc, cost_item=item, attributes={"Name": "Foo"})
qto = ifcopenshell.api.pset.add_qto(ifc, product=wall, name="Qto_WallBaseQuantities")
ifcopenshell.api.pset.edit_qto(ifc, qto=qto, properties={"NetVolume": 42.0})
ifcopenshell.api.cost.assign_cost_item_quantity(ifc, cost_item=item, products=[wall], prop_name="NetVolume")
assert subject.get_related_cost_item_quantities(wall)[0]["cost_item_name"] == "Foo"
assert subject.get_related_cost_item_quantities(wall)[0]["quantity_name"] == "NetVolume"
assert subject.get_related_cost_item_quantities(wall)[0]["quantity_value"] == 42
+5 -3
View File
@@ -19,6 +19,8 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.feature
import ifcopenshell.api.type
import bonsai.core.tool
import bonsai.tool as tool
from test.bim.bootstrap import NewFile
@@ -74,8 +76,8 @@ class TestGetDecompositionRelationships(NewFile):
element = ifc.createIfcWall()
opening = ifc.createIfcOpeningElement()
fill = ifc.createIfcWindow()
ifcopenshell.api.run("feature.add_feature", ifc, feature=opening, element=element)
ifcopenshell.api.run("feature.add_filling", ifc, opening=opening, element=fill)
ifcopenshell.api.feature.add_feature(ifc, feature=opening, element=element)
ifcopenshell.api.feature.add_filling(ifc, opening=opening, element=fill)
obj = bpy.data.objects.new("Object", None)
tool.Ifc.link(fill, obj)
@@ -99,7 +101,7 @@ class TestGetElementType(NewFile):
ifc = tool.Ifc.get()
element = ifc.createIfcWall()
type = ifc.createIfcWallType()
ifcopenshell.api.run("type.assign_type", ifc, related_objects=[element], relating_type=type)
ifcopenshell.api.type.assign_type(ifc, related_objects=[element], relating_type=type)
assert subject.get_element_type(element) == type
+6 -4
View File
@@ -20,6 +20,8 @@ import numpy as np
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.api.spatial
import bonsai.core.tool
import bonsai.tool as tool
from bonsai.tool.spatial import Spatial as subject
@@ -158,7 +160,7 @@ class TestGetContainer(NewFile):
ifc = ifcopenshell.file()
site = ifc.createIfcSite()
wall = ifc.createIfcWall()
ifcopenshell.api.run("spatial.assign_container", ifc, products=[wall], relating_structure=site)
ifcopenshell.api.spatial.assign_container(ifc, products=[wall], relating_structure=site)
assert subject.get_container(wall) == site
@@ -167,7 +169,7 @@ class TestGetDecomposedElements(NewFile):
ifc = ifcopenshell.file()
site = ifc.createIfcSite()
wall = ifc.createIfcWall()
ifcopenshell.api.run("spatial.assign_container", ifc, products=[wall], relating_structure=site)
ifcopenshell.api.spatial.assign_container(ifc, products=[wall], relating_structure=site)
assert subject.get_decomposed_elements(site) == {wall}
@@ -227,7 +229,7 @@ class TestSelectProducts(NewFile):
def test_select_products(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
product = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
product = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
obj = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj)
tool.Ifc.link(product, obj)
@@ -240,7 +242,7 @@ class TestGenerateSpace(NewFile):
bpy.ops.bim.create_project()
ifc = tool.Ifc.get()
scene = bpy.context.scene
product = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
product = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
bpy.ops.mesh.primitive_cube_add(size=10, location=(0, 0, 4))
obj = bpy.data.objects["Cube"]
scene.collection.objects.link(obj)
+2 -1
View File
@@ -20,6 +20,7 @@ import os
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.util.representation
import bonsai.core.tool
import bonsai.tool as tool
@@ -105,7 +106,7 @@ class TestGetElementsByStyle(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
element = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
style = ifc.createIfcSurfaceStyle()
item = ifc.createIfcExtrudedAreaSolid()
ifc.createIfcStyledItem(Item=item, Styles=[style])
+5 -3
View File
@@ -20,6 +20,8 @@ import bpy
import numpy as np
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.api.unit
import ifcopenshell.util.geolocation
import test.bim.bootstrap
@@ -42,9 +44,9 @@ class TestGetGlobalMatrix(test.bim.bootstrap.NewFile):
def test_applying_an_object_placement_blender_offset(self):
ifc = ifcopenshell.file()
ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcProject")
unit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[unit])
ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcProject")
unit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="LENGTHUNIT", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(ifc, units=[unit])
tool.Ifc.set(ifc)
props = tool.Georeference.get_georeference_props()
props.has_blender_offset = True
+12 -12
View File
@@ -19,6 +19,8 @@
import bpy
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.api.system
import ifcopenshell.util.unit
import bonsai.core.tool
import bonsai.tool as tool
@@ -150,9 +152,9 @@ class TestExportSystemAttributes(NewFile):
class TestGetConnectedPort(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
port1 = ifcopenshell.api.run("system.add_port", ifc)
port2 = ifcopenshell.api.run("system.add_port", ifc)
ifcopenshell.api.run("system.connect_port", ifc, port1=port1, port2=port2)
port1 = ifcopenshell.api.system.add_port(ifc)
port2 = ifcopenshell.api.system.add_port(ifc)
ifcopenshell.api.system.connect_port(ifc, port1=port1, port2=port2)
assert subject.get_connected_port(port1) == port2
assert subject.get_connected_port(port2) == port1
@@ -163,7 +165,7 @@ class TestGetPorts(NewFile):
tool.Ifc().set(ifc)
element = ifc.createIfcDuctSegment()
port = ifc.createIfcDistributionPort()
ifcopenshell.api.run("system.assign_port", ifc, element=element, port=port)
ifcopenshell.api.system.assign_port(ifc, element=element, port=port)
assert subject.get_ports(element) == [port]
@@ -268,9 +270,9 @@ class TestSelectSystemProducts(NewFile):
assert bpy.context.scene
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcPump")
system = ifcopenshell.api.run("system.add_system", ifc, ifc_class="IfcSystem")
ifcopenshell.api.run("system.assign_system", ifc, products=[element], system=system)
element = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcPump")
system = ifcopenshell.api.system.add_system(ifc, ifc_class="IfcSystem")
ifcopenshell.api.system.assign_system(ifc, products=[element], system=system)
obj = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj)
tool.Ifc.link(element, obj)
@@ -282,7 +284,7 @@ class TestSetActiveSystem(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
system = ifcopenshell.api.run("system.add_system", ifc, ifc_class="IfcSystem")
system = ifcopenshell.api.system.add_system(ifc, ifc_class="IfcSystem")
subject.set_active_edited_system(system)
props = tool.System.get_system_props()
assert props.edited_system_id == system.id()
@@ -298,14 +300,12 @@ class TestFlowElementAndControls(NewFile):
assert len(subject.get_flow_element_controls(flow_element)) == 0
assert subject.get_flow_control_flow_element(flow_control) == None
ifcopenshell.api.run(
"system.assign_flow_control",
ifcopenshell.api.system.assign_flow_control(
ifc,
related_flow_control=flow_control,
relating_flow_element=flow_element,
)
ifcopenshell.api.run(
"system.assign_flow_control",
ifcopenshell.api.system.assign_flow_control(
ifc,
related_flow_control=flow_control1,
relating_flow_element=flow_element,
+1 -1
View File
@@ -122,7 +122,7 @@ class TestGetModelTypes(NewFile):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
type_classes = ("IfcWallType", "IfcDoorStyle", "IfcWindowStyle", "IfcTypeProduct")
types = [ifcopenshell.api.run("root.create_entity", ifc, ifc_class=c) for c in type_classes]
types = [ifcopenshell.api.root.create_entity(ifc, ifc_class=c) for c in type_classes]
assert set(subject.get_model_types()) == set(types)