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 indicators for from/to custom properties
This commit is contained in:
parent
7cf8007b18
commit
63bac03c7c
@ -42,11 +42,26 @@ class COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_ALL(Operator):
|
||||
bl_label = "Apply Registry to all objects"
|
||||
bl_options = {"UNDO"}
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
bpy.types.WindowManager.custom_properties_from_components_progress_all = bpy.props.FloatProperty(default=-1.0) #bpy.props.PointerProperty(type=RenameHelper)
|
||||
|
||||
@classmethod
|
||||
def unregister(cls):
|
||||
del bpy.types.WindowManager.custom_properties_from_components_progress_all
|
||||
|
||||
def execute(self, context):
|
||||
print("apply registry to all")
|
||||
#context.window_manager.components_registry.load_schema()
|
||||
for object in bpy.data.objects:
|
||||
total = len(bpy.data.objects)
|
||||
|
||||
for index, object in enumerate(bpy.data.objects):
|
||||
apply_propertyGroup_values_to_object_customProperties(object)
|
||||
progress = index / total
|
||||
context.window_manager.custom_properties_from_components_progress_all = progress
|
||||
# now force refresh the ui
|
||||
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
||||
context.window_manager.custom_properties_from_components_progress_all = -1.0
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
@ -56,10 +71,23 @@ class COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT(Operator):
|
||||
bl_label = "Apply Registry to current object"
|
||||
bl_options = {"UNDO"}
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
bpy.types.WindowManager.custom_properties_from_components_progress = bpy.props.FloatProperty(default=-1.0) #bpy.props.PointerProperty(type=RenameHelper)
|
||||
|
||||
@classmethod
|
||||
def unregister(cls):
|
||||
del bpy.types.WindowManager.custom_properties_from_components_progress
|
||||
|
||||
def execute(self, context):
|
||||
print("apply registry to current object")
|
||||
object = context.object
|
||||
context.window_manager.custom_properties_from_components_progress = 0.5
|
||||
# now force refresh the ui
|
||||
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
||||
apply_propertyGroup_values_to_object_customProperties(object)
|
||||
|
||||
context.window_manager.custom_properties_from_components_progress = -1.0
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
@ -69,44 +97,77 @@ class COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT(Operator):
|
||||
bl_label = "Apply custom_properties to current object"
|
||||
bl_options = {"UNDO"}
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
bpy.types.WindowManager.components_from_custom_properties_progress = bpy.props.FloatProperty(default=-1.0) #bpy.props.PointerProperty(type=RenameHelper)
|
||||
|
||||
@classmethod
|
||||
def unregister(cls):
|
||||
del bpy.types.WindowManager.components_from_custom_properties_progress
|
||||
|
||||
def execute(self, context):
|
||||
print("apply custom properties to current object")
|
||||
object = context.object
|
||||
error = False
|
||||
try:
|
||||
apply_customProperty_values_to_object_propertyGroups(object)
|
||||
progress = 0.5
|
||||
context.window_manager.components_from_custom_properties_progress = progress
|
||||
# now force refresh the ui
|
||||
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
||||
|
||||
except Exception as error:
|
||||
del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure
|
||||
error = True
|
||||
self.report({'ERROR'}, "Failed to update propertyGroup values from custom property: Error:" + str(error))
|
||||
if not error:
|
||||
self.report({'INFO'}, "Sucessfully generated UI values for custom properties for selected object")
|
||||
context.window_manager.components_from_custom_properties_progress = -1.0
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL(Operator):
|
||||
"""Update UI values from custom properties to ALL object"""
|
||||
bl_idname = "object.refresh_ui_from_custom_properties_all"
|
||||
bl_label = "Apply custom_properties to all objects"
|
||||
bl_options = {"UNDO"}
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
bpy.types.WindowManager.components_from_custom_properties_progress_all = bpy.props.FloatProperty(default=-1.0) #bpy.props.PointerProperty(type=RenameHelper)
|
||||
|
||||
@classmethod
|
||||
def unregister(cls):
|
||||
del bpy.types.WindowManager.components_from_custom_properties_progress_all
|
||||
|
||||
def execute(self, context):
|
||||
print("apply custom properties to all object")
|
||||
bpy.context.window_manager.components_registry.disable_all_object_updates = True
|
||||
errors = []
|
||||
for object in bpy.data.objects:
|
||||
total = len(bpy.data.objects)
|
||||
|
||||
for index, object in enumerate(bpy.data.objects):
|
||||
|
||||
try:
|
||||
apply_customProperty_values_to_object_propertyGroups(object)
|
||||
except Exception as error:
|
||||
del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure
|
||||
errors.append( "object: '" + object.name + "', error: " + str(error))
|
||||
|
||||
progress = index / total
|
||||
context.window_manager.components_from_custom_properties_progress_all = progress
|
||||
# now force refresh the ui
|
||||
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
||||
|
||||
|
||||
|
||||
if len(errors) > 0:
|
||||
self.report({'ERROR'}, "Failed to update propertyGroup values from custom property: Errors:" + str(errors))
|
||||
else:
|
||||
self.report({'INFO'}, "Sucessfully generated UI values for custom properties for all objects")
|
||||
bpy.context.window_manager.components_registry.disable_all_object_updates = False
|
||||
|
||||
|
||||
context.window_manager.components_from_custom_properties_progress_all = -1.0
|
||||
return {'FINISHED'}
|
||||
|
||||
class OT_OpenFilebrowser(Operator, ImportHelper):
|
||||
|
@ -169,27 +169,54 @@ class BEVY_COMPONENTS_PT_AdvancedToolsPanel(bpy.types.Panel):
|
||||
row.label(text="WARNING ! The following operations will overwrite your existing custom properties if they have matching types on the bevy side !")
|
||||
row.alert = True
|
||||
|
||||
##
|
||||
row = layout.row()
|
||||
custom_properties_from_components_progress_current = context.window_manager.custom_properties_from_components_progress
|
||||
|
||||
if custom_properties_from_components_progress_current == -1.0:
|
||||
row.operator(COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT.bl_idname, text="update custom properties of current object" , icon="LOOP_FORWARDS")
|
||||
row.enabled = registry_has_type_infos and selected_object is not None
|
||||
else:
|
||||
if hasattr(layout,"progress") : # only for Blender > 4.0
|
||||
layout.progress(factor = custom_properties_from_components_progress_current, text=f"updating {custom_properties_from_components_progress_current * 100.0:.2f}%")
|
||||
|
||||
layout.separator()
|
||||
row = layout.row()
|
||||
custom_properties_from_components_progress_all = context.window_manager.custom_properties_from_components_progress_all
|
||||
|
||||
if custom_properties_from_components_progress_all == -1.0:
|
||||
row.operator(COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_ALL.bl_idname, text="update custom properties of ALL objects" , icon="LOOP_FORWARDS")
|
||||
row.enabled = registry_has_type_infos
|
||||
else:
|
||||
if hasattr(layout,"progress") : # only for Blender > 4.0
|
||||
layout.progress(factor = custom_properties_from_components_progress_all, text=f"updating {custom_properties_from_components_progress_all * 100.0:.2f}%")
|
||||
|
||||
########################
|
||||
|
||||
row = layout.row()
|
||||
row.label(text="WARNING ! The following operations will try to overwrite your existing ui values if they have matching types on the bevy side !")
|
||||
row.alert = True
|
||||
|
||||
components_from_custom_properties_progress_current = context.window_manager.components_from_custom_properties_progress
|
||||
|
||||
row = layout.row()
|
||||
if components_from_custom_properties_progress_current == -1.0:
|
||||
row.operator(COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT.bl_idname, text="update UI FROM custom properties of current object" , icon="LOOP_BACK")
|
||||
row.enabled = registry_has_type_infos and selected_object is not None
|
||||
else:
|
||||
if hasattr(layout,"progress") : # only for Blender > 4.0
|
||||
layout.progress(factor = components_from_custom_properties_progress_current, text=f"updating {components_from_custom_properties_progress_current * 100.0:.2f}%")
|
||||
|
||||
layout.separator()
|
||||
row = layout.row()
|
||||
components_from_custom_properties_progress_all = context.window_manager.components_from_custom_properties_progress_all
|
||||
|
||||
if components_from_custom_properties_progress_all == -1.0:
|
||||
row.operator(COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL.bl_idname, text="update UI FROM custom properties of ALL objects" , icon="LOOP_BACK")
|
||||
row.enabled = registry_has_type_infos
|
||||
else:
|
||||
if hasattr(layout,"progress") : # only for Blender > 4.0
|
||||
layout.progress(factor = components_from_custom_properties_progress_all, text=f"updating {components_from_custom_properties_progress_all * 100.0:.2f}%")
|
||||
|
||||
|
||||
class BEVY_COMPONENTS_PT_MissingTypesPanel(bpy.types.Panel):
|
||||
|
Loading…
Reference in New Issue
Block a user