mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 17:57:02 +00:00
Fix #976. Bug where project data dir was not very customisable without running into issues.
This commit is contained in:
@@ -23,7 +23,6 @@ from pathlib import Path
|
|||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from . import schema
|
|
||||||
|
|
||||||
|
|
||||||
class FileCopy(threading.Thread):
|
class FileCopy(threading.Thread):
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import blenderbim.bim.schema # refactor
|
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from blenderbim.bim.prop import StrProperty, Attribute
|
from blenderbim.bim.prop import StrProperty, Attribute
|
||||||
from bpy.types import PropertyGroup
|
from bpy.types import PropertyGroup
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class SheetBuilder:
|
|||||||
self.scale = "NTS"
|
self.scale = "NTS"
|
||||||
|
|
||||||
def create(self, name, titleblock_name):
|
def create(self, name, titleblock_name):
|
||||||
sheet_path = "{}sheets/{}.svg".format(self.data_dir, name)
|
sheet_path = os.path.join(self.data_dir, f"{name}.svg")
|
||||||
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"
|
||||||
@@ -121,9 +121,9 @@ class SheetBuilder:
|
|||||||
title.attrib["height"] = str(self.convert_to_mm(title_root.attrib.get("height")))
|
title.attrib["height"] = str(self.convert_to_mm(title_root.attrib.get("height")))
|
||||||
|
|
||||||
def build(self, sheet_name):
|
def build(self, sheet_name):
|
||||||
os.makedirs("{}build/{}/".format(self.data_dir, sheet_name), exist_ok=True)
|
os.makedirs(os.path.join(self.data_dir, "build", sheet_name), exist_ok=True)
|
||||||
|
|
||||||
sheet_path = "{}sheets/{}.svg".format(self.data_dir, sheet_name)
|
sheet_path = os.path.join(self.data_dir, "sheets", f"{sheet_name}.svg")
|
||||||
|
|
||||||
ET.register_namespace("", "http://www.w3.org/2000/svg")
|
ET.register_namespace("", "http://www.w3.org/2000/svg")
|
||||||
ET.register_namespace("xlink", "http://www.w3.org/1999/xlink")
|
ET.register_namespace("xlink", "http://www.w3.org/1999/xlink")
|
||||||
@@ -140,7 +140,7 @@ class SheetBuilder:
|
|||||||
self.build_drawings(root.findall('{http://www.w3.org/2000/svg}g[@data-type="drawing"]'), sheet_name)
|
self.build_drawings(root.findall('{http://www.w3.org/2000/svg}g[@data-type="drawing"]'), sheet_name)
|
||||||
self.build_schedules(root.findall('{http://www.w3.org/2000/svg}g[@data-type="schedule"]'))
|
self.build_schedules(root.findall('{http://www.w3.org/2000/svg}g[@data-type="schedule"]'))
|
||||||
|
|
||||||
with open("{}build/{}/{}.svg".format(self.data_dir, sheet_name, sheet_name), "wb") as output:
|
with open(os.path.join(self.data_dir, "build", sheet_name, f"{sheet_name}.svg"), "wb") as output:
|
||||||
tree.write(output)
|
tree.write(output)
|
||||||
|
|
||||||
def build_drawings(self, drawings, sheet_name):
|
def build_drawings(self, drawings, sheet_name):
|
||||||
@@ -155,8 +155,9 @@ class SheetBuilder:
|
|||||||
view.append(self.parse_embedded_svg(foreground, {}))
|
view.append(self.parse_embedded_svg(foreground, {}))
|
||||||
|
|
||||||
# Add background
|
# Add background
|
||||||
background_path = "{}sheets/{}".format(self.data_dir, self.get_href(background))
|
background_path = os.path.join(self.data_dir, "sheets", self.get_href(background))
|
||||||
copy(background_path, "{}build/{}/".format(self.data_dir, sheet_name))
|
|
||||||
|
copy(background_path, os.path.join(self.data_dir, "build", sheet_name))
|
||||||
|
|
||||||
# Add view title
|
# Add view title
|
||||||
foreground_path = self.get_href(foreground)
|
foreground_path = self.get_href(foreground)
|
||||||
@@ -202,7 +203,7 @@ class SheetBuilder:
|
|||||||
self.convert_to_mm(image.attrib.get("x")), self.convert_to_mm(image.attrib.get("y"))
|
self.convert_to_mm(image.attrib.get("x")), self.convert_to_mm(image.attrib.get("y"))
|
||||||
)
|
)
|
||||||
svg_path = self.get_href(image)
|
svg_path = self.get_href(image)
|
||||||
with open("{}sheets/{}".format(self.data_dir, svg_path), "r") as template:
|
with open(os.path.join(self.data_dir, "sheets", svg_path), "r") as template:
|
||||||
embedded = ET.fromstring(pystache.render(template.read(), data))
|
embedded = ET.fromstring(pystache.render(template.read(), data))
|
||||||
# viewBox should not be nested
|
# viewBox should not be nested
|
||||||
embedded.attrib["viewBox"] = ""
|
embedded.attrib["viewBox"] = ""
|
||||||
|
|||||||
@@ -79,23 +79,23 @@ class SvgWriter:
|
|||||||
self.height = self.raw_height * self.scale
|
self.height = self.raw_height * self.scale
|
||||||
|
|
||||||
def add_stylesheet(self):
|
def add_stylesheet(self):
|
||||||
with open("{}styles/{}.css".format(self.data_dir, self.vector_style), "r") as stylesheet:
|
with open(os.path.join(self.data_dir, "styles", f"{self.vector_style}.css"), "r") as stylesheet:
|
||||||
self.svg.defs.add(self.svg.style(stylesheet.read()))
|
self.svg.defs.add(self.svg.style(stylesheet.read()))
|
||||||
|
|
||||||
def add_markers(self):
|
def add_markers(self):
|
||||||
tree = ET.parse("{}templates/markers.svg".format(self.data_dir))
|
tree = ET.parse(os.path.join(self.data_dir, "templates", "markers.svg"))
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
for child in root.getchildren():
|
for child in root.getchildren():
|
||||||
self.svg.defs.add(External(child))
|
self.svg.defs.add(External(child))
|
||||||
|
|
||||||
def add_symbols(self):
|
def add_symbols(self):
|
||||||
tree = ET.parse("{}templates/symbols.svg".format(self.data_dir))
|
tree = ET.parse(os.path.join(self.data_dir, "templates", "symbols.svg"))
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
for child in root.getchildren():
|
for child in root.getchildren():
|
||||||
self.svg.defs.add(External(child))
|
self.svg.defs.add(External(child))
|
||||||
|
|
||||||
def add_patterns(self):
|
def add_patterns(self):
|
||||||
tree = ET.parse("{}templates/patterns.svg".format(self.data_dir))
|
tree = ET.parse(os.path.join(self.data_dir, "templates", "patterns.svg"))
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
for child in root.getchildren():
|
for child in root.getchildren():
|
||||||
self.svg.defs.add(External(child))
|
self.svg.defs.add(External(child))
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import blenderbim.bim.schema # refactor
|
|
||||||
from ifcopenshell.api.material.data import Data
|
from ifcopenshell.api.material.data import Data
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from blenderbim.bim.prop import StrProperty, Attribute
|
from blenderbim.bim.prop import StrProperty, Attribute
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
import bpy
|
import bpy
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ class ExecuteIfcPatch(bpy.types.Operator):
|
|||||||
"output": context.scene.BIMPatchProperties.ifc_patch_output,
|
"output": context.scene.BIMPatchProperties.ifc_patch_output,
|
||||||
"recipe": context.scene.BIMPatchProperties.ifc_patch_recipes,
|
"recipe": context.scene.BIMPatchProperties.ifc_patch_recipes,
|
||||||
"arguments": json.loads(context.scene.BIMPatchProperties.ifc_patch_args or "[]"),
|
"arguments": json.loads(context.scene.BIMPatchProperties.ifc_patch_args or "[]"),
|
||||||
"log": context.scene.BIMProperties.data_dir + "process.log",
|
"log": os.path.join(context.scene.BIMProperties.data_dir, "process.log"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class ExportIFC(bpy.types.Operator):
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
logger = logging.getLogger("ExportIFC")
|
logger = logging.getLogger("ExportIFC")
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
filename=context.scene.BIMProperties.data_dir + "process.log", filemode="a", level=logging.DEBUG
|
filename=os.path.join(context.scene.BIMProperties.data_dir, "process.log"), filemode="a", level=logging.DEBUG
|
||||||
)
|
)
|
||||||
extension = self.filepath.split(".")[-1]
|
extension = self.filepath.split(".")[-1]
|
||||||
if extension == "ifczip":
|
if extension == "ifczip":
|
||||||
@@ -98,7 +98,7 @@ class ImportIFC(bpy.types.Operator, ImportHelper):
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
logger = logging.getLogger("ImportIFC")
|
logger = logging.getLogger("ImportIFC")
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
filename=bpy.context.scene.BIMProperties.data_dir + "process.log", filemode="a", level=logging.DEBUG
|
filename=os.path.join(bpy.context.scene.BIMProperties.data_dir, "process.log"), filemode="a", level=logging.DEBUG
|
||||||
)
|
)
|
||||||
|
|
||||||
settings = import_ifc.IfcImportSettings.factory(context, self.filepath, logger)
|
settings = import_ifc.IfcImportSettings.factory(context, self.filepath, logger)
|
||||||
@@ -201,7 +201,7 @@ class FetchExternalMaterial(bpy.types.Operator):
|
|||||||
if location[-6:] != ".mpass":
|
if location[-6:] != ".mpass":
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
if not os.path.isabs(location):
|
if not os.path.isabs(location):
|
||||||
location = os.path.join(os.path.join(bpy.context.scene.BIMProperties.data_dir, location))
|
location = os.path.join(bpy.context.scene.BIMProperties.data_dir, location)
|
||||||
with open(location) as f:
|
with open(location) as f:
|
||||||
self.material_pass = json.load(f)
|
self.material_pass = json.load(f)
|
||||||
if bpy.context.scene.render.engine == "BLENDER_EEVEE" and "eevee" in self.material_pass:
|
if bpy.context.scene.render.engine == "BLENDER_EEVEE" and "eevee" in self.material_pass:
|
||||||
@@ -214,7 +214,7 @@ class FetchExternalMaterial(bpy.types.Operator):
|
|||||||
identification = bpy.context.active_object.active_material.BIMMaterialProperties.identification
|
identification = bpy.context.active_object.active_material.BIMMaterialProperties.identification
|
||||||
uri = self.material_pass[name]["uri"]
|
uri = self.material_pass[name]["uri"]
|
||||||
if not os.path.isabs(uri):
|
if not os.path.isabs(uri):
|
||||||
uri = os.path.join(os.path.join(bpy.context.scene.BIMProperties.data_dir, uri))
|
uri = os.path.join(bpy.context.scene.BIMProperties.data_dir, uri)
|
||||||
bpy.ops.wm.link(filename=identification, directory=os.path.join(uri, "Material"))
|
bpy.ops.wm.link(filename=identification, directory=os.path.join(uri, "Material"))
|
||||||
for material in bpy.data.materials:
|
for material in bpy.data.materials:
|
||||||
if material.name == identification and material.library:
|
if material.name == identification and material.library:
|
||||||
|
|||||||
@@ -30,6 +30,18 @@ def getAttributeEnumValues(self, context):
|
|||||||
return [(e, e, "") for e in json.loads(self.enum_items)]
|
return [(e, e, "") for e in json.loads(self.enum_items)]
|
||||||
|
|
||||||
|
|
||||||
|
def updateSchemaDir(self, context):
|
||||||
|
import blenderbim.bim.schema
|
||||||
|
|
||||||
|
blenderbim.bim.schema.ifc.schema_dir = context.scene.BIMProperties.schema_dir
|
||||||
|
|
||||||
|
|
||||||
|
def updateDataDir(self, context):
|
||||||
|
import blenderbim.bim.schema
|
||||||
|
|
||||||
|
blenderbim.bim.schema.ifc.data_dir = context.scene.BIMProperties.data_dir
|
||||||
|
|
||||||
|
|
||||||
def updateIfcFile(self, context):
|
def updateIfcFile(self, context):
|
||||||
if context.scene.BIMProperties.ifc_file:
|
if context.scene.BIMProperties.ifc_file:
|
||||||
IfcStore.file = None
|
IfcStore.file = None
|
||||||
@@ -151,8 +163,12 @@ class Attribute(PropertyGroup):
|
|||||||
|
|
||||||
|
|
||||||
class BIMProperties(PropertyGroup):
|
class BIMProperties(PropertyGroup):
|
||||||
schema_dir: StringProperty(default=os.path.join(cwd, "schema") + os.path.sep, name="Schema Directory")
|
schema_dir: StringProperty(
|
||||||
data_dir: StringProperty(default=os.path.join(cwd, "data") + os.path.sep, name="Data Directory")
|
default=os.path.join(cwd, "schema") + os.path.sep, name="Schema Directory", update=updateSchemaDir
|
||||||
|
)
|
||||||
|
data_dir: StringProperty(
|
||||||
|
default=os.path.join(cwd, "data") + os.path.sep, name="Data Directory", update=updateDataDir
|
||||||
|
)
|
||||||
ifc_file: StringProperty(name="IFC File", update=updateIfcFile)
|
ifc_file: StringProperty(name="IFC File", update=updateIfcFile)
|
||||||
id_map: StringProperty(name="ID Map")
|
id_map: StringProperty(name="ID Map")
|
||||||
guid_map: StringProperty(name="GUID Map")
|
guid_map: StringProperty(name="GUID Map")
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ cwd = os.path.dirname(os.path.realpath(__file__))
|
|||||||
|
|
||||||
class IfcSchema:
|
class IfcSchema:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.schema_dir = Path(cwd).joinpath("schema") # TODO: make configurable
|
self.schema_dir = Path(cwd).joinpath("schema")
|
||||||
self.data_dir = Path(cwd).joinpath("data") # TODO: make configurable
|
self.data_dir = Path(cwd).joinpath("data")
|
||||||
# TODO: Make it less troublesome
|
# TODO: Make it less troublesome
|
||||||
self.products = [
|
self.products = [
|
||||||
"IfcElement",
|
"IfcElement",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class Usecase:
|
|||||||
self.settings[key] = value
|
self.settings[key] = value
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
data = {"Name": self.settings["Name"]}
|
data = {"Name": self.settings["name"]}
|
||||||
if self.file.schema == "IFC2X3":
|
if self.file.schema == "IFC2X3":
|
||||||
data["Id"] = self.settings["identification"]
|
data["Id"] = self.settings["identification"]
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user