Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 89 additions & 1 deletion LightGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# to select the Environment so it can be reassigned via Assign/Unassign like lights.

import bpy
from bpy.types import Operator, Panel
from bpy.types import Operator, Panel, Menu
from bpy.props import StringProperty

# -------------------------------------------------------------------------
Expand Down Expand Up @@ -60,6 +60,28 @@ def execute(self, context):
context.scene.light_group_filter = ""
return {'FINISHED'}


class LG_MT_lightgroup_context_menu(Menu):
bl_label = "LighGroup Specials"

def draw(self, _context):
layout = self.layout

layout.operator("scene.view_layer_add_used_lightgroups", icon='ADD')
layout.operator("scene.view_layer_remove_unused_lightgroups", icon='REMOVE')

layout.separator()
layout.operator(
"lg.reset_all_lightgroups",
icon='LOOP_BACK',
text="Reset All LighGroups",
)
layout.operator(
"lg.remove_all_lightgroups",
icon='NONE',
text="Delete All LighGroups",
)

# -------------------------------------------------------------------------
# Operators
# -------------------------------------------------------------------------
Expand Down Expand Up @@ -226,6 +248,67 @@ def execute(self, context):
self.report({'WARNING'}, "Lightgroups not available in this Blender version.")
return {'FINISHED'}



class LG_ResetAllLighgrGroups(Operator):
"""Remove all lights from any LightGroups."""
bl_idname = "lg.reset_all_lightgroups"
bl_label = "Reset All LightGroups"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
view_layer = context.view_layer
# Unassign lights from the group before removing the group
for obj in context.scene.objects :
print(obj.type)
if obj.type == 'LIGHT' and (obj.lightgroup != ""):
obj.lightgroup = ""

# Force redraw panel so lightgroup gets updated
for area in context.screen.areas:
if area.type == 'PROPERTIES':
area.tag_redraw()

for obj in bpy.data.worlds:
if obj.lightgroup != "":
obj.lightgroup = ""

# Force redraw panel so lightgroup gets updated
for area in context.screen.areas:
if area.type == 'PROPERTIES':
area.tag_redraw()

else:
self.report({'INFO'}, "All Lightgroups cleared.")
return {'FINISHED'}


class LG_RemoveAllLighgrGroups(Operator):
"""Remove all LightGroups."""
bl_idname = "lg.remove_all_lightgroups"
bl_label = "Remove All the LightGroups in the scene. Also removes them from the lights."
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
view_layer = context.view_layer
# Unassign lights from the group before removing the group
if hasattr(view_layer, "lightgroups"):
for index, item in reversed(list(enumerate(view_layer.lightgroups))):
view_layer.active_lightgroup_index = index

# Use the Blender operator to remove the lightgroup
bpy.ops.scene.view_layer_remove_lightgroup()

# Force redraw panel so lightgroup gets updated
for area in context.screen.areas:
if area.type == 'PROPERTIES':
area.tag_redraw()

else:
self.report({'INFO'}, "All Lightgroups Removed.")
return {'FINISHED'}


# -------------------------------------------------------------------------
# Drawing
# -------------------------------------------------------------------------
Expand Down Expand Up @@ -274,6 +357,8 @@ def draw(self, context):
col = row.column(align=True)
col.operator("lg_editor.add_light_group", icon='ADD', text="")
col.operator("lg_editor.remove_light_group", icon='REMOVE', text="")

col.menu("LG_MT_lightgroup_context_menu", icon='DOWNARROW_HLT', text="")
else:
col.label(text="No Lightgroups in this Blender version", icon='ERROR')

Expand Down Expand Up @@ -371,6 +456,9 @@ def draw(self, context):
LG_AddLightGroup,
LG_RemoveLightGroup,
LG_ClearFilter,
LG_MT_lightgroup_context_menu,
LG_ResetAllLighgrGroups,
LG_RemoveAllLighgrGroups,
)

def register():
Expand Down
Loading