I want a self-updating dropdown list that changes the render engine to either Cycles or eevee.
The code for this works when it is written directly like this.
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.engine = 'BLENDER_EEVEE'
But If I try to put it in a dropdown list, it doesn't work. Am I doing something wrong?
The same dropdown list work for other settings like FPS or render formats, why isn't it working here?
import bpy
from bpy.types import (Panel,
Menu,
PropertyGroup,
)
class MyProperties(bpy.types.PropertyGroup):
my_enum0 : bpy.props.EnumProperty(
name= "",
description= "Change the render engine of the scene",
items= [('OP1', "Cycles", "f"),
('OP2', "Eevee", "fg"),
],
update=lambda self, context: bpy.ops.addonname.myop_operator00()
)
class TestPanel(bpy.types.Panel):
bl_label = "Quick Render Presets"
bl_idname = "PT_TestPanel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Example'
def draw(self, context):
layout = self.layout
scene = context.scene
mytool = scene.my_tool
rowAA = layout.row()
rowAA.label(text= "Render Engine:")
layout.prop(mytool, "my_enum0")
class RenderRender2(bpy.types.Operator):
bl_label = "Render Engine"
bl_idname = "addonname.myop_operator00"
def execute(self, context):
scene = context.scene
mytool = scene.my_tool
if mytool.my_enum == 'OP1':
bpy.context.scene.render.engine = 'CYCLES'
if mytool.my_enum == 'OP2':
bpy.data.scene.render.engine = 'BLENDER_EEVEE'
return {'FINISHED'}
classes = [MyProperties, RenderRender2, TestPanel]
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.my_tool = bpy.props.PointerProperty(type= MyProperties)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
del bpy.types.Scene.my_tool
if __name__ == "__main__":
register()
mytool.my_enum0
? Also why not simply writinglayout.prop(context.scene.render, "engine")
in the panel draw code ? $\endgroup$OP1
andOP2
byCYCLES
andBLENDER_EEVEE
in the enum, you can replace the two if statements withbpy.context.scene.render.engine = mytool.my_enum
and then you won't have to change the code if you add another render engine to the enum. $\endgroup$