2
$\begingroup$

Can i somehow enable/disable lights/objects depending on render engine?

e.g. sun should be disabled on cycles, a plane with emission should be enabled only on cycles.

On EEVEE the sun should be enabled and the plane with emission should be disabled.

The only idea i have i disabling it with driver and python. Is there an easier way?

$\endgroup$
2
  • 3
    $\begingroup$ that would be a great option, or create a light collection for each engine $\endgroup$
    – moonboots
    Aug 29 at 12:15
  • $\begingroup$ @moonboots: good idea...but i have still have no idea how to automate this. I wish there would be a Blender handler for render engine change.... $\endgroup$
    – Chris
    Aug 29 at 15:34
2
$\begingroup$

I agree with @moonboots, having two different collections holding your lights is the best option by far. Easy, robust, quick.

The only thing that I would add (optionally) are few lines of code in case I wanted to have more control over it (separate it to different scenarios maybe, keep track of different groups of lights etc).

Which I guess is an over-killer but here we go:

first things first, is always good to know which render engine are you on

and this one gives always the correct answer:

bpy.context.scene.render.engine

next you may want to enable and disable certain Collections or even objects if you like.

What I would do to anticipate this is to use a prefix for my objects/groups or collections. Something similar to EV_nameofmylight for my EEVEE light objects and on the other hand something like CY_nameofmylightobject for the CYCLES lights.

then a quite dirty but an effective way to toggle them would be to parse the whole collection of my objects (notice here that if you disabled a light in purpose its state will be ignored and it will be enabled again). So we have already a small bug to deal with.

The code should look something like this:

import bpy

scn = bpy.context.scene
render_engine = bpy.context.scene.render.engine

#exceptions is an optional list where you may put the names of the lightobjects that you want to remain unchanged 
#is not that useful if you consider that you may always remove the suffix (CY or EV) by the object's name instead
exceptions = []


for obj in scn.objects:
    if render_engine == 'BLENDER_EEVEE':
        if 'CY_' in obj.name and obj.name not in exceptions:
            obj.hide_render = True
            #obj.hide_viewport = True
            obj.hide_set(True)
        if 'EV_' in obj.name and obj.name not in exceptions:
            obj.hide_render = False
            #obj.hide_viewport = False
            obj.hide_set(False)
    elif render_engine == 'CYCLES':
        if 'CY_' in obj.name and obj.name not in exceptions:
            obj.hide_render = False
            #obj.hide_viewport = False
            obj.hide_set(False)
        if 'EV_' in obj.name and obj.name not in exceptions:
            obj.hide_render = True
            #obj.hide_viewport = True
            obj.hide_set(True)
$\endgroup$
2
  • 1
    $\begingroup$ I would suggest iterating through a list of pairs of (render engine name, prefix) rather than the if statement for those people who use add-on render engines like renderman. $\endgroup$ Aug 29 at 17:49
  • $\begingroup$ Sure, that would be also useful. Feel free to alter the code to your taste! $\endgroup$
    – cnisidis
    Aug 29 at 17:59

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.