# IfcOpenShell - IFC toolkit and geometry engine # Copyright (C) 2021 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 ifcopenshell import ifcopenshell.api.owner import ifcopenshell.api.pset import ifcopenshell.guid import ifcopenshell.util.element def unshare_pset( file: ifcopenshell.file, products: list[ifcopenshell.entity_instance], pset: ifcopenshell.entity_instance, ) -> list[ifcopenshell.entity_instance]: """Copy a shared pset as linked only to the provided elements. Note that method will create a copy of the pset for each element provided. :param products: Elements (or element types) to link the pset to. :param pset: Shared property set. :return: List of copied property sets. Example: .. code:: python element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") ifcopenshell.api.pset.assign_pset(self.file, [element1, element2], pset) # Pset is now shared by 2 elements. assert ifcopenshell.util.element.get_elements_using_pset(pset) == {element1, element2} new_psets = ifcopenshell.api.pset.unshare_pset(self.file, [element2], pset) # element2 was unassigned from the original pset. assert ifcopenshell.util.element.get_elements_using_pset(pset) == {element1} new_pset = new_psets[0] # New pset was created and was assigned to element2. assert new_pset != pset assert ifcopenshell.util.element.get_elements_using_pset(new_pset) == {element2} """ products_occurrences: set[ifcopenshell.entity_instance] = set() products_types: set[ifcopenshell.entity_instance] = set() for product in products: if product.is_a("IfcTypeProduct"): products_types.add(product) else: products_occurrences.add(product) ifcopenshell.api.pset.unassign_pset(file, products, pset) pset_copies: list[ifcopenshell.entity_instance] = [] for product in products: pset_copy = ifcopenshell.util.element.copy_deep(file, pset) pset_copies.append(pset_copy) ifcopenshell.api.pset.assign_pset(file, [product], pset_copy) return pset_copies