I'm working on an Addon that saves Render Settings and Camera Settings.
If I try to save camera settings but the multiview in the Output Settings is not set to True
, it gives an error, because the Stereoscopy Settings in the Camera-Properties are non existing.
I found out because it is not possible to get values from the context inside of a class.
How can I make an if
statement happen by looking for a boolean value in Blender context?
This example is a copy from the Blender API, just to make it work in a small txt-file. Look for the if
statement with ##<-------- here is the question
.
import bpy
from bpy.types import Operator, Menu
from bl_operators.presets import AddPresetBase
class OBJECT_MT_display_presets(Menu):
bl_label = "Object Display Presets"
preset_subdir = "object/display"
preset_operator = "script.execute_preset"
draw = Menu.draw_preset
class AddPresetObjectDisplay(AddPresetBase, Operator):
'''Add a Object Display Preset'''
bl_idname = "camera.object_display_preset_add"
bl_label = "Add Object Display Preset"
preset_menu = "OBJECT_MT_display_presets"
# variable used for all preset values
preset_defines = [
"obj = bpy.context.object"
"data = bpy.context.data"
]
# properties to store in the preset
preset_values = [
"obj.display_type",
"obj.show_bounds",
"obj.display_bounds_type",
"obj.show_name",
"obj.show_axis",
"obj.show_wire",
]
######################
######################
if bpy.context.scene.render.use_multiview == True: ##<--------here is the question
self.preset_values.extend([
"data.stereo.convergence_mode",
"data.stereo.convergence_distance",
"data.stereo.interocular_distance",
"data.stereo.use_spherical_stereo",
])
#####################
#####################
# where to store the preset
preset_subdir = "object/display"
# Display into an existing panel
def panel_func(self, context):
layout = self.layout
row = layout.row(align=True)
row.menu(OBJECT_MT_display_presets.__name__, text=OBJECT_MT_display_presets.bl_label)
row.operator(AddPresetObjectDisplay.bl_idname, text="", icon='ZOOM_IN')
row.operator(AddPresetObjectDisplay.bl_idname, text="", icon='ZOOM_OUT').remove_active = True
classes = (
OBJECT_MT_display_presets,
AddPresetObjectDisplay,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.OBJECT_PT_display.prepend(panel_func)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
bpy.types.OBJECT_PT_display.remove(panel_func)
if __name__ == "__main__":
register()
context
defined? Not my area.. but should that bebpy.context
? $\endgroup$