mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -15,3 +15,12 @@
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from .add_information import add_information
|
||||
from .add_reference import add_reference
|
||||
from .assign_document import assign_document
|
||||
from .edit_information import edit_information
|
||||
from .edit_reference import edit_reference
|
||||
from .remove_information import remove_information
|
||||
from .remove_reference import remove_reference
|
||||
from .unassign_document import unassign_document
|
||||
|
||||
@@ -19,69 +19,62 @@
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, parent=None):
|
||||
"""Adds a new document information to the project
|
||||
def add_information(file, parent=None) -> None:
|
||||
"""Adds a new document information to the project
|
||||
|
||||
An IFC document information is a document associated with the project.
|
||||
It may be a drawing, specification, schedule, certificate, warranty
|
||||
guarantee, manual, contract, and so on. They are often used for drawings
|
||||
and facility management purposes.
|
||||
An IFC document information is a document associated with the project.
|
||||
It may be a drawing, specification, schedule, certificate, warranty
|
||||
guarantee, manual, contract, and so on. They are often used for drawings
|
||||
and facility management purposes.
|
||||
|
||||
A document may also be a subdocument of a larger document, this is
|
||||
useful for superseding documents or tracking older versions. The parent
|
||||
is considered the latest version and the children are older revisions.
|
||||
A document may also be a subdocument of a larger document, this is
|
||||
useful for superseding documents or tracking older versions. The parent
|
||||
is considered the latest version and the children are older revisions.
|
||||
|
||||
:param parent: The parent document, if necessary.
|
||||
:type parent: ifcopenshell.entity_instance, optional
|
||||
:return: The newly created IfcDocumentInformation entity
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
:param parent: The parent document, if necessary.
|
||||
:type parent: ifcopenshell.entity_instance, optional
|
||||
:return: The newly created IfcDocumentInformation entity
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
document = ifcopenshell.api.run("document.add_information", model)
|
||||
# A document typically has a unique drawing or document name (which
|
||||
# follows a coding system depending on the project), as well as a
|
||||
# title. This should match what is shown on the titleblock or title
|
||||
# page of the document. At a minimum you'd also want to specify a
|
||||
# URI location. The location may be on local, or on a CDE, or any
|
||||
# other platform.
|
||||
ifcopenshell.api.run("document.edit_information", model,
|
||||
information=document,
|
||||
attributes={"Identification": "A-GA-6100", "Name": "Overall Plan",
|
||||
"Location": "A-GA-6100 - Overall Plan.pdf"})
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"parent": parent}
|
||||
document = ifcopenshell.api.run("document.add_information", model)
|
||||
# A document typically has a unique drawing or document name (which
|
||||
# follows a coding system depending on the project), as well as a
|
||||
# title. This should match what is shown on the titleblock or title
|
||||
# page of the document. At a minimum you'd also want to specify a
|
||||
# URI location. The location may be on local, or on a CDE, or any
|
||||
# other platform.
|
||||
ifcopenshell.api.run("document.edit_information", model,
|
||||
information=document,
|
||||
attributes={"Identification": "A-GA-6100", "Name": "Overall Plan",
|
||||
"Location": "A-GA-6100 - Overall Plan.pdf"})
|
||||
"""
|
||||
settings = {"parent": parent}
|
||||
|
||||
def execute(self):
|
||||
id_attribute = "DocumentId" if self.file.schema == "IFC2X3" else "Identification"
|
||||
information = self.file.create_entity(
|
||||
"IfcDocumentInformation", **{id_attribute: "X", "Name": "Unnamed"}
|
||||
id_attribute = "DocumentId" if file.schema == "IFC2X3" else "Identification"
|
||||
information = file.create_entity("IfcDocumentInformation", **{id_attribute: "X", "Name": "Unnamed"})
|
||||
parent = settings["parent"]
|
||||
if not parent and file.by_type("IfcProject"):
|
||||
parent = file.by_type("IfcProject")[0]
|
||||
if parent.is_a("IfcProject") or parent.is_a("IfcContext"):
|
||||
file.create_entity(
|
||||
"IfcRelAssociatesDocument",
|
||||
GlobalId=ifcopenshell.guid.new(),
|
||||
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", file),
|
||||
RelatingDocument=information,
|
||||
RelatedObjects=[parent],
|
||||
)
|
||||
parent = self.settings["parent"]
|
||||
if not parent and self.file.by_type("IfcProject"):
|
||||
parent = self.file.by_type("IfcProject")[0]
|
||||
if parent.is_a("IfcProject") or parent.is_a("IfcContext"):
|
||||
self.file.create_entity(
|
||||
"IfcRelAssociatesDocument",
|
||||
GlobalId=ifcopenshell.guid.new(),
|
||||
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
RelatingDocument=information,
|
||||
RelatedObjects=[parent],
|
||||
elif parent.is_a("IfcDocumentInformation"):
|
||||
if parent.IsPointer:
|
||||
rel = parent.IsPointer[0]
|
||||
documents = set(rel.RelatedDocuments)
|
||||
documents.add(information)
|
||||
rel.RelatedDocuments = list(documents)
|
||||
else:
|
||||
file.create_entity(
|
||||
"IfcDocumentInformationRelationship", RelatingDocument=parent, RelatedDocuments=[information]
|
||||
)
|
||||
elif parent.is_a("IfcDocumentInformation"):
|
||||
if parent.IsPointer:
|
||||
rel = parent.IsPointer[0]
|
||||
documents = set(rel.RelatedDocuments)
|
||||
documents.add(information)
|
||||
rel.RelatedDocuments = list(documents)
|
||||
else:
|
||||
self.file.create_entity(
|
||||
"IfcDocumentInformationRelationship",
|
||||
RelatingDocument=parent,
|
||||
RelatedDocuments=[information]
|
||||
)
|
||||
return information
|
||||
return information
|
||||
|
||||
@@ -19,62 +19,57 @@
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file: ifcopenshell.file, information: ifcopenshell.entity_instance):
|
||||
"""Creates a new reference to a document to assign to products
|
||||
def add_reference(file: ifcopenshell.file, information: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
|
||||
"""Creates a new reference to a document to assign to products
|
||||
|
||||
A document may be associated with physical products, tasks, cost items,
|
||||
and so on. For example, spaces, storeys, and buildings may have a list
|
||||
of associated drawings so you can see which drawings (e.g. plans,
|
||||
sections, details) are documenting that location. Alternatively,
|
||||
equipment may have associated training manuals, operation and
|
||||
maintenance manuals or detailed assembly drawings. Resources may be
|
||||
training certification required, schedules may have gantt charts or bid
|
||||
documents, and so on.
|
||||
A document may be associated with physical products, tasks, cost items,
|
||||
and so on. For example, spaces, storeys, and buildings may have a list
|
||||
of associated drawings so you can see which drawings (e.g. plans,
|
||||
sections, details) are documenting that location. Alternatively,
|
||||
equipment may have associated training manuals, operation and
|
||||
maintenance manuals or detailed assembly drawings. Resources may be
|
||||
training certification required, schedules may have gantt charts or bid
|
||||
documents, and so on.
|
||||
|
||||
In order to associate a document with an object, a reference to that
|
||||
document needs to be created. It could be a reference to the entire
|
||||
document, or a reference to a particular page or chapter. See
|
||||
ifcopenshell.api.document.assign_document for more information.
|
||||
In order to associate a document with an object, a reference to that
|
||||
document needs to be created. It could be a reference to the entire
|
||||
document, or a reference to a particular page or chapter. See
|
||||
ifcopenshell.api.document.assign_document for more information.
|
||||
|
||||
:param information: The IfcDocumentInformation that the reference will
|
||||
be created for
|
||||
:type information: ifcopenshell.entity_instance
|
||||
:return: The newly created IfcDocumentReference entity
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
:param information: The IfcDocumentInformation that the reference will
|
||||
be created for
|
||||
:type information: ifcopenshell.entity_instance
|
||||
:return: The newly created IfcDocumentReference entity
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
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"})
|
||||
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"})
|
||||
|
||||
# In this case, we don't specify any more information, and so the
|
||||
# reference is for the entire document, as opposed to a single page or
|
||||
# chapter or section.
|
||||
reference = ifcopenshell.api.run("document.add_reference", model, information=document)
|
||||
# In this case, we don't specify any more information, and so the
|
||||
# reference is for the entire document, as opposed to a single page or
|
||||
# chapter or section.
|
||||
reference = ifcopenshell.api.run("document.add_reference", model, information=document)
|
||||
|
||||
# Alternatively, we can specify a single section, such as by a
|
||||
# subheading code.
|
||||
reference2 = ifcopenshell.api.run("document.add_reference", model, information=document)
|
||||
ifcopenshell.api.run("document.edit_reference", model,
|
||||
reference=reference2, attributes={"Identification": "2.1.15"})
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"information": information}
|
||||
# Alternatively, we can specify a single section, such as by a
|
||||
# subheading code.
|
||||
reference2 = ifcopenshell.api.run("document.add_reference", model, information=document)
|
||||
ifcopenshell.api.run("document.edit_reference", model,
|
||||
reference=reference2, attributes={"Identification": "2.1.15"})
|
||||
"""
|
||||
settings = {"information": information}
|
||||
|
||||
def execute(self) -> ifcopenshell.entity_instance:
|
||||
if self.file.schema == "IFC2X3":
|
||||
reference = self.file.create_entity("IfcDocumentReference", ItemReference="X")
|
||||
if self.settings["information"]:
|
||||
references = list(self.settings["information"].DocumentReferences or [])
|
||||
references.append(reference)
|
||||
self.settings["information"].DocumentReferences = references
|
||||
return reference
|
||||
return self.file.create_entity(
|
||||
"IfcDocumentReference", ReferencedDocument=self.settings["information"], Identification="X"
|
||||
)
|
||||
if file.schema == "IFC2X3":
|
||||
reference = file.create_entity("IfcDocumentReference", ItemReference="X")
|
||||
if settings["information"]:
|
||||
references = list(settings["information"].DocumentReferences or [])
|
||||
references.append(reference)
|
||||
settings["information"].DocumentReferences = references
|
||||
return reference
|
||||
return file.create_entity("IfcDocumentReference", ReferencedDocument=settings["information"], Identification="X")
|
||||
|
||||
@@ -22,93 +22,85 @@ import ifcopenshell.util.element
|
||||
from typing import Union
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(
|
||||
self,
|
||||
file: ifcopenshell.file,
|
||||
products: list[ifcopenshell.entity_instance],
|
||||
document: ifcopenshell.entity_instance,
|
||||
):
|
||||
"""Assigns a document to a list of products
|
||||
def assign_document(
|
||||
file: ifcopenshell.file,
|
||||
products: list[ifcopenshell.entity_instance],
|
||||
document: ifcopenshell.entity_instance,
|
||||
) -> Union[ifcopenshell.entity_instance, None]:
|
||||
"""Assigns a document to a list of products
|
||||
|
||||
An object may be assigned to zero, one, or multiple documents. Almost
|
||||
any object or property may be assigned to a document, though typically
|
||||
we'd only use it for spaces, types, physical products and schedules.
|
||||
Adding a new assignment is typically done using a document reference and
|
||||
an object. IFC technically allows association with a document
|
||||
information and an object, but this is not encouraged because it is not
|
||||
consistent with other external relationships (such as classification
|
||||
systems or libraries).
|
||||
An object may be assigned to zero, one, or multiple documents. Almost
|
||||
any object or property may be assigned to a document, though typically
|
||||
we'd only use it for spaces, types, physical products and schedules.
|
||||
Adding a new assignment is typically done using a document reference and
|
||||
an object. IFC technically allows association with a document
|
||||
information and an object, but this is not encouraged because it is not
|
||||
consistent with other external relationships (such as classification
|
||||
systems or libraries).
|
||||
|
||||
:param product: The list of objects to associate the document to. This could be
|
||||
almost any sensible object in IFC.
|
||||
:type product: list[ifcopenshell.entity_instance]
|
||||
:param document: The IfcDocumentReference to associate to, or
|
||||
alternatively an IfcDocumentInformation, though this is not
|
||||
recommended.
|
||||
:type document: ifcopenshell.entity_instance
|
||||
:return: The IfcRelAssociatesDocument relationship
|
||||
or `None` if `products` was an empty list or all products were
|
||||
already assigned to the `document`.
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
:param product: The list of objects to associate the document to. This could be
|
||||
almost any sensible object in IFC.
|
||||
:type product: list[ifcopenshell.entity_instance]
|
||||
:param document: The IfcDocumentReference to associate to, or
|
||||
alternatively an IfcDocumentInformation, though this is not
|
||||
recommended.
|
||||
:type document: ifcopenshell.entity_instance
|
||||
:return: The IfcRelAssociatesDocument relationship
|
||||
or `None` if `products` was an empty list or all products were
|
||||
already assigned to the `document`.
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
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)
|
||||
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
|
||||
ifcopenshell.api.run("document.assign_document", model, products=[storey], document=reference)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"products": products,
|
||||
"document": document,
|
||||
}
|
||||
# Let's imagine storey represents an IfcBuildingStorey for the ground floor
|
||||
ifcopenshell.api.run("document.assign_document", model, products=[storey], document=reference)
|
||||
"""
|
||||
settings = {
|
||||
"products": products,
|
||||
"document": document,
|
||||
}
|
||||
|
||||
def execute(self) -> Union[ifcopenshell.entity_instance, None]:
|
||||
# TODO: do we need to support non-ifcroot elements like we do in classification.add_reference?
|
||||
# NOTE: reuses code from `library.assign_reference`
|
||||
# TODO: do we need to support non-ifcroot elements like we do in classification.add_reference?
|
||||
# NOTE: reuses code from `library.assign_reference`
|
||||
|
||||
referenced_elements = ifcopenshell.util.element.get_referenced_elements(self.settings["document"])
|
||||
products: set[ifcopenshell.entity_instance] = set(self.settings["products"])
|
||||
products = products - referenced_elements
|
||||
referenced_elements = ifcopenshell.util.element.get_referenced_elements(settings["document"])
|
||||
products: set[ifcopenshell.entity_instance] = set(settings["products"])
|
||||
products = products - referenced_elements
|
||||
|
||||
if not products:
|
||||
return
|
||||
if not products:
|
||||
return
|
||||
|
||||
if self.file.schema == "IFC2X3":
|
||||
rel = next(
|
||||
(
|
||||
r
|
||||
for r in self.file.by_type("IfcRelAssociatesDocument")
|
||||
if r.RelatingDocument == self.settings["document"]
|
||||
),
|
||||
None,
|
||||
)
|
||||
else:
|
||||
ifc_class = self.settings["document"].is_a()
|
||||
if ifc_class == "IfcDocumentReference":
|
||||
rel = next(iter(self.settings["document"].DocumentRefForObjects), None)
|
||||
elif ifc_class == "IfcDocumentInformation":
|
||||
rel = next(iter(self.settings["document"].DocumentInfoForObjects), None)
|
||||
if file.schema == "IFC2X3":
|
||||
rel = next(
|
||||
(r for r in file.by_type("IfcRelAssociatesDocument") if r.RelatingDocument == settings["document"]),
|
||||
None,
|
||||
)
|
||||
else:
|
||||
ifc_class = settings["document"].is_a()
|
||||
if ifc_class == "IfcDocumentReference":
|
||||
rel = next(iter(settings["document"].DocumentRefForObjects), None)
|
||||
elif ifc_class == "IfcDocumentInformation":
|
||||
rel = next(iter(settings["document"].DocumentInfoForObjects), None)
|
||||
|
||||
if not rel:
|
||||
return self.file.create_entity(
|
||||
"IfcRelAssociatesDocument",
|
||||
GlobalId=ifcopenshell.guid.new(),
|
||||
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
RelatedObjects=list(products),
|
||||
RelatingDocument=self.settings["document"],
|
||||
)
|
||||
if not rel:
|
||||
return file.create_entity(
|
||||
"IfcRelAssociatesDocument",
|
||||
GlobalId=ifcopenshell.guid.new(),
|
||||
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", file),
|
||||
RelatedObjects=list(products),
|
||||
RelatingDocument=settings["document"],
|
||||
)
|
||||
|
||||
related_objects = set(rel.RelatedObjects) | products
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, element=rel)
|
||||
return rel
|
||||
related_objects = set(rel.RelatedObjects) | products
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
ifcopenshell.api.run("owner.update_owner_history", file, element=rel)
|
||||
return rel
|
||||
|
||||
@@ -19,38 +19,34 @@ import ifcopenshell
|
||||
from typing import Any, Optional
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(
|
||||
self,
|
||||
file: ifcopenshell.file,
|
||||
information: ifcopenshell.entity_instance,
|
||||
attributes: Optional[dict[str, Any]] = None,
|
||||
):
|
||||
"""Edits the attributes of an IfcDocumentInformation
|
||||
def edit_information(
|
||||
file: ifcopenshell.file,
|
||||
information: ifcopenshell.entity_instance,
|
||||
attributes: Optional[dict[str, Any]] = None,
|
||||
) -> None:
|
||||
"""Edits the attributes of an IfcDocumentInformation
|
||||
|
||||
For more information about the attributes and data types of an
|
||||
IfcDocumentInformation, consult the IFC documentation.
|
||||
For more information about the attributes and data types of an
|
||||
IfcDocumentInformation, consult the IFC documentation.
|
||||
|
||||
:param reference: The IfcDocumentInformation entity you want to edit
|
||||
:type reference: ifcopenshell.entity_instance
|
||||
:param attributes: a dictionary of attribute names and values.
|
||||
:type attributes: dict, optional
|
||||
:return: None
|
||||
:rtype: None
|
||||
:param reference: The IfcDocumentInformation entity you want to edit
|
||||
:type reference: ifcopenshell.entity_instance
|
||||
:param attributes: a dictionary of attribute names and values.
|
||||
:type attributes: dict, optional
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
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"})
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"information": information, "attributes": attributes or {}}
|
||||
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"})
|
||||
"""
|
||||
settings = {"information": information, "attributes": attributes or {}}
|
||||
|
||||
def execute(self) -> None:
|
||||
for name, value in self.settings["attributes"].items():
|
||||
setattr(self.settings["information"], name, value)
|
||||
for name, value in settings["attributes"].items():
|
||||
setattr(settings["information"], name, value)
|
||||
|
||||
@@ -19,41 +19,37 @@ import ifcopenshell
|
||||
from typing import Any, Optional
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(
|
||||
self,
|
||||
file: ifcopenshell.file,
|
||||
reference: ifcopenshell.entity_instance,
|
||||
attributes: Optional[dict[str, Any]] = None,
|
||||
):
|
||||
"""Edits the attributes of an IfcDocumentReference
|
||||
def edit_reference(
|
||||
file: ifcopenshell.file,
|
||||
reference: ifcopenshell.entity_instance,
|
||||
attributes: Optional[dict[str, Any]] = None,
|
||||
) -> None:
|
||||
"""Edits the attributes of an IfcDocumentReference
|
||||
|
||||
For more information about the attributes and data types of an
|
||||
IfcDocumentReference, consult the IFC documentation.
|
||||
For more information about the attributes and data types of an
|
||||
IfcDocumentReference, consult the IFC documentation.
|
||||
|
||||
:param reference: The IfcDocumentReference entity you want to edit
|
||||
:type reference: ifcopenshell.entity_instance
|
||||
:param attributes: a dictionary of attribute names and values.
|
||||
:type attributes: dict, optional
|
||||
:return: None
|
||||
:rtype: None
|
||||
:param reference: The IfcDocumentReference entity you want to edit
|
||||
:type reference: ifcopenshell.entity_instance
|
||||
:param attributes: a dictionary of attribute names and values.
|
||||
:type attributes: dict, optional
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
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)
|
||||
ifcopenshell.api.run("document.edit_reference", model,
|
||||
reference=reference, attributes={"Identification": "2.1.15"})
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"reference": reference, "attributes": attributes or {}}
|
||||
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)
|
||||
ifcopenshell.api.run("document.edit_reference", model,
|
||||
reference=reference, attributes={"Identification": "2.1.15"})
|
||||
"""
|
||||
settings = {"reference": reference, "attributes": attributes or {}}
|
||||
|
||||
def execute(self) -> None:
|
||||
for name, value in self.settings["attributes"].items():
|
||||
setattr(self.settings["reference"], name, value)
|
||||
for name, value in settings["attributes"].items():
|
||||
setattr(settings["reference"], name, value)
|
||||
|
||||
@@ -22,45 +22,42 @@ import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, information=None):
|
||||
"""Removes a document information
|
||||
def remove_information(file, information=None) -> None:
|
||||
"""Removes a document information
|
||||
|
||||
All references and associations are also removed.
|
||||
All references and associations are also removed.
|
||||
|
||||
:param information: The IfcDocumentInformation to remove
|
||||
:type information: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
:param information: The IfcDocumentInformation to remove
|
||||
:type information: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
# Add a document
|
||||
document = ifcopenshell.api.run("document.add_information", model)
|
||||
# ... and remove it!
|
||||
ifcopenshell.api.run("document.remove_information", model, information=document)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"information": information}
|
||||
# Add a document
|
||||
document = ifcopenshell.api.run("document.add_information", model)
|
||||
# ... and remove it!
|
||||
ifcopenshell.api.run("document.remove_information", model, information=document)
|
||||
"""
|
||||
settings = {"information": information}
|
||||
|
||||
def execute(self):
|
||||
for reference in self.settings["information"].HasDocumentReferences or []:
|
||||
ifcopenshell.api.run("document.remove_reference", self.file, reference=reference)
|
||||
for reference in settings["information"].HasDocumentReferences or []:
|
||||
ifcopenshell.api.run("document.remove_reference", file, reference=reference)
|
||||
|
||||
for rel in self.settings["information"].IsPointer or []:
|
||||
for information in rel.RelatedDocuments:
|
||||
ifcopenshell.api.run("document.remove_information", self.file, information=information)
|
||||
for rel in settings["information"].IsPointer or []:
|
||||
for information in rel.RelatedDocuments:
|
||||
ifcopenshell.api.run("document.remove_information", file, information=information)
|
||||
|
||||
for rel in self.settings["information"].IsPointedTo or []:
|
||||
if rel.RelatedDocuments == (self.settings["information"],):
|
||||
# This relationship is non-rooted
|
||||
self.file.remove(rel)
|
||||
for rel in settings["information"].IsPointedTo or []:
|
||||
if rel.RelatedDocuments == (settings["information"],):
|
||||
# This relationship is non-rooted
|
||||
file.remove(rel)
|
||||
|
||||
for rel in self.settings["information"].DocumentInfoForObjects or []:
|
||||
history = rel.OwnerHistory
|
||||
self.file.remove(rel)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(self.file, history)
|
||||
self.file.remove(self.settings["information"])
|
||||
for rel in settings["information"].DocumentInfoForObjects or []:
|
||||
history = rel.OwnerHistory
|
||||
file.remove(rel)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(file, history)
|
||||
file.remove(settings["information"])
|
||||
|
||||
@@ -20,32 +20,29 @@ import ifcopenshell
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file: ifcopenshell.file, reference: ifcopenshell.entity_instance):
|
||||
"""Remove a document reference
|
||||
def remove_reference(file: ifcopenshell.file, reference: ifcopenshell.entity_instance) -> None:
|
||||
"""Remove a document reference
|
||||
|
||||
All associations with objects are removed.
|
||||
All associations with objects are removed.
|
||||
|
||||
:param reference: The IfcDocumentReference to remove
|
||||
:type reference: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
:param reference: The IfcDocumentReference to remove
|
||||
:type reference: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
document = ifcopenshell.api.run("document.add_information", model)
|
||||
reference = ifcopenshell.api.run("document.add_reference", model, information=document)
|
||||
ifcopenshell.api.run("document.remove_reference", model, reference=reference)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"reference": reference}
|
||||
document = ifcopenshell.api.run("document.add_information", model)
|
||||
reference = ifcopenshell.api.run("document.add_reference", model, information=document)
|
||||
ifcopenshell.api.run("document.remove_reference", model, reference=reference)
|
||||
"""
|
||||
settings = {"reference": reference}
|
||||
|
||||
def execute(self) -> None:
|
||||
for rel in self.settings["reference"].DocumentRefForObjects or []:
|
||||
history = rel.OwnerHistory
|
||||
self.file.remove(rel)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(self.file, history)
|
||||
self.file.remove(self.settings["reference"])
|
||||
for rel in settings["reference"].DocumentRefForObjects or []:
|
||||
history = rel.OwnerHistory
|
||||
file.remove(rel)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(file, history)
|
||||
file.remove(settings["reference"])
|
||||
|
||||
@@ -21,69 +21,65 @@ import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(
|
||||
self,
|
||||
file: ifcopenshell.file,
|
||||
products: list[ifcopenshell.entity_instance],
|
||||
document: ifcopenshell.entity_instance,
|
||||
):
|
||||
"""Unassigns a document and an association to the list of products
|
||||
def unassign_document(
|
||||
file: ifcopenshell.file,
|
||||
products: list[ifcopenshell.entity_instance],
|
||||
document: ifcopenshell.entity_instance,
|
||||
) -> None:
|
||||
"""Unassigns a document and an association to the list of products
|
||||
|
||||
:param product: The list of objects that the document reference or information is
|
||||
related to.
|
||||
:type product: list[ifcopenshell.entity_instance]
|
||||
:param document: The IfcDocumentReference (typically) or in rare cases
|
||||
the IfcDocumentInformation that is associated with the product
|
||||
:type document: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
:param product: The list of objects that the document reference or information is
|
||||
related to.
|
||||
:type product: list[ifcopenshell.entity_instance]
|
||||
:param document: The IfcDocumentReference (typically) or in rare cases
|
||||
the IfcDocumentInformation that is associated with the product
|
||||
:type document: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
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)
|
||||
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
|
||||
ifcopenshell.api.run("document.assign_document", model, products=[storey], document=reference)
|
||||
# Let's imagine storey represents an IfcBuildingStorey for the ground floor
|
||||
ifcopenshell.api.run("document.assign_document", model, products=[storey], document=reference)
|
||||
|
||||
# Now let's change our mind and remove the association
|
||||
ifcopenshell.api.run("document.unassign_document", model, products=[storey], document=reference)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"products": products,
|
||||
"document": document,
|
||||
}
|
||||
# Now let's change our mind and remove the association
|
||||
ifcopenshell.api.run("document.unassign_document", model, products=[storey], document=reference)
|
||||
"""
|
||||
settings = {
|
||||
"products": products,
|
||||
"document": document,
|
||||
}
|
||||
|
||||
def execute(self):
|
||||
# TODO: do we need to support non-ifcroot elements like we do in classification.add_reference?
|
||||
# NOTE: reuses code from `library.un assign_reference`
|
||||
# TODO: do we need to support non-ifcroot elements like we do in classification.add_reference?
|
||||
# NOTE: reuses code from `library.un assign_reference`
|
||||
|
||||
reference_rels: set[ifcopenshell.entity_instance] = set()
|
||||
products = set(self.settings["products"])
|
||||
for product in products:
|
||||
reference_rels.update(product.HasAssociations)
|
||||
reference_rels: set[ifcopenshell.entity_instance] = set()
|
||||
products = set(settings["products"])
|
||||
for product in products:
|
||||
reference_rels.update(product.HasAssociations)
|
||||
|
||||
reference_rels = {
|
||||
rel
|
||||
for rel in reference_rels
|
||||
if rel.is_a("IfcRelAssociatesDocument") and rel.RelatingDocument == self.settings["document"]
|
||||
}
|
||||
reference_rels = {
|
||||
rel
|
||||
for rel in reference_rels
|
||||
if rel.is_a("IfcRelAssociatesDocument") and rel.RelatingDocument == settings["document"]
|
||||
}
|
||||
|
||||
for rel in reference_rels:
|
||||
related_objects = set(rel.RelatedObjects) - products
|
||||
if related_objects:
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|
||||
else:
|
||||
history = rel.OwnerHistory
|
||||
self.file.remove(rel)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(self.file, history)
|
||||
for rel in reference_rels:
|
||||
related_objects = set(rel.RelatedObjects) - products
|
||||
if related_objects:
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": rel})
|
||||
else:
|
||||
history = rel.OwnerHistory
|
||||
file.remove(rel)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(file, history)
|
||||
|
||||
Reference in New Issue
Block a user