# IfcOpenShell - IFC toolkit and geometry engine # Copyright (C) 2021-2022 Dion Moult , Yassine Oualid # # 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 import ifcopenshell.util.element def change_nest(file, item=None, new_parent=None) -> None: """Assigns a cost item to a new parent cost item""" settings = {"item": item, "new_parent": new_parent} if not settings["item"].Nests: return nests = settings["item"].Nests[0] related_objects = list(nests.RelatedObjects) related_objects.remove(settings["item"]) if related_objects: nests.RelatedObjects = related_objects ifcopenshell.api.run("owner.update_owner_history", file, **{"element": nests}) else: history = nests.OwnerHistory file.remove(nests) if history: ifcopenshell.util.element.remove_deep2(file, history) ifcopenshell.api.run( "nest.assign_object", file, related_objects=[settings["item"]], relating_object=settings["new_parent"], )