diff --git a/src/ifcopenshell-python/ifcopenshell/api/pset/add_pset.py b/src/ifcopenshell-python/ifcopenshell/api/pset/add_pset.py index c5c5d95d27..ae8a1cb96d 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/pset/add_pset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/pset/add_pset.py @@ -27,7 +27,7 @@ class Usecase: self.settings[key] = value def execute(self): - if self.settings["product"].is_a("IfcObject"): + if self.settings["product"].is_a("IfcObject") or self.settings["product"].is_a("IfcContext"): for rel in self.settings["product"].IsDefinedBy or []: if ( rel.is_a("IfcRelDefinesByProperties") diff --git a/src/ifcopenshell-python/test/api/pset/test_add_pset.py b/src/ifcopenshell-python/test/api/pset/test_add_pset.py new file mode 100644 index 0000000000..3170b53abd --- /dev/null +++ b/src/ifcopenshell-python/test/api/pset/test_add_pset.py @@ -0,0 +1,60 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2022 Dion Moult +# +# This file is part of IfcOpenShell. +# +# IfcOpenShell is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# IfcOpenShell is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with IfcOpenShell. If not, see . + +import test.bootstrap +import ifcopenshell.api + + +class TestAddPset(test.bootstrap.IFC4): + def test_adding_a_pset_to_an_object(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon") + assert pset.is_a("IfcPropertySet") + assert "Pset_WallCommon" in ifcopenshell.util.element.get_psets(element) + + def test_adding_a_pset_to_a_type_object(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType") + pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon") + assert pset.is_a("IfcPropertySet") + assert "Pset_WallCommon" in ifcopenshell.util.element.get_psets(element) + + def test_adding_a_pset_to_a_material(self): + material = ifcopenshell.api.run("material.add_material", self.file) + pset = ifcopenshell.api.run("pset.add_pset", self.file, product=material, name="Pset_MaterialCommon") + assert pset.is_a("IfcMaterialProperties") + assert "Pset_MaterialCommon" in ifcopenshell.util.element.get_psets(material) + + def test_adding_a_pset_to_a_profile(self): + profile = ifcopenshell.api.run("profile.add_parameterized_profile", self.file, ifc_class="IfcCircleProfileDef") + pset = ifcopenshell.api.run("pset.add_pset", self.file, product=profile, name="Pset_ProfileMechanical") + assert pset.is_a("IfcProfileProperties") + assert "Pset_ProfileMechanical" in ifcopenshell.util.element.get_psets(profile) + + def test_adding_a_pset_to_a_context(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject") + pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Custom_Pset") + assert pset.is_a("IfcPropertySet") + assert "Custom_Pset" in ifcopenshell.util.element.get_psets(element) + + +class TestAddPsetIFC2X3(test.bootstrap.IFC2X3): + def test_adding_a_pset_to_a_project(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject") + pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Custom_Pset") + assert pset.is_a("IfcPropertySet") + assert "Custom_Pset" in ifcopenshell.util.element.get_psets(element)