mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-27 05:46:59 +00:00
feat(bevy_components): added progress bars for bulk operators
This commit is contained in:
parent
00695a18d8
commit
0d69791d88
@ -112,9 +112,7 @@ class RemoveComponentOperator(Operator):
|
|||||||
object = context.object
|
object = context.object
|
||||||
else:
|
else:
|
||||||
object = bpy.data.objects[self.object_name]
|
object = bpy.data.objects[self.object_name]
|
||||||
|
|
||||||
print("removing component ", self.component_name, "from object '"+object.name+"'")
|
print("removing component ", self.component_name, "from object '"+object.name+"'")
|
||||||
|
|
||||||
if object is not None and self.component_name in object:
|
if object is not None and self.component_name in object:
|
||||||
remove_component_from_object(object, self.component_name)
|
remove_component_from_object(object, self.component_name)
|
||||||
else:
|
else:
|
||||||
@ -134,13 +132,27 @@ class RemoveComponentFromAllObjectsOperator(Operator):
|
|||||||
description="component to delete",
|
description="component to delete",
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def register(cls):
|
||||||
|
bpy.types.WindowManager.components_remove_progress = bpy.props.FloatProperty(default=-1.0)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def unregister(cls):
|
||||||
|
del bpy.types.WindowManager.components_remove_progress
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
print("removing component ", self.component_name, "from all objects")
|
print("removing component ", self.component_name, "from all objects")
|
||||||
|
total = len(bpy.data.objects)
|
||||||
for object in bpy.data.objects:
|
for index, object in enumerate(bpy.data.objects):
|
||||||
if len(object.keys()) > 0:
|
if len(object.keys()) > 0:
|
||||||
if object is not None and self.component_name in object:
|
if object is not None and self.component_name in object:
|
||||||
remove_component_from_object(object, self.component_name)
|
remove_component_from_object(object, self.component_name)
|
||||||
|
|
||||||
|
progress = index / total
|
||||||
|
context.window_manager.components_remove_progress = progress
|
||||||
|
# now force refresh the ui
|
||||||
|
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
||||||
|
context.window_manager.components_remove_progress = -1.0
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@ -173,6 +185,14 @@ class OT_rename_component(Operator):
|
|||||||
|
|
||||||
target_objects: bpy.props.StringProperty() # type: ignore
|
target_objects: bpy.props.StringProperty() # type: ignore
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def register(cls):
|
||||||
|
bpy.types.WindowManager.components_rename_progress = bpy.props.FloatProperty(default=-1.0) #bpy.props.PointerProperty(type=RenameHelper)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def unregister(cls):
|
||||||
|
del bpy.types.WindowManager.components_rename_progress
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
registry = context.window_manager.components_registry
|
registry = context.window_manager.components_registry
|
||||||
type_infos = registry.type_infos
|
type_infos = registry.type_infos
|
||||||
@ -180,13 +200,14 @@ class OT_rename_component(Operator):
|
|||||||
original_name = settings.original_name if self.original_name == "" else self.original_name
|
original_name = settings.original_name if self.original_name == "" else self.original_name
|
||||||
new_name = self.new_name
|
new_name = self.new_name
|
||||||
|
|
||||||
print("FOO", self.original_name, "fsdf", settings.original_name)
|
|
||||||
|
|
||||||
print("renaming components: original name", original_name, "new_name", self.new_name, "targets", self.target_objects)
|
print("renaming components: original name", original_name, "new_name", self.new_name, "targets", self.target_objects)
|
||||||
target_objects = json.loads(self.target_objects)
|
target_objects = json.loads(self.target_objects)
|
||||||
errors = []
|
errors = []
|
||||||
|
total = len(target_objects)
|
||||||
|
|
||||||
if original_name != '' and new_name != '' and original_name != new_name and len(target_objects) > 0:
|
if original_name != '' and new_name != '' and original_name != new_name and len(target_objects) > 0:
|
||||||
for object_name in target_objects:
|
for index, object_name in enumerate(target_objects):
|
||||||
object = bpy.data.objects[object_name]
|
object = bpy.data.objects[object_name]
|
||||||
if object and original_name in object:
|
if object and original_name in object:
|
||||||
# get metadata
|
# get metadata
|
||||||
@ -221,6 +242,11 @@ class OT_rename_component(Operator):
|
|||||||
component_meta.invalid_details = "wrong custom property value, overwrite them by changing the values in the ui or change them & regenerate ('Update UI from ...button')"
|
component_meta.invalid_details = "wrong custom property value, overwrite them by changing the values in the ui or change them & regenerate ('Update UI from ...button')"
|
||||||
|
|
||||||
errors.append( "wrong custom property values to generate target component: object: '" + object.name + "', error: " + str(error))
|
errors.append( "wrong custom property values to generate target component: object: '" + object.name + "', error: " + str(error))
|
||||||
|
|
||||||
|
progress = index / total
|
||||||
|
context.window_manager.components_rename_progress = progress
|
||||||
|
# now force refresh the ui
|
||||||
|
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
||||||
|
|
||||||
if len(errors) > 0:
|
if len(errors) > 0:
|
||||||
self.report({'ERROR'}, "Failed to rename component: Errors:" + str(errors))
|
self.report({'ERROR'}, "Failed to rename component: Errors:" + str(errors))
|
||||||
@ -230,6 +256,7 @@ class OT_rename_component(Operator):
|
|||||||
#clear data after we are done
|
#clear data after we are done
|
||||||
self.original_name = ""
|
self.original_name = ""
|
||||||
context.window_manager.bevy_component_rename_helper.original_name = ""
|
context.window_manager.bevy_component_rename_helper.original_name = ""
|
||||||
|
context.window_manager.components_rename_progress = -1.0
|
||||||
|
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
@ -174,16 +174,27 @@ class BEVY_COMPONENTS_PT_AdvancedToolsPanel(bpy.types.Panel):
|
|||||||
#row.prop(available_components, "filter",text="Filter")
|
#row.prop(available_components, "filter",text="Filter")
|
||||||
|
|
||||||
col = row.column()
|
col = row.column()
|
||||||
operator = col.operator(OT_rename_component.bl_idname, text="apply", icon="SHADERFX")
|
components_rename_progress = context.window_manager.components_rename_progress
|
||||||
operator.target_objects = json.dumps(objects_with_invalid_components)
|
|
||||||
new_name = registry.type_infos[available_components.list]['short_name'] if available_components.list in registry.type_infos else ""
|
if components_rename_progress == -1.0:
|
||||||
operator.new_name = new_name
|
operator = col.operator(OT_rename_component.bl_idname, text="apply", icon="SHADERFX")
|
||||||
col.enabled = registry_has_type_infos and original_name != "" and original_name != new_name
|
operator.target_objects = json.dumps(objects_with_invalid_components)
|
||||||
|
new_name = registry.type_infos[available_components.list]['short_name'] if available_components.list in registry.type_infos else ""
|
||||||
|
operator.new_name = new_name
|
||||||
|
col.enabled = registry_has_type_infos and original_name != "" and original_name != new_name
|
||||||
|
else:
|
||||||
|
if hasattr(layout,"progress") : # only for Blender > 4.0
|
||||||
|
col.progress(factor = components_rename_progress, text=f"updating {components_rename_progress * 100.0:.2f}%")
|
||||||
|
|
||||||
col = row.column()
|
col = row.column()
|
||||||
operator = row.operator(RemoveComponentFromAllObjectsOperator.bl_idname, text="", icon="X")
|
remove_components_progress = context.window_manager.components_remove_progress
|
||||||
operator.component_name = context.window_manager.bevy_component_rename_helper.original_name
|
if remove_components_progress == -1.0:
|
||||||
col.enabled = registry_has_type_infos and original_name != ""
|
operator = row.operator(RemoveComponentFromAllObjectsOperator.bl_idname, text="", icon="X")
|
||||||
|
operator.component_name = context.window_manager.bevy_component_rename_helper.original_name
|
||||||
|
col.enabled = registry_has_type_infos and original_name != ""
|
||||||
|
else:
|
||||||
|
if hasattr(layout,"progress") : # only for Blender > 4.0
|
||||||
|
col.progress(factor = remove_components_progress, text=f"updating {remove_components_progress * 100.0:.2f}%")
|
||||||
|
|
||||||
layout.separator()
|
layout.separator()
|
||||||
layout.separator()
|
layout.separator()
|
||||||
|
Loading…
Reference in New Issue
Block a user