Skip to main content
added 1 character in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

Put them in a collection

IMO the simplest way to do this is, as suggested

scene_lights = [ob for ob in scene.objects if ob.type == 'LIGHT']

One light object could have the same light data as any or all of the lights in a scene. Even if there are few lights, checking that the data belongs to an object in the scene could prove less efficient than above.

If you feel that there are so many objects in the scene that iterating over them is inefficient, consider linking them to a collection(s) using name or ID property to tag the collection as being for light objects.

lightcol = bpy.data.collectioncollections.get("Lights")

if not lightcol:
    lightcol =  bpy.data.collections.new("Lights")
    scene.collection.children.link(lightcol) # or wherever
# populate it.
for lt in scene_lights:
    lightcol.objects.link(lt)

Could make collections within this collection to further categorize by light type

Polled PointerProperty

As mentioned by @brockmann can also consider using a polled pointer property, an example for materials

Custom search data to UILayout.prop_search

whereas in the case of lights the pointer property type would be bpy.types.Object, and the poll method would test against type. Could easily be extended to light type

Put them in a collection

IMO the simplest way to do this is, as suggested

scene_lights = [ob for ob in scene.objects if ob.type == 'LIGHT']

One light object could have the same light data as any or all of the lights in a scene. Even if there are few lights, checking that the data belongs to an object in the scene could prove less efficient than above.

If you feel that there are so many objects in the scene that iterating over them is inefficient, consider linking them to a collection(s) using name or ID property to tag the collection as being for light objects.

lightcol = bpy.data.collection.get("Lights")

if not lightcol:
    lightcol =  bpy.data.collections.new("Lights")
    scene.collection.children.link(lightcol) # or wherever
# populate it.
for lt in scene_lights:
    lightcol.objects.link(lt)

Could make collections within this collection to further categorize by light type

Polled PointerProperty

As mentioned by @brockmann can also consider using a polled pointer property, an example for materials

Custom search data to UILayout.prop_search

whereas in the case of lights the pointer property type would be bpy.types.Object, and the poll method would test against type. Could easily be extended to light type

Put them in a collection

IMO the simplest way to do this is, as suggested

scene_lights = [ob for ob in scene.objects if ob.type == 'LIGHT']

One light object could have the same light data as any or all of the lights in a scene. Even if there are few lights, checking that the data belongs to an object in the scene could prove less efficient than above.

If you feel that there are so many objects in the scene that iterating over them is inefficient, consider linking them to a collection(s) using name or ID property to tag the collection as being for light objects.

lightcol = bpy.data.collections.get("Lights")

if not lightcol:
    lightcol =  bpy.data.collections.new("Lights")
    scene.collection.children.link(lightcol) # or wherever
# populate it.
for lt in scene_lights:
    lightcol.objects.link(lt)

Could make collections within this collection to further categorize by light type

Polled PointerProperty

As mentioned by @brockmann can also consider using a polled pointer property, an example for materials

Custom search data to UILayout.prop_search

whereas in the case of lights the pointer property type would be bpy.types.Object, and the poll method would test against type. Could easily be extended to light type

Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

Put them in a collection

IMO the simplest way to do this is, as suggested

scene_lights = [ob for ob in scene.objects if ob.type == 'LIGHT']

One light object could have the same light data as any or all of the lights in a scene. Even if there are few lights, checking that the data belongs to an object in the scene could prove less efficient than above.

If you feel that there are so many objects in the scene that iterating over them is inefficient, consider linking them to a collection(s) using name or ID property to tag the collection as being for light objects.

lightcol = bpy.data.collection.get("Lights")

if not lightcol:
    lightcol =  bpy.data.collections.new("Lights")
    scene.collection.children.link(lightcol) # or wherever
# populate it.
for lt in scene_lights:
    lightcol.objects.link(lt)

Could make collections within this collection to further categorize by light type

Polled PointerProperty

As mentioned by @brockmann can also consider using a polled pointer property, an example for materials

Custom search data to UILayout.prop_search

whereas in the case of lights the pointer property type would be bpy.types.Object, and the poll method would test against type. Could easily be extended to light type