Prevent using pset operators when no template available

This commit is contained in:
Gorgious
2021-09-28 13:20:20 +02:00
parent dbac865a39
commit 6fb4714317
2 changed files with 19 additions and 2 deletions
@@ -21,7 +21,11 @@ import ifcopenshell
import ifcopenshell.api
import blenderbim.bim.schema
import blenderbim.bim.handler
from blenderbim.bim.module.pset_template.prop import updatePsetTemplateFiles, updatePsetTemplates
from blenderbim.bim.module.pset_template.prop import (
updatePsetTemplateFiles,
updatePsetTemplates,
getPsetTemplates
)
from ifcopenshell.api.pset_template.data import Data
from blenderbim.bim.ifc import IfcStore
@@ -59,6 +63,11 @@ class RemovePsetTemplate(bpy.types.Operator):
bl_label = "Remove Pset Template"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
props = context.scene.BIMPsetTemplateProperties
return bool(getPsetTemplates(props, context))
def execute(self, context):
IfcStore.begin_transaction(self)
IfcStore.pset_template_file.begin_transaction()
@@ -93,6 +102,11 @@ class EnableEditingPsetTemplate(bpy.types.Operator):
bl_label = "Enable Editing Pset Template"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
props = context.scene.BIMPsetTemplateProperties
return bool(getPsetTemplates(props, context))
def execute(self, context):
props = context.scene.BIMPsetTemplateProperties
props.active_pset_template_id = int(props.pset_templates)
@@ -19,6 +19,9 @@
import bpy
from bpy.types import Panel
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.module.pset_template.prop import (
getPsetTemplates,
)
from ifcopenshell.api.pset_template.data import Data
@@ -40,7 +43,7 @@ class BIM_PT_pset_template(Panel):
row = layout.row(align=True)
if props.pset_templates:
if bool(getPsetTemplates(props, context)):
row.prop(props, "pset_templates", text="", icon="COPY_ID")
else:
row.label(text="No Pset Templates", icon="COPY_ID")