mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
Replace all ifcopenshell.api.run with ifcopenshell.api static functions.
This commit is contained in:
@@ -17,28 +17,28 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.material
|
||||
|
||||
|
||||
class TestAddMaterialSetIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_add_layer_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialLayerSet")
|
||||
material = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialLayerSet")
|
||||
assert material.LayerSetName == "Unnamed"
|
||||
assert material.is_a("IfcMaterialLayerSet")
|
||||
|
||||
def test_add_list(self):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialList")
|
||||
material = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialList")
|
||||
assert material.is_a("IfcMaterialList")
|
||||
|
||||
|
||||
class TestAddMaterialSetIFC4(test.bootstrap.IFC4, TestAddMaterialSetIFC2X3):
|
||||
# entities added in IFC4
|
||||
def test_add_profile_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialProfileSet")
|
||||
material = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialProfileSet")
|
||||
assert material.Name == "Unnamed"
|
||||
assert material.is_a("IfcMaterialProfileSet")
|
||||
|
||||
def test_add_constituent_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialConstituentSet")
|
||||
material = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialConstituentSet")
|
||||
assert material.Name == "Unnamed"
|
||||
assert material.is_a("IfcMaterialConstituentSet")
|
||||
|
||||
@@ -16,48 +16,45 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.type
|
||||
import ifcopenshell.api.material
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestAssignMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_assign_element_single_material(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterial", material=material
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterial", material=material
|
||||
)
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert ifcopenshell.util.element.get_material(element1) == material
|
||||
assert ifcopenshell.util.element.get_material(element2) == material
|
||||
|
||||
def test_raise_exception_creating_ifc_material_without(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element], type="IfcMaterial", material=None
|
||||
)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], type="IfcMaterial", material=None)
|
||||
assert ifcopenshell.util.element.get_material(element)
|
||||
|
||||
def test_assign_type_single_material(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterial", material=material
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterial", material=material
|
||||
)
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert ifcopenshell.util.element.get_material(element1) == material
|
||||
assert ifcopenshell.util.element.get_material(element2) == material
|
||||
|
||||
def test_assign_type_material_layer_set(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterialLayerSet"
|
||||
)
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element1, element2], type="IfcMaterialLayerSet")
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
material_set = ifcopenshell.util.element.get_material(element1)
|
||||
assert material_set.is_a("IfcMaterialLayerSet")
|
||||
@@ -65,15 +62,13 @@ class TestAssignMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
assert ifcopenshell.util.element.get_material(element2) == material_set
|
||||
|
||||
def test_assign_type_material_layer_set_and_element_layer_set_usage(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run(
|
||||
"type.assign_type", self.file, related_objects=[element1, element2], relating_type=element_type
|
||||
)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element_type], type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterialLayerSetUsage"
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1, element2], relating_type=element_type)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type], type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterialLayerSetUsage"
|
||||
)
|
||||
material_set = ifcopenshell.util.element.get_material(element_type)
|
||||
material_usage1 = ifcopenshell.util.element.get_material(element1, should_inherit=False)
|
||||
@@ -82,22 +77,18 @@ class TestAssignMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
assert ifcopenshell.util.element.get_material(element2, should_inherit=False) == material_usage1
|
||||
|
||||
def test_assign_type_material_layer_set_and_element_layer_set_usage_is_different_for_different_types(self):
|
||||
element_type1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element1], relating_type=element_type1)
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element_type1], type="IfcMaterialLayerSet"
|
||||
)
|
||||
element_type1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1], relating_type=element_type1)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type1], type="IfcMaterialLayerSet")
|
||||
|
||||
element_type2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element2], relating_type=element_type2)
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element_type2], type="IfcMaterialLayerSet"
|
||||
)
|
||||
element_type2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element2], relating_type=element_type2)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type2], type="IfcMaterialLayerSet")
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterialLayerSetUsage"
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterialLayerSetUsage"
|
||||
)
|
||||
material_set1 = ifcopenshell.util.element.get_material(element_type1)
|
||||
material_usage1 = ifcopenshell.util.element.get_material(element1, should_inherit=False)
|
||||
@@ -111,10 +102,10 @@ class TestAssignMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
assert material_usage2 != material_usage1
|
||||
|
||||
def test_assign_element_layer_set_usage_is_different_for_different_layer_set_directions(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterialLayerSetUsage"
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSlab")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterialLayerSetUsage"
|
||||
)
|
||||
|
||||
material_usage1 = ifcopenshell.util.element.get_material(element1, should_inherit=False)
|
||||
@@ -133,11 +124,10 @@ class TestAssignMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
assert material_usage1 != material_usage2
|
||||
|
||||
def test_assign_element_material_list(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material",
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file,
|
||||
products=[element1, element2],
|
||||
type="IfcMaterialList",
|
||||
@@ -152,10 +142,10 @@ class TestAssignMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
|
||||
class TestAssignMaterialIFC4(test.bootstrap.IFC4, TestAssignMaterialIFC2X3):
|
||||
def test_assign_type_material_profile_set(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterialProfileSet"
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterialProfileSet"
|
||||
)
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
material_set = ifcopenshell.util.element.get_material(element1)
|
||||
@@ -164,17 +154,13 @@ class TestAssignMaterialIFC4(test.bootstrap.IFC4, TestAssignMaterialIFC2X3):
|
||||
assert ifcopenshell.util.element.get_material(element2) == material_set
|
||||
|
||||
def test_assign_type_material_profile_set_and_element_profile_set_usage(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run(
|
||||
"type.assign_type", self.file, related_objects=[element1, element2], relating_type=element_type
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element_type], type="IfcMaterialProfileSet"
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterialProfileSetUsage"
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1, element2], relating_type=element_type)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type], type="IfcMaterialProfileSet")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterialProfileSetUsage"
|
||||
)
|
||||
material_set = element_type.HasAssociations[0].RelatingMaterial
|
||||
material_usage1 = element1.HasAssociations[0].RelatingMaterial
|
||||
@@ -183,22 +169,18 @@ class TestAssignMaterialIFC4(test.bootstrap.IFC4, TestAssignMaterialIFC2X3):
|
||||
assert ifcopenshell.util.element.get_material(element2, should_inherit=False) == material_usage1
|
||||
|
||||
def test_assign_type_material_profile_set_and_element_profile_set_usage_is_different_for_different_types(self):
|
||||
element_type1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element1], relating_type=element_type1)
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element_type1], type="IfcMaterialProfileSet"
|
||||
)
|
||||
element_type1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1], relating_type=element_type1)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type1], type="IfcMaterialProfileSet")
|
||||
|
||||
element_type2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element2], relating_type=element_type2)
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element_type2], type="IfcMaterialProfileSet"
|
||||
)
|
||||
element_type2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element2], relating_type=element_type2)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type2], type="IfcMaterialProfileSet")
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterialProfileSetUsage"
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterialProfileSetUsage"
|
||||
)
|
||||
material_set1 = ifcopenshell.util.element.get_material(element_type1)
|
||||
material_usage1 = ifcopenshell.util.element.get_material(element1, should_inherit=False)
|
||||
@@ -212,10 +194,10 @@ class TestAssignMaterialIFC4(test.bootstrap.IFC4, TestAssignMaterialIFC2X3):
|
||||
assert material_usage2 != material_usage1
|
||||
|
||||
def test_assign_type_material_constituent_set(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterialConstituentSet"
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterialConstituentSet"
|
||||
)
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
material_set = ifcopenshell.util.element.get_material(element1)
|
||||
|
||||
@@ -17,22 +17,26 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.style
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.material
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestCopyMaterial(test.bootstrap.IFC4):
|
||||
def test_copy_a_single_material(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material)
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
new = ifcopenshell.api.material.copy_material(self.file, material=material)
|
||||
assert new.Name == "CON01"
|
||||
assert len(self.file.by_type("IfcMaterial")) == 2
|
||||
|
||||
def test_assignments_are_not_copied(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element], material=material)
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material)
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element], material=material)
|
||||
new = ifcopenshell.api.material.copy_material(self.file, material=material)
|
||||
assert ifcopenshell.util.element.get_elements_by_material(self.file, material)
|
||||
assert not ifcopenshell.util.element.get_elements_by_material(self.file, new)
|
||||
|
||||
@@ -42,10 +46,10 @@ class TestCopyMaterial(test.bootstrap.IFC4):
|
||||
return material.HasProperties
|
||||
return [i for i in self.file.get_inverse(material) if i.is_a("IfcMaterialProperties")]
|
||||
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=material, name="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"foo": "bar"})
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material)
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=material, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"foo": "bar"})
|
||||
new = ifcopenshell.api.material.copy_material(self.file, material=material)
|
||||
assert new.Name == "CON01"
|
||||
assert len(self.file.by_type("IfcMaterial")) == 2
|
||||
assert len(self.file.by_type("IfcMaterialProperties")) == 2
|
||||
@@ -60,12 +64,12 @@ class TestCopyMaterial(test.bootstrap.IFC4):
|
||||
assert props_new.ExtendedProperties[0].NominalValue.wrappedValue == "bar"
|
||||
|
||||
def test_copy_a_material_with_a_style_representation(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
context = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
style = ifcopenshell.api.run("style.add_style", self.file)
|
||||
ifcopenshell.api.run("style.assign_material_style", self.file, material=material, style=style, context=context)
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material)
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
context = ifcopenshell.api.context.add_context(self.file, context_type="Model")
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
style = ifcopenshell.api.style.add_style(self.file)
|
||||
ifcopenshell.api.style.assign_material_style(self.file, material=material, style=style, context=context)
|
||||
new = ifcopenshell.api.material.copy_material(self.file, material=material)
|
||||
assert new.Name == "CON01"
|
||||
assert len(self.file.by_type("IfcPresentationStyle")) == 1
|
||||
assert len(self.file.by_type("IfcMaterialDefinitionRepresentation")) == 2
|
||||
@@ -74,15 +78,13 @@ class TestCopyMaterial(test.bootstrap.IFC4):
|
||||
assert new.HasRepresentation[0].Representations[0].ContextOfItems == context
|
||||
|
||||
def test_copy_a_material_constituent_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, name="Foo", set_type="IfcMaterialConstituentSet"
|
||||
)
|
||||
item = ifcopenshell.api.run(
|
||||
"material.add_constituent", self.file, constituent_set=material_set, material=material
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
material_set = ifcopenshell.api.material.add_material_set(
|
||||
self.file, name="Foo", set_type="IfcMaterialConstituentSet"
|
||||
)
|
||||
item = ifcopenshell.api.material.add_constituent(self.file, constituent_set=material_set, material=material)
|
||||
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material_set)
|
||||
new = ifcopenshell.api.material.copy_material(self.file, material=material_set)
|
||||
assert new != material_set
|
||||
assert new.Name == "Foo"
|
||||
assert new.MaterialConstituents[0] != item
|
||||
@@ -92,13 +94,11 @@ class TestCopyMaterial(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||
|
||||
def test_copy_a_material_layer_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, name="Foo", set_type="IfcMaterialLayerSet"
|
||||
)
|
||||
item = ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
material_set = ifcopenshell.api.material.add_material_set(self.file, name="Foo", set_type="IfcMaterialLayerSet")
|
||||
item = ifcopenshell.api.material.add_layer(self.file, layer_set=material_set, material=material)
|
||||
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material_set)
|
||||
new = ifcopenshell.api.material.copy_material(self.file, material=material_set)
|
||||
assert new != material_set
|
||||
assert new.LayerSetName == "Foo"
|
||||
assert new.MaterialLayers[0] != item
|
||||
@@ -108,7 +108,7 @@ class TestCopyMaterial(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||
|
||||
def test_copy_a_material_profile_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
profile = self.file.create_entity(
|
||||
"IfcIShapeProfileDef",
|
||||
ProfileName="HEA100",
|
||||
@@ -119,14 +119,14 @@ class TestCopyMaterial(test.bootstrap.IFC4):
|
||||
FlangeThickness=8,
|
||||
FilletRadius=12,
|
||||
)
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, name="Foo", set_type="IfcMaterialProfileSet"
|
||||
material_set = ifcopenshell.api.material.add_material_set(
|
||||
self.file, name="Foo", set_type="IfcMaterialProfileSet"
|
||||
)
|
||||
item = ifcopenshell.api.run(
|
||||
"material.add_profile", self.file, profile_set=material_set, material=material, profile=profile
|
||||
item = ifcopenshell.api.material.add_profile(
|
||||
self.file, profile_set=material_set, material=material, profile=profile
|
||||
)
|
||||
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material_set)
|
||||
new = ifcopenshell.api.material.copy_material(self.file, material=material_set)
|
||||
assert new != material_set
|
||||
assert new.Name == "Foo"
|
||||
assert new.MaterialProfiles[0] != item
|
||||
@@ -138,11 +138,11 @@ class TestCopyMaterial(test.bootstrap.IFC4):
|
||||
assert len(self.file.by_type("IfcProfileDef")) == 1
|
||||
|
||||
def test_copy_a_material_list(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialList")
|
||||
ifcopenshell.api.run("material.add_list_item", self.file, material_list=material_set, material=material)
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
material_set = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialList")
|
||||
ifcopenshell.api.material.add_list_item(self.file, material_list=material_set, material=material)
|
||||
|
||||
new = ifcopenshell.api.run("material.copy_material", self.file, material=material_set)
|
||||
new = ifcopenshell.api.material.copy_material(self.file, material=material_set)
|
||||
assert new != material_set
|
||||
assert new.Materials[0] == material
|
||||
assert len(self.file.by_type("IfcMaterialList")) == 2
|
||||
|
||||
@@ -17,58 +17,62 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.style
|
||||
import ifcopenshell.api.context
|
||||
import ifcopenshell.api.material
|
||||
|
||||
|
||||
class TestRemoveMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_removing_material(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
ifcopenshell.api.material.remove_material(self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterial")) == 0
|
||||
|
||||
def test_removing_material_with_associations(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[wall], material=material)
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[wall], material=material)
|
||||
ifcopenshell.api.material.remove_material(self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 0
|
||||
|
||||
def test_removing_material_in_layer(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[wall], material=material_set)
|
||||
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
material_set = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.material.add_layer(self.file, layer_set=material_set, material=material)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[wall], material=material_set)
|
||||
assert len(self.file.by_type("IfcMaterialLayerSet")[0].MaterialLayers) == 1
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
ifcopenshell.api.material.remove_material(self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert len(self.file.by_type("IfcMaterialLayerSet")[0].MaterialLayers) == 0
|
||||
|
||||
def test_removing_material_in_list(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialList")
|
||||
ifcopenshell.api.run("material.add_list_item", self.file, material_list=material_set, material=material)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[wall], material=material_set)
|
||||
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
material_set = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialList")
|
||||
ifcopenshell.api.material.add_list_item(self.file, material_list=material_set, material=material)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[wall], material=material_set)
|
||||
assert len(self.file.by_type("IfcMaterialList")[0].Materials) == 1
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
ifcopenshell.api.material.remove_material(self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert len(self.file.by_type("IfcMaterialList")[0].Materials) == 0
|
||||
|
||||
def test_removing_a_material_with_a_style_definition(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
context = ifcopenshell.api.run("context.add_context", self.file, context_type="Model")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
style = ifcopenshell.api.run("style.add_style", self.file)
|
||||
ifcopenshell.api.run("style.assign_material_style", self.file, material=material, style=style, context=context)
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
context = ifcopenshell.api.context.add_context(self.file, context_type="Model")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
style = ifcopenshell.api.style.add_style(self.file)
|
||||
ifcopenshell.api.style.assign_material_style(self.file, material=material, style=style, context=context)
|
||||
assert len(self.file.by_type("IfcMaterialDefinitionRepresentation")) == 1
|
||||
assert len(self.file.by_type("IfcStyledRepresentation")) == 1
|
||||
assert len(self.file.by_type("IfcStyledItem")) == 1
|
||||
assert len(self.file.by_type("IfcSurfaceStyle")) == 1
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
ifcopenshell.api.material.remove_material(self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcMaterialDefinitionRepresentation")) == 0
|
||||
assert len(self.file.by_type("IfcStyledRepresentation")) == 0
|
||||
@@ -81,11 +85,11 @@ class TestRemoveMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
return material.HasProperties
|
||||
return [i for i in self.file.get_inverse(material) if i.is_a("IfcMaterialProperties")]
|
||||
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=material, name="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=material, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
assert get_material_props(material)
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
ifcopenshell.api.material.remove_material(self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterialProperties")) == 0
|
||||
assert len(self.file.by_type("IfcPropertySingleValue")) == 0
|
||||
|
||||
@@ -93,27 +97,27 @@ class TestRemoveMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
class TestRemoveMaterialIFC4(test.bootstrap.IFC4, TestRemoveMaterialIFC2X3):
|
||||
# IfcMaterialProfileSet added in IFC4
|
||||
def test_removing_material_in_profile(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialProfileSet")
|
||||
ifcopenshell.api.run("material.add_profile", self.file, profile_set=material_set, material=material)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[wall], material=material_set)
|
||||
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
material_set = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialProfileSet")
|
||||
ifcopenshell.api.material.add_profile(self.file, profile_set=material_set, material=material)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[wall], material=material_set)
|
||||
assert len(self.file.by_type("IfcMaterialProfileSet")[0].MaterialProfiles) == 1
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
ifcopenshell.api.material.remove_material(self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert len(self.file.by_type("IfcMaterialProfileSet")[0].MaterialProfiles) == 0
|
||||
|
||||
def test_removing_material_in_constituent(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run(
|
||||
"material.add_material_set", self.file, set_type="IfcMaterialConstituentSet"
|
||||
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
material_set = ifcopenshell.api.material.add_material_set(
|
||||
self.file, set_type="IfcMaterialConstituentSet"
|
||||
)
|
||||
ifcopenshell.api.run("material.add_constituent", self.file, constituent_set=material_set, material=material)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[wall], material=material_set)
|
||||
ifcopenshell.api.material.add_constituent(self.file, constituent_set=material_set, material=material)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[wall], material=material_set)
|
||||
assert len(self.file.by_type("IfcMaterialConstituentSet")[0].MaterialConstituents) == 1
|
||||
ifcopenshell.api.run("material.remove_material", self.file, material=material)
|
||||
ifcopenshell.api.material.remove_material(self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert self.file.by_type("IfcMaterialConstituentSet")[0].MaterialConstituents is None
|
||||
|
||||
@@ -17,28 +17,30 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.material
|
||||
|
||||
|
||||
class TestRemoveMaterialSetIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_removing_material_set(self):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.run("material.remove_material_set", self.file, material=material)
|
||||
material = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.material.remove_material_set(self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterialLayerSet")) == 0
|
||||
|
||||
def test_removing_material_set_with_associations(self):
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[wall], material=material)
|
||||
ifcopenshell.api.run("material.remove_material_set", self.file, material=material)
|
||||
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[wall], material=material)
|
||||
ifcopenshell.api.material.remove_material_set(self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterialLayerSet")) == 0
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 0
|
||||
|
||||
def test_removing_a_material_set_with_set_items_but_preserving_materials(self):
|
||||
material = ifcopenshell.api.run("material.add_material", self.file)
|
||||
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.run("material.add_layer", self.file, layer_set=material_set, material=material)
|
||||
ifcopenshell.api.run("material.remove_material_set", self.file, material=material_set)
|
||||
material = ifcopenshell.api.material.add_material(self.file)
|
||||
material_set = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.material.add_layer(self.file, layer_set=material_set, material=material)
|
||||
ifcopenshell.api.material.remove_material_set(self.file, material=material_set)
|
||||
assert len(self.file.by_type("IfcMaterialLayerSet")) == 0
|
||||
assert len(self.file.by_type("IfcMaterialLayer")) == 0
|
||||
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||
@@ -47,10 +49,10 @@ class TestRemoveMaterialSetIFC2X3(test.bootstrap.IFC2X3):
|
||||
class TestRemoveMaterialSetIFC4(test.bootstrap.IFC4, TestRemoveMaterialSetIFC2X3):
|
||||
# IFC2X3 doesn't support adding a pset to IfcMaterialLayerSet
|
||||
def test_removing_a_material_set_with_properties(self):
|
||||
material = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialLayerSet")
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=material, name="Foo_Bar")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
material = ifcopenshell.api.material.add_material_set(self.file, set_type="IfcMaterialLayerSet")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=material, name="Foo_Bar")
|
||||
ifcopenshell.api.pset.edit_pset(self.file, pset=pset, properties={"Foo": "Bar"})
|
||||
assert material.HasProperties
|
||||
ifcopenshell.api.run("material.remove_material_set", self.file, material=material)
|
||||
ifcopenshell.api.material.remove_material_set(self.file, material=material)
|
||||
assert len(self.file.by_type("IfcMaterialProperties")) == 0
|
||||
assert len(self.file.by_type("IfcPropertySingleValue")) == 0
|
||||
|
||||
@@ -17,31 +17,33 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.type
|
||||
import ifcopenshell.api.material
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class TestUnassignMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_unassign_single_material(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterial", material=material
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterial", material=material
|
||||
)
|
||||
ifcopenshell.api.run("material.unassign_material", self.file, products=[element1, element2])
|
||||
ifcopenshell.api.material.unassign_material(self.file, products=[element1, element2])
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcWall")) == 2
|
||||
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||
|
||||
def test_unassign_single_material_with_multiple_elements(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterial", material=material
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterial", material=material
|
||||
)
|
||||
ifcopenshell.api.run("material.unassign_material", self.file, products=[element2])
|
||||
ifcopenshell.api.material.unassign_material(self.file, products=[element2])
|
||||
assert element1.HasAssociations
|
||||
assert not element2.HasAssociations
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
@@ -49,28 +51,24 @@ class TestUnassignMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
assert len(self.file.by_type("IfcMaterial")) == 1
|
||||
|
||||
def test_unassign_material_layer_set_from_type(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterialLayerSet"
|
||||
)
|
||||
ifcopenshell.api.run("material.unassign_material", self.file, products=[element1, element2])
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element1, element2], type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.material.unassign_material(self.file, products=[element1, element2])
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcWallType")) == 2
|
||||
assert len(self.file.by_type("IfcMaterialLayerSet")) == 1
|
||||
|
||||
def test_unassign_material_layer_set_usage_from_element(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run(
|
||||
"type.assign_type", self.file, related_objects=[element1, element2], relating_type=element_type
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1, element2], relating_type=element_type)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type], type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterialLayerSetUsage"
|
||||
)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element_type], type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterialLayerSetUsage"
|
||||
)
|
||||
ifcopenshell.api.run("material.unassign_material", self.file, products=[element1, element2])
|
||||
ifcopenshell.api.material.unassign_material(self.file, products=[element1, element2])
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert element_type.HasAssociations
|
||||
assert len(self.file.by_type("IfcWallType")) == 1
|
||||
@@ -79,20 +77,14 @@ class TestUnassignMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
assert len(self.file.by_type("IfcMaterialLayerSetUsage")) == 0
|
||||
|
||||
def test_unassign_material_layer_set_usage_shouldnt_remove_other_usages_of_the_type(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run(
|
||||
"type.assign_type", self.file, related_objects=[element1, element2], relating_type=element_type
|
||||
)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element_type], type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1], type="IfcMaterialLayerSetUsage"
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element2], type="IfcMaterialLayerSetUsage"
|
||||
)
|
||||
ifcopenshell.api.run("material.unassign_material", self.file, products=[element1])
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1, element2], relating_type=element_type)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type], type="IfcMaterialLayerSet")
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element1], type="IfcMaterialLayerSetUsage")
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element2], type="IfcMaterialLayerSetUsage")
|
||||
ifcopenshell.api.material.unassign_material(self.file, products=[element1])
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 2
|
||||
assert element_type.HasAssociations
|
||||
assert len(self.file.by_type("IfcWallType")) == 1
|
||||
@@ -101,20 +93,18 @@ class TestUnassignMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
assert len(self.file.by_type("IfcMaterialLayerSetUsage")) == 1
|
||||
|
||||
def test_unassign_material_layer_set_usage_from_element_with_multiple_invalid_usages(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element], relating_type=element_type)
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_objects=[element2], relating_type=element_type)
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element_type], type="IfcMaterialLayerSet")
|
||||
rel = ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element], type="IfcMaterialLayerSetUsage"
|
||||
)
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element2], relating_type=element_type)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type], type="IfcMaterialLayerSet")
|
||||
rel = ifcopenshell.api.material.assign_material(self.file, products=[element], type="IfcMaterialLayerSetUsage")
|
||||
|
||||
# In some invalid IFCs from Revit, they reuse usages. Let's recreate this invalid scenario
|
||||
rel.RelatedObjects = list(rel.RelatedObjects) + [element2]
|
||||
|
||||
ifcopenshell.api.run("material.unassign_material", self.file, products=[element])
|
||||
ifcopenshell.api.material.unassign_material(self.file, products=[element])
|
||||
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 2
|
||||
for rel in self.file.by_type("IfcRelAssociatesMaterial"):
|
||||
@@ -128,22 +118,21 @@ class TestUnassignMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
assert ifcopenshell.util.element.get_material(element2, should_inherit=False).is_a("IfcMaterialLayerSetUsage")
|
||||
|
||||
def test_unassign_element_material_list(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material1 = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material",
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material1 = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file,
|
||||
products=[element1, element2],
|
||||
type="IfcMaterialList",
|
||||
material=material1,
|
||||
)
|
||||
element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
material3 = ifcopenshell.api.run("material.add_material", self.file, name="CON01")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element3], type="IfcMaterialList", material=material3
|
||||
element3 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
material3 = ifcopenshell.api.material.add_material(self.file, name="CON01")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element3], type="IfcMaterialList", material=material3
|
||||
)
|
||||
ifcopenshell.api.run("material.unassign_material", self.file, products=[element1, element2, element3])
|
||||
ifcopenshell.api.material.unassign_material(self.file, products=[element1, element2, element3])
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcMaterialList")) == 2
|
||||
assert len(self.file.by_type("IfcMaterial")) == 2
|
||||
@@ -152,29 +141,25 @@ class TestUnassignMaterialIFC2X3(test.bootstrap.IFC2X3):
|
||||
class TestUnassignMaterialIFC4(test.bootstrap.IFC4, TestUnassignMaterialIFC2X3):
|
||||
|
||||
def test_unassign_material_profile_set_from_type(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element1], type="IfcMaterialProfileSet")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run("material.assign_material", self.file, products=[element2], type="IfcMaterialProfileSet")
|
||||
ifcopenshell.api.run("material.unassign_material", self.file, products=[element1, element2])
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element1], type="IfcMaterialProfileSet")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element2], type="IfcMaterialProfileSet")
|
||||
ifcopenshell.api.material.unassign_material(self.file, products=[element1, element2])
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcWallType")) == 2
|
||||
assert len(self.file.by_type("IfcMaterialProfileSet")) == 2
|
||||
|
||||
def test_unassign_material_profile_set_usage_from_element(self):
|
||||
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run(
|
||||
"type.assign_type", self.file, related_objects=[element1, element2], relating_type=element_type
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1, element2], relating_type=element_type)
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element_type], type="IfcMaterialProfileSet")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterialProfileSetUsage"
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element_type], type="IfcMaterialProfileSet"
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterialProfileSetUsage"
|
||||
)
|
||||
ifcopenshell.api.run("material.unassign_material", self.file, products=[element1, element2])
|
||||
ifcopenshell.api.material.unassign_material(self.file, products=[element1, element2])
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 1
|
||||
assert element_type.HasAssociations
|
||||
assert len(self.file.by_type("IfcWallType")) == 1
|
||||
@@ -183,16 +168,14 @@ class TestUnassignMaterialIFC4(test.bootstrap.IFC4, TestUnassignMaterialIFC2X3):
|
||||
assert len(self.file.by_type("IfcMaterialProfileSetUsage")) == 0
|
||||
|
||||
def test_unassign_material_constituent_set_from_type(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element1, element2], type="IfcMaterialConstituentSet"
|
||||
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.material.assign_material(
|
||||
self.file, products=[element1, element2], type="IfcMaterialConstituentSet"
|
||||
)
|
||||
element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run(
|
||||
"material.assign_material", self.file, products=[element3], type="IfcMaterialConstituentSet"
|
||||
)
|
||||
ifcopenshell.api.run("material.unassign_material", self.file, products=[element1, element2, element3])
|
||||
element3 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.material.assign_material(self.file, products=[element3], type="IfcMaterialConstituentSet")
|
||||
ifcopenshell.api.material.unassign_material(self.file, products=[element1, element2, element3])
|
||||
assert len(self.file.by_type("IfcRelAssociatesMaterial")) == 0
|
||||
assert len(self.file.by_type("IfcWallType")) == 3
|
||||
assert len(self.file.by_type("IfcMaterialConstituentSet")) == 2
|
||||
|
||||
Reference in New Issue
Block a user