mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 18:21:59 +00:00
Change documents name/identification from UI
Example - https://imgur.com/a/TAkxxSF
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
import bonsai.tool as tool
|
||||||
from bonsai.bim.prop import StrProperty, Attribute
|
from bonsai.bim.prop import StrProperty, Attribute
|
||||||
from bpy.types import PropertyGroup
|
from bpy.types import PropertyGroup
|
||||||
from bpy.props import (
|
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):
|
class Document(PropertyGroup):
|
||||||
name: StringProperty(name="Name")
|
name: StringProperty(name="Name", update=update_document_name)
|
||||||
identification: StringProperty(name="Identification")
|
identification: StringProperty(name="Identification", update=update_document_identification)
|
||||||
is_information: BoolProperty(name="Is Information")
|
is_information: BoolProperty(
|
||||||
|
name="Is Information",
|
||||||
|
description="Whether element is IfcDocumentInformation, otherwise it's IfcDocumentReference.",
|
||||||
|
)
|
||||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ class BIM_UL_documents(UIList):
|
|||||||
row.label(text="", icon="FILE_HIDDEN")
|
row.label(text="", icon="FILE_HIDDEN")
|
||||||
|
|
||||||
split1 = row.split(factor=0.1)
|
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 = split1.split(factor=0.9)
|
||||||
split2.label(text=item.name)
|
split2.prop(item, "name", text="", emboss=False)
|
||||||
|
|||||||
@@ -94,12 +94,9 @@ class Document(bonsai.core.tool.Document):
|
|||||||
element = rel.RelatingDocument
|
element = rel.RelatingDocument
|
||||||
new = props.documents.add()
|
new = props.documents.add()
|
||||||
new.ifc_definition_id = element.id()
|
new.ifc_definition_id = element.id()
|
||||||
new.name = element.Name or "Unnamed"
|
new["name"] = element.Name or "Unnamed"
|
||||||
new.is_information = True
|
new.is_information = True
|
||||||
if tool.Ifc.get_schema() == "IFC2X3":
|
new["identification"] = cls.get_document_information_id(element)
|
||||||
new.identification = element.DocumentId or "*"
|
|
||||||
else:
|
|
||||||
new.identification = element.Identification or "*"
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def import_references(cls, document: ifcopenshell.entity_instance) -> None:
|
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
|
# Use Description + Location instead of Name as IFC has a restriction
|
||||||
# for IfcDocumentReference to have Name only if it has no ReferencedDocument.
|
# for IfcDocumentReference to have Name only if it has no ReferencedDocument.
|
||||||
name = " - ".join([x for x in [element.Description, element.Location] if x])
|
name = " - ".join([x for x in [element.Description, element.Location] if x])
|
||||||
new.name = name or "Unnamed"
|
new["name"] = name or "Unnamed"
|
||||||
new.identification = (element.ItemReference if is_ifc2x3 else element.Identification) or "*"
|
new["identification"] = cls.get_external_reference_id(element)
|
||||||
new.is_information = False
|
new.is_information = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -123,12 +120,9 @@ class Document(bonsai.core.tool.Document):
|
|||||||
for element in document.IsPointer[0].RelatedDocuments or []:
|
for element in document.IsPointer[0].RelatedDocuments or []:
|
||||||
new = props.documents.add()
|
new = props.documents.add()
|
||||||
new.ifc_definition_id = element.id()
|
new.ifc_definition_id = element.id()
|
||||||
new.name = element.Name or "Unnamed"
|
new["name"] = element.Name or "Unnamed"
|
||||||
new.is_information = True
|
new.is_information = True
|
||||||
if tool.Ifc.get_schema() == "IFC2X3":
|
new["identification"] = cls.get_document_information_id(element) or "*"
|
||||||
new.identification = element.DocumentId or "*"
|
|
||||||
else:
|
|
||||||
new.identification = element.Identification or "*"
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_document_information(cls, document: ifcopenshell.entity_instance) -> bool:
|
def is_document_information(cls, document: ifcopenshell.entity_instance) -> bool:
|
||||||
@@ -143,3 +137,23 @@ class Document(bonsai.core.tool.Document):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def set_active_document(cls, document: ifcopenshell.entity_instance) -> None:
|
def set_active_document(cls, document: ifcopenshell.entity_instance) -> None:
|
||||||
bpy.context.scene.BIMDocumentProperties.active_document_id = document.id()
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user