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 Answer 1

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$
7
  • $\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
    Commented Jan 5, 2015 at 19:00
  • $\begingroup$ Well if it hasn't been renamed then you don't need to. $\endgroup$ Commented Jan 5, 2015 at 19:17
  • 1
    $\begingroup$ @BlendingJake Python will still iterate trough the list anyway... stackoverflow.com/questions/12905513/… $\endgroup$ Commented Jan 5, 2015 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$ Commented Jan 5, 2015 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$ Commented Jan 6, 2015 at 13:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .