bcf bonsai - create bcf v3 projects and display loaded bcf version

Example - https://imgur.com/a/3ZSGtw7
This commit is contained in:
Andrej730
2024-08-21 16:38:04 +05:00
parent 84a8c5dfeb
commit 9b12cae8b4
4 changed files with 27 additions and 3 deletions
+9 -1
View File
@@ -46,7 +46,15 @@ class BcfStore:
@classmethod
def set(cls, bcfxml: Union[bcf.bcfxml.BcfXml, None], filepath: str) -> None:
cls.bcfxml = bcfxml
bpy.context.scene.BCFProperties.bcf_file = filepath
props = bpy.context.scene.BCFProperties
props.bcf_file = filepath
# Set bcf_version prop on load.
if filepath or bcfxml:
bcfxml = cls.get_bcfxml()
assert bcfxml
bcf_v2 = (bcfxml.version.version_id or "").startswith("2")
props.bcf_version = "2" if bcf_v2 else "3"
@classmethod
def set_by_filepath(cls, filepath: str) -> None:
+7 -2
View File
@@ -55,7 +55,10 @@ class NewBcfProject(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
bcfxml = bcf.v2.bcfxml.BcfXml.create_new("New Project")
props = context.scene.BCFProperties
bcf_v2 = props.bcf_version == "2"
bcf_class = bcf.v2.bcfxml.BcfXml if bcf_v2 else bcf.v3.bcfxml.BcfXml
bcfxml = bcf_class.create_new("New Project")
bcfstore.BcfStore.set(bcfxml, "")
bpy.ops.bim.load_bcf_project()
return {"FINISHED"}
@@ -65,12 +68,14 @@ class LoadBcfProject(bpy.types.Operator):
bl_idname = "bim.load_bcf_project"
bl_label = "Load BCF Project"
bl_options = {"REGISTER", "UNDO"}
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
filepath: bpy.props.StringProperty(subtype="FILE_PATH", options={"SKIP_SAVE"})
filter_glob: bpy.props.StringProperty(default="*.bcf;*.bcfzip", options={"HIDDEN"})
def execute(self, context):
# Operator is also used when new project is created by not yet saved.
if self.filepath:
bcfstore.BcfStore.set_by_filepath(self.filepath)
bcfxml = bcfstore.BcfStore.get_bcfxml()
assert bcfxml
bcf_v2 = (bcfxml.version.version_id or "").startswith("2")
+6
View File
@@ -201,6 +201,12 @@ def get_related_topics(self: "BCFProperties", context: bpy.types.Context) -> lis
class BCFProperties(PropertyGroup):
bcf_file: StringProperty(name="BCF File")
bcf_version: EnumProperty(
name="BCF Version",
description="Currently loaded BCF project version / BCF version to use for created projects",
items=[("2", "v2.1", ""), ("3", "v3.0", "")],
default="3",
)
comment_text_width: IntProperty(name="Comment Text Width", default=40)
name: StringProperty(default="", name="Project Name", update=updateBcfProjectName)
author: StringProperty(
+5
View File
@@ -44,6 +44,7 @@ class BIM_PT_bcf(Panel):
row = layout.row(align=True)
row.operator("bim.new_bcf_project", text="New Project")
row.operator("bim.load_bcf_project", text="Load Project")
layout.prop(props, "bcf_version")
return
row = layout.row(align=True)
@@ -52,6 +53,10 @@ class BIM_PT_bcf(Panel):
row.operator("bim.save_bcf_project", icon="EXPORT", text="Save Project As...")
row.operator("bim.unload_bcf_project", text="", icon="CANCEL")
row = layout.row()
row.prop(props, "bcf_version", emboss=False)
row.enabled = False
row = layout.row()
row.prop(props, "name")