Separate project templates and libraries and provide dropdown to built-in libraries to aid discoverability.

This commit is contained in:
Dion Moult
2024-03-03 15:24:46 +11:00
parent 01b0164e0d
commit 7a7c89e475
5 changed files with 1154 additions and 6 deletions
File diff suppressed because one or more lines are too long
@@ -35,6 +35,7 @@ class ProjectData:
def load(cls):
cls.data = {
"export_schema": cls.get_export_schema(),
"library_file": cls.library_file(),
"template_file": cls.template_file(),
"last_saved": cls.last_saved(),
}
@@ -45,10 +46,17 @@ class ProjectData:
return [(s, s, "") for s in IfcStore.schema_identifiers]
@classmethod
def template_file(cls):
def library_file(cls):
files = os.listdir(os.path.join(bpy.context.scene.BIMProperties.data_dir, "libraries"))
results = [("0", "Custom Library", "")]
results.extend([(f, os.path.splitext(f)[0], "") for f in files if ".ifc" in f])
return results
@classmethod
def template_file(cls):
files = os.listdir(os.path.join(bpy.context.scene.BIMProperties.data_dir, "templates", "projects"))
results = [("0", "Blank Project", "")]
results.extend([(f, f.replace(".ifc", ""), "") for f in files if ".ifc" in f])
results.extend([(f, os.path.splitext(f)[0], "") for f in files if ".ifc" in f])
return results
@classmethod
@@ -16,6 +16,7 @@
# 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/>.
import os
import bpy
import ifcopenshell.util.placement
from blenderbim.bim.module.project.data import ProjectData
@@ -45,6 +46,19 @@ def get_template_file(self, context):
return ProjectData.data["template_file"]
def get_library_file(self, context):
if not ProjectData.is_loaded:
ProjectData.load()
return ProjectData.data["library_file"]
def update_library_file(self, context):
if self.library_file != "0":
bpy.ops.bim.select_library_file(
filepath=os.path.join(bpy.context.scene.BIMProperties.data_dir, "libraries", self.library_file)
)
def update_filter_mode(self, context):
self.filter_categories.clear()
if self.filter_mode == "NONE":
@@ -169,6 +183,7 @@ class BIMProjectProperties(PropertyGroup):
active_link_index: IntProperty(name="Active Link Index")
export_schema: EnumProperty(items=get_export_schema, name="IFC Schema")
template_file: EnumProperty(items=get_template_file, name="Template File")
library_file: EnumProperty(items=get_library_file, name="Library File", update=update_library_file)
use_relative_project_path: BoolProperty(name="Use Relative Project Path", default=False)
queried_obj: bpy.props.PointerProperty(type=bpy.types.Object)
clipping_planes: bpy.props.CollectionProperty(type=ObjProperty)
@@ -255,12 +255,20 @@ class BIM_PT_project_library(Panel):
self.layout.use_property_split = True
self.props = context.scene.BIMProjectProperties
row = self.layout.row(align=True)
row.label(text=IfcStore.library_path or "No Library Loaded", icon="ASSET_MANAGER")
row.prop(self.props, "library_file", text="")
if self.props.library_file == "0":
row.operator("bim.select_library_file", icon="FILE_FOLDER", text="")
row = self.layout.row(align=True)
if IfcStore.library_file:
row.label(text=IfcStore.library_file.schema)
row.label(
text=os.path.splitext(os.path.basename(IfcStore.library_path))[0]
+ f" - {IfcStore.library_file.schema}",
icon="ASSET_MANAGER",
)
row.operator("bim.append_library_element_by_query", text="", icon="APPEND_BLEND")
row.operator("bim.save_library_file", text="", icon="EXPORT")
row.operator("bim.select_library_file", icon="FILE_FOLDER", text="")
else:
row.label(text="No Library Loaded", icon="ASSET_MANAGER")
if IfcStore.library_file:
self.draw_library_ul()
+1 -1
View File
@@ -31,7 +31,7 @@ class Project(blenderbim.core.tool.Project):
@classmethod
def append_all_types_from_template(cls, template):
# TODO refactor
filepath = os.path.join(bpy.context.scene.BIMProperties.data_dir, "libraries", template)
filepath = os.path.join(bpy.context.scene.BIMProperties.data_dir, "templates", "projects", template)
bpy.ops.bim.select_library_file(filepath=filepath)
if IfcStore.library_file.schema != tool.Ifc.get().schema:
return