2021-11-16 08:54:16 +11:00
|
|
|
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
|
|
|
|
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
|
|
|
|
#
|
|
|
|
|
# This file is part of BlenderBIM Add-on.
|
|
|
|
|
#
|
|
|
|
|
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# BlenderBIM Add-on 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 General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2022-01-29 13:42:46 +11:00
|
|
|
import os
|
2022-01-22 21:00:04 +11:00
|
|
|
import re
|
2021-11-16 08:54:16 +11:00
|
|
|
import bpy
|
2022-01-29 13:42:46 +11:00
|
|
|
import webbrowser
|
2021-11-16 08:54:16 +11:00
|
|
|
import blenderbim.core.tool
|
|
|
|
|
import blenderbim.tool as tool
|
|
|
|
|
import ifcopenshell.util.representation
|
2022-01-29 13:42:46 +11:00
|
|
|
import blenderbim.bim.module.drawing.sheeter as sheeter
|
2021-11-16 08:54:16 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Drawing(blenderbim.core.tool.Drawing):
|
2022-01-29 13:42:46 +11:00
|
|
|
@classmethod
|
|
|
|
|
def create_svg_sheet(cls, document, titleblock):
|
|
|
|
|
sheet_builder = sheeter.SheetBuilder()
|
|
|
|
|
sheet_builder.data_dir = bpy.context.scene.BIMProperties.data_dir
|
|
|
|
|
sheet_builder.create(cls.get_sheet_filename(document), titleblock)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def disable_editing_sheets(cls):
|
|
|
|
|
bpy.context.scene.DocProperties.is_editing_sheets = False
|
|
|
|
|
|
2021-11-16 08:54:16 +11:00
|
|
|
@classmethod
|
|
|
|
|
def disable_editing_text(cls, obj):
|
|
|
|
|
obj.BIMTextProperties.is_editing = False
|
|
|
|
|
|
2022-01-14 18:00:08 +11:00
|
|
|
@classmethod
|
|
|
|
|
def disable_editing_text_product(cls, obj):
|
|
|
|
|
obj.BIMTextProperties.is_editing_product = False
|
|
|
|
|
|
2022-01-29 13:42:46 +11:00
|
|
|
@classmethod
|
|
|
|
|
def enable_editing_sheets(cls):
|
|
|
|
|
bpy.context.scene.DocProperties.is_editing_sheets = True
|
|
|
|
|
|
2021-11-16 08:54:16 +11:00
|
|
|
@classmethod
|
|
|
|
|
def enable_editing_text(cls, obj):
|
|
|
|
|
obj.BIMTextProperties.is_editing = True
|
|
|
|
|
|
2022-01-14 18:00:08 +11:00
|
|
|
@classmethod
|
|
|
|
|
def enable_editing_text_product(cls, obj):
|
|
|
|
|
obj.BIMTextProperties.is_editing_product = True
|
|
|
|
|
|
2022-01-29 13:42:46 +11:00
|
|
|
@classmethod
|
|
|
|
|
def ensure_unique_identification(cls, identification):
|
|
|
|
|
if tool.Ifc.get_schema() == "IFC2X3":
|
|
|
|
|
ids = [d.DocumentId for d in tool.Ifc.get().by_type("IfcDocumentInformation") if d.Scope == "DOCUMENTATION"]
|
|
|
|
|
else:
|
|
|
|
|
ids = [
|
|
|
|
|
d.Identification for d in tool.Ifc.get().by_type("IfcDocumentInformation") if d.Scope == "DOCUMENTATION"
|
|
|
|
|
]
|
|
|
|
|
while identification in ids:
|
|
|
|
|
identification += "-X"
|
|
|
|
|
return identification
|
|
|
|
|
|
2021-11-16 08:54:16 +11:00
|
|
|
@classmethod
|
|
|
|
|
def export_text_literal_attributes(cls, obj):
|
|
|
|
|
return blenderbim.bim.helper.export_attributes(obj.BIMTextProperties.attributes)
|
|
|
|
|
|
2022-01-29 13:42:46 +11:00
|
|
|
@classmethod
|
|
|
|
|
def get_sheet_filename(cls, document):
|
|
|
|
|
if hasattr(document, "Identification"):
|
|
|
|
|
name = document.Identification or "X"
|
|
|
|
|
else:
|
|
|
|
|
name = document.DocumentId or "X"
|
|
|
|
|
name += " - " + document.Name or "Unnamed"
|
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def generate_sheet_identification(cls):
|
|
|
|
|
number = len([d for d in tool.Ifc.get().by_type("IfcDocumentInformation") if d.Scope == "DOCUMENTATION"])
|
|
|
|
|
return "A" + str(number).zfill(2)
|
|
|
|
|
|
2021-11-16 08:54:16 +11:00
|
|
|
@classmethod
|
|
|
|
|
def get_text_literal(cls, obj):
|
|
|
|
|
element = tool.Ifc.get_entity(obj)
|
|
|
|
|
if not element:
|
|
|
|
|
return
|
|
|
|
|
rep = ifcopenshell.util.representation.get_representation(element, "Plan", "Annotation")
|
|
|
|
|
if not rep:
|
|
|
|
|
return
|
|
|
|
|
items = [i for i in rep.Items if i.is_a("IfcTextLiteral")]
|
|
|
|
|
if items:
|
|
|
|
|
return items[0]
|
|
|
|
|
|
2022-01-14 18:00:08 +11:00
|
|
|
@classmethod
|
|
|
|
|
def get_text_product(cls, element):
|
|
|
|
|
for rel in element.HasAssignments:
|
|
|
|
|
if rel.is_a("IfcRelAssignsToProduct"):
|
|
|
|
|
return rel.RelatingProduct
|
|
|
|
|
|
2022-01-29 13:42:46 +11:00
|
|
|
@classmethod
|
|
|
|
|
def import_sheets(cls):
|
|
|
|
|
bpy.context.scene.DocProperties.sheets.clear()
|
|
|
|
|
sheets = [d for d in tool.Ifc.get().by_type("IfcDocumentInformation") if d.Scope == "DOCUMENTATION"]
|
|
|
|
|
for sheet in sheets:
|
|
|
|
|
new = bpy.context.scene.DocProperties.sheets.add()
|
|
|
|
|
new.ifc_definition_id = sheet.id()
|
|
|
|
|
if tool.Ifc.get_schema() == "IFC2X3":
|
|
|
|
|
new.identification = sheet.DocumentId
|
|
|
|
|
else:
|
|
|
|
|
new.identification = sheet.Identification
|
|
|
|
|
new.name = sheet.Name
|
|
|
|
|
|
2021-11-16 08:54:16 +11:00
|
|
|
@classmethod
|
|
|
|
|
def import_text_attributes(cls, obj):
|
|
|
|
|
props = obj.BIMTextProperties
|
|
|
|
|
props.attributes.clear()
|
|
|
|
|
text = cls.get_text_literal(obj)
|
|
|
|
|
blenderbim.bim.helper.import_attributes2(text, props.attributes)
|
|
|
|
|
|
2022-01-14 18:00:08 +11:00
|
|
|
@classmethod
|
|
|
|
|
def import_text_product(cls, obj):
|
|
|
|
|
element = tool.Ifc.get_entity(obj)
|
|
|
|
|
product = cls.get_text_product(element)
|
|
|
|
|
if product:
|
|
|
|
|
obj.BIMTextProperties.relating_product = tool.Ifc.get_object(product)
|
|
|
|
|
else:
|
|
|
|
|
obj.BIMTextProperties.relating_product = None
|
|
|
|
|
|
2022-01-29 13:42:46 +11:00
|
|
|
@classmethod
|
|
|
|
|
def open_with_user_command(cls, user_command, path):
|
|
|
|
|
if user_command:
|
|
|
|
|
commands = eval(user_command)
|
|
|
|
|
for command in commands:
|
|
|
|
|
subprocess.run(command)
|
|
|
|
|
else:
|
|
|
|
|
webbrowser.open("file://" + path)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def open_svg(cls, filename):
|
|
|
|
|
cls.open_with_user_command(
|
|
|
|
|
bpy.context.preferences.addons["blenderbim"].preferences.svg_command,
|
|
|
|
|
os.path.join(bpy.context.scene.BIMProperties.data_dir, "sheets", filename + ".svg"),
|
|
|
|
|
)
|
|
|
|
|
|
2021-11-16 08:54:16 +11:00
|
|
|
@classmethod
|
|
|
|
|
def update_text_value(cls, obj):
|
|
|
|
|
element = cls.get_text_literal(obj)
|
2022-01-22 21:00:04 +11:00
|
|
|
if not element:
|
|
|
|
|
return
|
|
|
|
|
value = element.Literal
|
|
|
|
|
product = cls.get_text_product(tool.Ifc.get_entity(obj))
|
|
|
|
|
if product:
|
|
|
|
|
selector = ifcopenshell.util.selector.Selector()
|
|
|
|
|
variables = {}
|
|
|
|
|
for variable in re.findall("{{.*?}}", value):
|
|
|
|
|
value = value.replace(variable, selector.get_element_value(product, variable[2:-2]) or "")
|
|
|
|
|
obj.BIMTextProperties.value = value
|