2022-01-19 12:18:33 +11:00
|
|
|
# IfcOpenShell - IFC toolkit and geometry engine
|
|
|
|
|
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
|
|
|
|
#
|
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2021-01-23 11:58:29 +11:00
|
|
|
import ifcopenshell
|
2023-11-28 10:45:49 +11:00
|
|
|
import ifcopenshell.util.element
|
2021-01-23 11:58:29 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Usecase:
|
2022-11-23 10:56:12 +09:00
|
|
|
def __init__(self, file, product=None, document=None):
|
|
|
|
|
"""Unassigns a document and a product association
|
|
|
|
|
|
|
|
|
|
:param product: The object that the document reference or information is
|
|
|
|
|
related to.
|
|
|
|
|
:type product: ifcopenshell.entity_instance.entity_instance
|
|
|
|
|
:param document: The IfcDocumentReference (typically) or in rare cases
|
|
|
|
|
the IfcDocumentInformation that is associated with the product
|
|
|
|
|
:type document: ifcopenshell.entity_instance.entity_instance
|
|
|
|
|
:return: None
|
|
|
|
|
:rtype: None
|
|
|
|
|
|
2023-01-10 10:16:28 +11:00
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code:: python
|
2022-11-23 10:56:12 +09:00
|
|
|
|
|
|
|
|
document = ifcopenshell.api.run("document.add_information", model)
|
|
|
|
|
ifcopenshell.api.run("document.edit_information", model,
|
|
|
|
|
information=document,
|
|
|
|
|
attributes={"Identification": "A-GA-6100", "Name": "Overall Plan",
|
|
|
|
|
"Location": "A-GA-6100 - Overall Plan.pdf"})
|
|
|
|
|
reference = ifcopenshell.api.run("document.add_reference", model, information=document)
|
|
|
|
|
|
|
|
|
|
# Let's imagine storey represents an IfcBuildingStorey for the ground floor
|
2024-04-15 16:32:54 +05:00
|
|
|
ifcopenshell.api.run("document.assign_document", model, products=[storey], document=reference)
|
2022-11-23 10:56:12 +09:00
|
|
|
|
|
|
|
|
# Now let's change our mind and remove the association
|
|
|
|
|
ifcopenshell.api.run("document.unassign_document", model, product=storey, document=reference)
|
|
|
|
|
"""
|
2021-01-23 11:58:29 +11:00
|
|
|
self.file = file
|
|
|
|
|
self.settings = {
|
2022-11-23 10:56:12 +09:00
|
|
|
"product": product,
|
|
|
|
|
"document": document,
|
2021-01-23 11:58:29 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
|
for rel in self.settings["product"].HasAssociations:
|
|
|
|
|
if rel.is_a("IfcRelAssociatesDocument") and rel.RelatingDocument == self.settings["document"]:
|
2023-04-10 22:26:58 +10:00
|
|
|
if len(rel.RelatedObjects) == 1:
|
2023-11-28 10:45:49 +11:00
|
|
|
history = rel.OwnerHistory
|
2023-04-10 22:26:58 +10:00
|
|
|
self.file.remove(rel)
|
2023-11-28 10:45:49 +11:00
|
|
|
if history:
|
|
|
|
|
ifcopenshell.util.element.remove_deep2(self.file, history)
|
2023-04-10 22:26:58 +10:00
|
|
|
else:
|
|
|
|
|
rel.RelatedObjects = [o for o in rel.RelatedObjects if o != self.settings["product"]]
|