Change documents name/identification from UI

Example - https://imgur.com/a/TAkxxSF
This commit is contained in:
Andrej730
2024-12-25 16:58:46 +05:00
parent ff147a4c24
commit 60d6252fe7
3 changed files with 52 additions and 17 deletions
+23 -3
View File
@@ -17,6 +17,7 @@
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
import bpy
import bonsai.tool as tool
from bonsai.bim.prop import StrProperty, Attribute
from bpy.types import PropertyGroup
from bpy.props import (
@@ -31,10 +32,29 @@ from bpy.props import (
)
def update_document_name(self: "Document", context: bpy.types.Context) -> None:
if not self.ifc_definition_id:
return
tool.Ifc.get().by_id(self.ifc_definition_id).Name = self.name
def update_document_identification(self: "Document", context: bpy.types.Context) -> None:
if not self.ifc_definition_id:
return
document = tool.Ifc.get().by_id(self.ifc_definition_id)
if document.is_a("IfcDocumentInformation"):
tool.Document.set_document_information_id(document, self.identification)
else:
tool.Document.set_external_reference_id(document, self.identification)
class Document(PropertyGroup):
name: StringProperty(name="Name")
identification: StringProperty(name="Identification")
is_information: BoolProperty(name="Is Information")
name: StringProperty(name="Name", update=update_document_name)
identification: StringProperty(name="Identification", update=update_document_identification)
is_information: BoolProperty(
name="Is Information",
description="Whether element is IfcDocumentInformation, otherwise it's IfcDocumentReference.",
)
ifc_definition_id: IntProperty(name="IFC Definition ID")
+3 -2
View File
@@ -155,6 +155,7 @@ class BIM_UL_documents(UIList):
row.label(text="", icon="FILE_HIDDEN")
split1 = row.split(factor=0.1)
split1.label(text=item.identification)
# split1.label(text=item.identification)
split1.prop(item, "identification", text="", emboss=False)
split2 = split1.split(factor=0.9)
split2.label(text=item.name)
split2.prop(item, "name", text="", emboss=False)
+26 -12
View File
@@ -94,12 +94,9 @@ class Document(bonsai.core.tool.Document):
element = rel.RelatingDocument
new = props.documents.add()
new.ifc_definition_id = element.id()
new.name = element.Name or "Unnamed"
new["name"] = element.Name or "Unnamed"
new.is_information = True
if tool.Ifc.get_schema() == "IFC2X3":
new.identification = element.DocumentId or "*"
else:
new.identification = element.Identification or "*"
new["identification"] = cls.get_document_information_id(element)
@classmethod
def import_references(cls, document: ifcopenshell.entity_instance) -> None:
@@ -112,8 +109,8 @@ class Document(bonsai.core.tool.Document):
# Use Description + Location instead of Name as IFC has a restriction
# for IfcDocumentReference to have Name only if it has no ReferencedDocument.
name = " - ".join([x for x in [element.Description, element.Location] if x])
new.name = name or "Unnamed"
new.identification = (element.ItemReference if is_ifc2x3 else element.Identification) or "*"
new["name"] = name or "Unnamed"
new["identification"] = cls.get_external_reference_id(element)
new.is_information = False
@classmethod
@@ -123,12 +120,9 @@ class Document(bonsai.core.tool.Document):
for element in document.IsPointer[0].RelatedDocuments or []:
new = props.documents.add()
new.ifc_definition_id = element.id()
new.name = element.Name or "Unnamed"
new["name"] = element.Name or "Unnamed"
new.is_information = True
if tool.Ifc.get_schema() == "IFC2X3":
new.identification = element.DocumentId or "*"
else:
new.identification = element.Identification or "*"
new["identification"] = cls.get_document_information_id(element) or "*"
@classmethod
def is_document_information(cls, document: ifcopenshell.entity_instance) -> bool:
@@ -143,3 +137,23 @@ class Document(bonsai.core.tool.Document):
@classmethod
def set_active_document(cls, document: ifcopenshell.entity_instance) -> None:
bpy.context.scene.BIMDocumentProperties.active_document_id = document.id()
@classmethod
def get_document_information_id(cls, document: ifcopenshell.entity_instance) -> Union[str, None]:
"""Get IfcDocumentInformation.DocumentId/Identification, compatible with IFC2X3."""
return document[0]
@classmethod
def set_document_information_id(cls, document: ifcopenshell.entity_instance, value: Union[str, None]) -> None:
"""Set IfcDocumentInformation.DocumentId/Identification, compatible with IFC2X3."""
document[0] = value
@classmethod
def get_external_reference_id(cls, reference: ifcopenshell.entity_instance) -> Union[str, None]:
"""Get IfcExternalReference.ItemReference/Identification, compatible with IFC2X3."""
return reference[1]
@classmethod
def set_external_reference_id(cls, reference: ifcopenshell.entity_instance, value: Union[str, None]) -> None:
"""Set IfcExternalReference.ItemReference/Identification, compatible with IFC2X3."""
reference[1] = value