0
$\begingroup$

I wanted to change the cycles render to Blender internal through a panel button but only want the panel button to appear only when the current render engine is cycles. How do I create the conditional statement ?

Here the code I'm trying but it's not working:

if context.scene.render.engine == {'CYCLES'}:
      layout.operator("mesh.primitive_cube_add")
$\endgroup$

2 Answers 2

2
$\begingroup$

You don't want the curly braces around the string.

if context.scene.render.engine == 'CYCLES':
    layout.operator('render.set_internal')

Note that cycles and blender internal are not the only choices for render engine. It would be better to test if blender internal is the current engine.

if context.scene.render.engine != 'BLENDER_RENDER':
    layout.operator('render.set_internal')
else:
    layout.label(text='Blender render is active.')
$\endgroup$
0
$\begingroup$

Okay so this kind of partially worked but I fixed it, had to create an additional class to switch to Blender Internal.

Here is the class

class SwitchBI(bpy.types.Operator):
       bl_idname = "switch.bi_operator"
       bl_label = "Switch BI"
       def execute(self, context):
             bpy.context.scene.render.engine = 'BLENDER_RENDER'
             return {"FINISHED"}

And then the conditional Statement

If context.scene.render.engine == 'CYCLES':
      layout.operator('switch.bi_operator')
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.