I'd like to fill a custom UI list with all the lights that are in the current scene, but am unsure of the best way to do this. We could iterate over bpy.context.scene.objects
and validate object.type == 'LIGHT'
to filter things out and then use objects[i].data
to get the actual light, but that strikes me as clunky and non-performant, especially for scenes that have a large number of objects.
Ideally I would like to drill into bpy.data.lights
and then filter this much smaller dataset based upon the scene(s) each light is used within. But, given a light in bpy.data.lights
, how can I find the object that's using it, and from there check this object's user_scene
attribute? This strikes me as being much faster than iterating in a top-down fashion over a bazillion objects' data
attributes, but if there's a mechanism for going bottom-up from a light to the object(s) that are using it then I can't find it in the API. Any ideas, smarter people of StackExchange?
Many thanks, and apologies if this is a DOH! kind of question, I'm new to this and still feeling my way around in the dark.