How to clear panels when switching render engine

Hello,

I’m writing a render engine of sorts. I’ve got a basic addon working that populates the list of render engines and I’ve got a basic panel showing. In fact as soon as I enable my addon my panel shows up in the render tab of the properties editor. When I disable my addon the panel is removed.

What I want is for my panel to be added and removed when I change the render engine. When I switch to my render engine I see only my panel. When I switch to a different render engine I see all the panels for the other engine AND I still see mine.

How do I get the behavior I want (which seems like the obvious right behavior)?

My programming is strong, my Python is fair and my Blender API is probably weak. I’m happy to look at tutorials and such but mostly what I see is basic (and about operators) and I’ve covered that.

Thanks.

/Daryl

make a test on the render engine

print (‘Render engine =’,bpy.context.scene.render.engine)

if bpy.context.scene.render.engine==‘BLENDER_RENDER’:
print (‘Render is = BLENDER_RENDER’)
bpy.context.scene.render.engine=“CYCLES”
print (‘Converted to BLENDER_CYCLES’)
else:
print (‘Render is = CYCLES’)

print ()

happy bl

Thanks for chiming in, Ricky, I’m confused though. Where what I put the test and what do I do in response? Is there an event handler I need to implement when my render engine is selected or deselected? Once I determine my render engine is selected or deselected, how do I add/remove my panel?

Thanks.

/Daryl

add an if test then select panel portion in your script or not !

but then you have to run the script for this effect

happy bl

A nice way is to add a class variable and check it in the poll class method:

class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    COMPAT_ENGINES = {'CYCLES', 'BLENDER_RENDER'}

    @classmethod
    def poll(cls, context):
        engine = context.scene.render.engine
        return engine in cls.COMPAT_ENGINES

See e.g. this official file.

Thanks CoDEmanX, that looks to be exactly what I was looking for. For the benefit of others who might read this, I found this documentation on the nature of the poll() method (which I had seen in tutorials but didn’t understand fully what it was for):

http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes#Polling

/Daryl

Just following up to say it worked, thanks. I’m new here and I don’t know how to mark this thread as “solved”.

/Daryl