How to get values from bpy.context inside a class 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 ##&lt;-------- 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 = &quot;Object Display Presets&quot;
    preset_subdir = &quot;object/display&quot;
    preset_operator = &quot;script.execute_preset&quot;
    draw = Menu.draw_preset


class AddPresetObjectDisplay(AddPresetBase, Operator):
    '''Add a Object Display Preset'''
    bl_idname = &quot;camera.object_display_preset_add&quot;
    bl_label = &quot;Add Object Display Preset&quot;
    preset_menu = &quot;OBJECT_MT_display_presets&quot;

    # variable used for all preset values
    preset_defines = [
        &quot;obj = bpy.context.object&quot;
        &quot;data = bpy.context.data&quot;

    ]

    # properties to store in the preset
    preset_values = [
        &quot;obj.display_type&quot;,
        &quot;obj.show_bounds&quot;,
        &quot;obj.display_bounds_type&quot;,
        &quot;obj.show_name&quot;,
        &quot;obj.show_axis&quot;,
        &quot;obj.show_wire&quot;,
    ]

######################
######################

    if bpy.context.scene.render.use_multiview == True:  ##&lt;--------here is the question
        self.preset_values.extend([
            &quot;data.stereo.convergence_mode&quot;,
            &quot;data.stereo.convergence_distance&quot;,
            &quot;data.stereo.interocular_distance&quot;,
            &quot;data.stereo.use_spherical_stereo&quot;,
        ])
        
#####################
#####################

    # where to store the preset
    preset_subdir = &quot;object/display&quot;


# 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=&quot;&quot;, icon='ZOOM_IN')
    row.operator(AddPresetObjectDisplay.bl_idname, text=&quot;&quot;, 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__ == &quot;__main__&quot;:
    register()
After a long while I finally understand it:
It's not possible to get the context inside a Class outside a function, (except of batFINGER's way, but I still don't understand that).
But it is possible to get what ever is needed in a function outside the class and then use the function like this: (Here is only the relevant part of the script shown)
-----&gt; In this way, the context won't update. Therefore the way over the &quot;@classmethod def poll(cls,context) is needed. (not shown here)
import bpy

def Multiview():
    if bpy.context.scene.render.use_multiview == True:
        print('Yes, its true')
        return True
    else:
        return False

class AddPresetObjectDisplay(AddPresetBase, Operator):
    '''Add a Object Display Preset'''
    bl_idname = &quot;camera.object_display_preset_add&quot;
    bl_label = &quot;Add Object Display Preset&quot;
    preset_menu = &quot;OBJECT_MT_display_presets&quot;

    # variable used for all preset values
    preset_defines = [
        &quot;obj = bpy.context.object&quot;
        &quot;data = bpy.context.data&quot;

    ]

    # properties to store in the preset
    preset_values = [
        &quot;obj.display_type&quot;,
        &quot;obj.show_bounds&quot;,
        &quot;obj.display_bounds_type&quot;,]

    if Multiview():          ####&lt;------- Context used here
        preset_values.extend([

        &quot;obj.show_name&quot;,
        &quot;obj.show_axis&quot;,])

Or another useful example:
def Blender_2_93():
    if bpy.app.version &gt;= (2,93,0):
        return True
    else:
        return False

With that little function is it very easy to  make changes for different blender versions if a preset system is used or something else where the access to context, data or what ever is not usual.