mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
Display IFC schema in file selector right hand side panel (#1978)
* Display IFC schema in file selector right hand side panel * Formatting * Fix possible error when the file name or description contains the word "schema"
This commit is contained in:
@@ -22,6 +22,7 @@ import json
|
|||||||
import webbrowser
|
import webbrowser
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import blenderbim.bim.handler
|
import blenderbim.bim.handler
|
||||||
|
from pathlib import Path
|
||||||
from . import schema
|
from . import schema
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from mathutils import Vector, Matrix, Euler
|
from mathutils import Vector, Matrix, Euler
|
||||||
@@ -46,8 +47,13 @@ class SelectIfcFile(bpy.types.Operator):
|
|||||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||||
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
|
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
|
||||||
|
|
||||||
|
def is_existing_ifc_file(self, filepath=None):
|
||||||
|
if filepath is None:
|
||||||
|
filepath = self.filepath
|
||||||
|
return os.path.exists(filepath) and "ifc" in os.path.splitext(filepath)[1].lower()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
if os.path.exists(self.filepath) and "ifc" in os.path.splitext(self.filepath)[1]:
|
if self.is_existing_ifc_file():
|
||||||
context.scene.BIMProperties.ifc_file = self.filepath
|
context.scene.BIMProperties.ifc_file = self.filepath
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
@@ -55,6 +61,25 @@ class SelectIfcFile(bpy.types.Operator):
|
|||||||
context.window_manager.fileselect_add(self)
|
context.window_manager.fileselect_add(self)
|
||||||
return {"RUNNING_MODAL"}
|
return {"RUNNING_MODAL"}
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
# Access filepath & Directory https://blender.stackexchange.com/a/207665
|
||||||
|
params = context.space_data.params
|
||||||
|
# Decode byte string https://stackoverflow.com/a/47737082/
|
||||||
|
directory = Path(params.directory.decode("utf-8"))
|
||||||
|
filepath = os.path.join(directory, params.filename)
|
||||||
|
if self.is_existing_ifc_file(filepath):
|
||||||
|
self.draw_ifc_specs(filepath)
|
||||||
|
|
||||||
|
def draw_ifc_specs(self, filepath):
|
||||||
|
with open(filepath) as ifc_file:
|
||||||
|
max_lines_to_parse = 50
|
||||||
|
for _ in range(max_lines_to_parse):
|
||||||
|
line = next(ifc_file)
|
||||||
|
if line.startswith("FILE_SCHEMA(('") and line.endswith("'));\n"):
|
||||||
|
schema = line.split("'")[1]
|
||||||
|
self.layout.label(text=f"File Schema : {schema}")
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
class SelectDataDir(bpy.types.Operator):
|
class SelectDataDir(bpy.types.Operator):
|
||||||
bl_idname = "bim.select_data_dir"
|
bl_idname = "bim.select_data_dir"
|
||||||
|
|||||||
Reference in New Issue
Block a user