I followed the recommendation of How to dynamically show/hide panel elements using python?
for an addon and it works fine during script development. But when I install the addon and use the panel an EnumPropery
which defines the layout seems to have lost the default value. The code is e.g.
class ABCK_Panel_with_sectors(bpy.types.Panel):
bl_space_type = "VIEW_3D" # window type panel is displayed in
bl_region_type = "TOOLS" # region of window panel is displayed in
bl_label = "Create ABCK objects in sectors 03" # heading of panel
def draw(self, context) :
layout = self.layout
scene = context.scene
col = layout.column()
#.........................................................
box = layout.box()
box.label("General definitions")
row = box.row()
row.prop(scene, 'Object_type')
if scene['Object_type'] == 2: #!!!!!!!!!!!!!!!!!!!here is the problem
row = box.row()
row.prop(scene, 'with_bevels')
row.prop(scene, 'with_colors')
#.........................................................
layout.label("")
box = layout.box()
box.label("Math only, no Blender objects")
box.prop(scene, "Generations")
box.prop(scene, "all_sectors")
if scene['all_sectors'] == False:
box.prop(scene, "Selection_of_sectors")
row = box.row()
row.operator("compute.objects", text = "compute")
row.operator("print_number_of.objects_sectors", \
text = "print count math")
#.........................................................
layout.label("")
box = layout.box()
box.label("Final creation")
row = box.row()
row.prop(scene, 'Border_type')
col = box.column()
if scene['Border_type'] == Border_sphere:
col.prop(scene, 'Size_max')
col.prop(scene, 'Size_min')
else:
#col.operator('select.object_for_tesselation')
col.label("select object for tesselation")
col.label("and press 'create objects'")
row = box.row()
row.operator("display_all.objects_sectors", \
text = "create objects")
if scene['Border_type'] == Border_sphere:
row.operator("print_number_of.objects_sectors", \
text = "print count tetrahedrons")
#.........................................................
layout.label("")
row = layout.row()
box = row.box()
box.label("Other")
box = box.row()
box.operator("delete.objects", text = "delete")
box.operator("toogle_select_all_visible.objects", \
text = "toggle selected objects")
layout.label("")
row = layout.row()
tets_on_layer_0 = [ob for ob in bpy.context.scene.objects \
if (ob.layers[0] and ob.name.startswith("T_"))]
if len(tets_on_layer_0) == 1:
row.label(text="1 object generated.", icon='OBJECT_DATA')
else:
row.label(text=str((len(tets_on_layer_0))) + \
" objects generated.", icon='OBJECT_DATA')
and I get a 'KeyError':
'bpy_struct[key]: key "Object_type" not found.'
What can be done here?