2
$\begingroup$

My first idea was to get the surface type of the material. If this is an emission shader it should be a light source, but I can't find something in the python documentation to get the surface input.

enter image description here

$\endgroup$
1
$\begingroup$

You can do this by getting the material and checking if there is a node called Emission in the node tree, like this:

import bpy
obj = bpy.context.object
nodes = obj.data.materials[0].node_tree.nodes
if "Emission" in nodes:
    print("yes")

Likewise, you could also check for a EMISSION node by using this instead:

for node in nodes:
    if node.type == "EMISSION":
        print("yes")

That way if the user had changed the name it would still catch it.

$\endgroup$
  • $\begingroup$ Thanks - makes sense to me! But can't believe that we need to iterate over the whole tree to find out whether the object is a light or not... :) $\endgroup$ – p2or Jan 5 '15 at 19:00
  • $\begingroup$ Well if it hasn't been renamed then you don't need to. $\endgroup$ – BlendingJake Jan 5 '15 at 19:17
  • 1
    $\begingroup$ @BlendingJake Python will still iterate trough the list anyway... stackoverflow.com/questions/12905513/… $\endgroup$ – someonewithpc Jan 5 '15 at 19:24
  • 1
    $\begingroup$ worried about lag? I just ran a script that created a list with 1,000,000 numbers in it and then checked to find a number in it. It only took 0.11 seconds. $\endgroup$ – BlendingJake Jan 5 '15 at 20:09
  • 2
    $\begingroup$ One way to save a little would be to iterate through the materials first then just look for that material on the objects. Otherwise you might be looking through the same material multiple times. $\endgroup$ – BlendingJake Jan 6 '15 at 13:49

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.