mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 17:57:02 +00:00
See #2516. Titleblocks dropdown now also shows project titleblocks.
This commit is contained in:
@@ -16,10 +16,12 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# 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/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import os
|
||||||
import bpy
|
import bpy
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
import ifcopenshell.util.representation
|
import ifcopenshell.util.representation
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def refresh():
|
def refresh():
|
||||||
@@ -56,13 +58,29 @@ class SheetsData:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls):
|
def load(cls):
|
||||||
cls.data = {"total_sheets": cls.total_sheets()}
|
cls.data = {"total_sheets": cls.total_sheets(), "titleblocks": cls.titleblocks()}
|
||||||
cls.is_loaded = True
|
cls.is_loaded = True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def total_sheets(cls):
|
def total_sheets(cls):
|
||||||
return len([d for d in tool.Ifc.get().by_type("IfcDocumentInformation") if d.Scope == "SHEET"])
|
return len([d for d in tool.Ifc.get().by_type("IfcDocumentInformation") if d.Scope == "SHEET"])
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def titleblocks(cls):
|
||||||
|
files = Path(os.path.join(bpy.context.scene.BIMProperties.data_dir, "templates", "titleblocks")).glob("*.svg")
|
||||||
|
files = [str(f.stem) for f in files]
|
||||||
|
|
||||||
|
if tool.Ifc.get():
|
||||||
|
project = tool.Ifc.get().by_type("IfcProject")[0]
|
||||||
|
titleblocks_dir = ifcopenshell.util.element.get_pset(project, "BBIM_Documentation", "TitleblocksDir")
|
||||||
|
if not titleblocks_dir:
|
||||||
|
titleblocks_dir = bpy.context.scene.DocProperties.titleblocks_dir
|
||||||
|
titleblocks_dir = tool.Ifc.resolve_uri(titleblocks_dir)
|
||||||
|
if os.path.exists(titleblocks_dir):
|
||||||
|
files.extend([str(f.stem) for f in Path(titleblocks_dir).glob("*.svg")])
|
||||||
|
|
||||||
|
return [(f, f, "") for f in sorted(list(set(files)))]
|
||||||
|
|
||||||
|
|
||||||
class DrawingsData:
|
class DrawingsData:
|
||||||
data = {}
|
data = {}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import blenderbim.tool as tool
|
|||||||
import blenderbim.core.drawing as core
|
import blenderbim.core.drawing as core
|
||||||
import blenderbim.bim.module.drawing.annotation as annotation
|
import blenderbim.bim.module.drawing.annotation as annotation
|
||||||
import blenderbim.bim.module.drawing.decoration as decoration
|
import blenderbim.bim.module.drawing.decoration as decoration
|
||||||
from blenderbim.bim.module.drawing.data import DrawingsData, DecoratorData
|
from blenderbim.bim.module.drawing.data import DrawingsData, DecoratorData, SheetsData
|
||||||
from blenderbim.bim.module.drawing.data import refresh as refresh_drawing_data
|
from blenderbim.bim.module.drawing.data import refresh as refresh_drawing_data
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from blenderbim.bim.prop import Attribute, StrProperty
|
from blenderbim.bim.prop import Attribute, StrProperty
|
||||||
@@ -44,18 +44,15 @@ from bpy.props import (
|
|||||||
|
|
||||||
|
|
||||||
diagram_scales_enum = []
|
diagram_scales_enum = []
|
||||||
titleblocks_enum = []
|
|
||||||
sheets_enum = []
|
sheets_enum = []
|
||||||
vector_styles_enum = []
|
vector_styles_enum = []
|
||||||
|
|
||||||
|
|
||||||
def purge():
|
def purge():
|
||||||
global diagram_scales_enum
|
global diagram_scales_enum
|
||||||
global titleblocks_enum
|
|
||||||
global sheets_enum
|
global sheets_enum
|
||||||
global vector_styles_enum
|
global vector_styles_enum
|
||||||
diagram_scales_enum = []
|
diagram_scales_enum = []
|
||||||
titleblocks_enum = []
|
|
||||||
sheets_enum = []
|
sheets_enum = []
|
||||||
vector_styles_enum = []
|
vector_styles_enum = []
|
||||||
|
|
||||||
@@ -191,20 +188,14 @@ def update_layer(self, context, name, value):
|
|||||||
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={name: value})
|
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={name: value})
|
||||||
|
|
||||||
|
|
||||||
def getTitleblocks(self, context):
|
def get_titleblocks(self, context):
|
||||||
global titleblocks_enum
|
if not SheetsData.is_loaded:
|
||||||
if len(titleblocks_enum) < 1:
|
SheetsData.load()
|
||||||
titleblocks_enum.clear()
|
return SheetsData.data["titleblocks"]
|
||||||
files = Path(os.path.join(context.scene.BIMProperties.data_dir, "templates", "titleblocks")).glob("*.svg")
|
|
||||||
files = sorted([str(f.stem) for f in files])
|
|
||||||
titleblocks_enum.extend([(f, f, "") for f in files])
|
|
||||||
return titleblocks_enum
|
|
||||||
|
|
||||||
|
|
||||||
def refreshTitleblocks(self, context):
|
def update_titleblocks(self, context):
|
||||||
global titleblocks_enum
|
SheetsData.data["titleblocks"] = SheetsData.titleblocks()
|
||||||
titleblocks_enum.clear()
|
|
||||||
getTitleblocks(self, context)
|
|
||||||
|
|
||||||
|
|
||||||
def toggleDecorations(self, context):
|
def toggleDecorations(self, context):
|
||||||
@@ -327,7 +318,7 @@ class DocProperties(PropertyGroup):
|
|||||||
current_drawing_index: IntProperty(name="Current Drawing Index")
|
current_drawing_index: IntProperty(name="Current Drawing Index")
|
||||||
schedules: CollectionProperty(name="Schedules", type=Schedule)
|
schedules: CollectionProperty(name="Schedules", type=Schedule)
|
||||||
active_schedule_index: IntProperty(name="Active Schedule Index")
|
active_schedule_index: IntProperty(name="Active Schedule Index")
|
||||||
titleblock: EnumProperty(items=getTitleblocks, name="Titleblock", update=refreshTitleblocks)
|
titleblock: EnumProperty(items=get_titleblocks, name="Titleblock", update=update_titleblocks)
|
||||||
is_editing_sheets: BoolProperty(name="Is Editing Sheets", default=False)
|
is_editing_sheets: BoolProperty(name="Is Editing Sheets", default=False)
|
||||||
sheets: CollectionProperty(name="Sheets", type=Sheet)
|
sheets: CollectionProperty(name="Sheets", type=Sheet)
|
||||||
active_sheet_index: IntProperty(name="Active Sheet Index")
|
active_sheet_index: IntProperty(name="Active Sheet Index")
|
||||||
|
|||||||
@@ -35,18 +35,22 @@ class SheetBuilder:
|
|||||||
self.scale = "NTS"
|
self.scale = "NTS"
|
||||||
|
|
||||||
def create(self, layout_path, titleblock_name):
|
def create(self, layout_path, titleblock_name):
|
||||||
sheet_dir = os.path.dirname(layout_path)
|
|
||||||
|
|
||||||
root = ET.Element("svg")
|
root = ET.Element("svg")
|
||||||
root.attrib["xmlns"] = "http://www.w3.org/2000/svg"
|
root.attrib["xmlns"] = "http://www.w3.org/2000/svg"
|
||||||
root.attrib["xmlns:xlink"] = "http://www.w3.org/1999/xlink"
|
root.attrib["xmlns:xlink"] = "http://www.w3.org/1999/xlink"
|
||||||
root.attrib["id"] = "root"
|
root.attrib["id"] = "root"
|
||||||
root.attrib["version"] = "1.1"
|
root.attrib["version"] = "1.1"
|
||||||
|
|
||||||
|
sheet_dir = os.path.dirname(layout_path)
|
||||||
ootb_titleblock_path = os.path.join(self.data_dir, "templates", "titleblocks", titleblock_name + ".svg")
|
ootb_titleblock_path = os.path.join(self.data_dir, "templates", "titleblocks", titleblock_name + ".svg")
|
||||||
titleblock_path = tool.Ifc.resolve_uri(tool.Drawing.get_default_titleblock_path(titleblock_name))
|
titleblock_path = tool.Ifc.resolve_uri(tool.Drawing.get_default_titleblock_path(titleblock_name))
|
||||||
|
|
||||||
view_root = ET.parse(ootb_titleblock_path).getroot()
|
os.makedirs(sheet_dir, exist_ok=True)
|
||||||
|
os.makedirs(os.path.dirname(titleblock_path), exist_ok=True)
|
||||||
|
if not os.path.exists(titleblock_path):
|
||||||
|
shutil.copy(ootb_titleblock_path, titleblock_path)
|
||||||
|
|
||||||
|
view_root = ET.parse(titleblock_path).getroot()
|
||||||
view_width = self.convert_to_mm(view_root.attrib.get("width"))
|
view_width = self.convert_to_mm(view_root.attrib.get("width"))
|
||||||
view_height = self.convert_to_mm(view_root.attrib.get("height"))
|
view_height = self.convert_to_mm(view_root.attrib.get("height"))
|
||||||
view = ET.SubElement(root, "g")
|
view = ET.SubElement(root, "g")
|
||||||
@@ -62,11 +66,6 @@ class SheetBuilder:
|
|||||||
root.attrib["height"] = "{}mm".format(view_height)
|
root.attrib["height"] = "{}mm".format(view_height)
|
||||||
root.attrib["viewBox"] = "0 0 {} {}".format(view_width, view_height)
|
root.attrib["viewBox"] = "0 0 {} {}".format(view_width, view_height)
|
||||||
|
|
||||||
os.makedirs(sheet_dir, exist_ok=True)
|
|
||||||
os.makedirs(os.path.dirname(titleblock_path), exist_ok=True)
|
|
||||||
if not os.path.exists(titleblock_path):
|
|
||||||
shutil.copy(ootb_titleblock_path, titleblock_path)
|
|
||||||
|
|
||||||
with open(layout_path, "w") as f:
|
with open(layout_path, "w") as f:
|
||||||
f.write(minidom.parseString(ET.tostring(root)).toprettyxml(indent=" "))
|
f.write(minidom.parseString(ET.tostring(root)).toprettyxml(indent=" "))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user