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 deletion of components individual & bulk
* a few other minor tweaks
This commit is contained in:
parent
63bac03c7c
commit
c5af203a94
@ -16,7 +16,7 @@ from bpy.props import (StringProperty)
|
|||||||
|
|
||||||
from .helpers import load_settings
|
from .helpers import load_settings
|
||||||
from .blueprints import CreateBlueprintOperator
|
from .blueprints import CreateBlueprintOperator
|
||||||
from .components.operators import CopyComponentOperator, OT_rename_component, RemoveComponentOperator, GenerateComponent_From_custom_property_Operator, PasteComponentOperator, AddComponentOperator, RenameHelper, Toggle_ComponentVisibility
|
from .components.operators import CopyComponentOperator, OT_rename_component, RemoveComponentFromAllObjectsOperator, RemoveComponentOperator, GenerateComponent_From_custom_property_Operator, PasteComponentOperator, AddComponentOperator, RenameHelper, Toggle_ComponentVisibility
|
||||||
|
|
||||||
from .registry.registry import ComponentsRegistry,MissingBevyType
|
from .registry.registry import ComponentsRegistry,MissingBevyType
|
||||||
from .registry.operators import (COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_ALL, COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT, COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL, COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT, OT_select_component_name_to_replace, OT_select_object, ReloadRegistryOperator, OT_OpenFilebrowser)
|
from .registry.operators import (COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_ALL, COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT, COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL, COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT, OT_select_component_name_to_replace, OT_select_object, ReloadRegistryOperator, OT_OpenFilebrowser)
|
||||||
@ -87,6 +87,7 @@ classes = [
|
|||||||
CopyComponentOperator,
|
CopyComponentOperator,
|
||||||
PasteComponentOperator,
|
PasteComponentOperator,
|
||||||
RemoveComponentOperator,
|
RemoveComponentOperator,
|
||||||
|
RemoveComponentFromAllObjectsOperator,
|
||||||
OT_rename_component,
|
OT_rename_component,
|
||||||
RenameHelper,
|
RenameHelper,
|
||||||
GenerateComponent_From_custom_property_Operator,
|
GenerateComponent_From_custom_property_Operator,
|
||||||
|
@ -91,9 +91,42 @@ class PasteComponentOperator(Operator):
|
|||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
class RemoveComponentOperator(Operator):
|
class RemoveComponentOperator(Operator):
|
||||||
"""Delete component from blueprint"""
|
"""Remove component from object"""
|
||||||
bl_idname = "object.remove_bevy_component"
|
bl_idname = "object.remove_bevy_component"
|
||||||
bl_label = "Delete component from blueprint Operator"
|
bl_label = "Remove component from object Operator"
|
||||||
|
bl_options = {"UNDO"}
|
||||||
|
|
||||||
|
component_name: StringProperty(
|
||||||
|
name="component name",
|
||||||
|
description="component to delete",
|
||||||
|
) # type: ignore
|
||||||
|
|
||||||
|
object_name: StringProperty(
|
||||||
|
name="object name",
|
||||||
|
description="object whose component to delete",
|
||||||
|
default=""
|
||||||
|
) # type: ignore
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
if self.object_name == "":
|
||||||
|
object = context.object
|
||||||
|
else:
|
||||||
|
object = bpy.data.objects[self.object_name]
|
||||||
|
|
||||||
|
print("removing component ", self.component_name, "from object '"+object.name+"'")
|
||||||
|
|
||||||
|
if object is not None and self.component_name in object:
|
||||||
|
remove_component_from_object(object, self.component_name)
|
||||||
|
else:
|
||||||
|
self.report({"ERROR"}, "The object/ component to remove ("+ self.component_name +") does not exist")
|
||||||
|
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
|
class RemoveComponentFromAllObjectsOperator(Operator):
|
||||||
|
"""Remove component from all object"""
|
||||||
|
bl_idname = "object.remove_bevy_component_all"
|
||||||
|
bl_label = "Remove component from all objects Operator"
|
||||||
bl_options = {"UNDO"}
|
bl_options = {"UNDO"}
|
||||||
|
|
||||||
component_name: StringProperty(
|
component_name: StringProperty(
|
||||||
@ -102,14 +135,12 @@ class RemoveComponentOperator(Operator):
|
|||||||
) # type: ignore
|
) # type: ignore
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
object = context.object
|
print("removing component ", self.component_name, "from all objects")
|
||||||
|
|
||||||
print("removing component ", self.component_name, "from object '"+object.name+"'")
|
for object in bpy.data.objects:
|
||||||
|
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)
|
||||||
else:
|
|
||||||
self.report({"ERROR"}, "The object/ component to remove ("+ self.component_name +") does not exist")
|
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import bpy
|
|||||||
from bpy_types import (UIList)
|
from bpy_types import (UIList)
|
||||||
from bpy.props import (StringProperty)
|
from bpy.props import (StringProperty)
|
||||||
|
|
||||||
from ..components.operators import OT_rename_component
|
from ..components.operators import OT_rename_component, RemoveComponentFromAllObjectsOperator, RemoveComponentOperator
|
||||||
from .operators import(
|
from .operators import(
|
||||||
COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL,
|
COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL,
|
||||||
COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT,
|
COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT,
|
||||||
@ -52,7 +52,7 @@ class BEVY_COMPONENTS_PT_Configuration(bpy.types.Panel):
|
|||||||
class BEVY_COMPONENTS_PT_AdvancedToolsPanel(bpy.types.Panel):
|
class BEVY_COMPONENTS_PT_AdvancedToolsPanel(bpy.types.Panel):
|
||||||
"""panel listing all the missing bevy types in the schema"""
|
"""panel listing all the missing bevy types in the schema"""
|
||||||
bl_idname = "BEVY_COMPONENTS_PT_AdvancedToolsPanel"
|
bl_idname = "BEVY_COMPONENTS_PT_AdvancedToolsPanel"
|
||||||
bl_label = "Advanced tools & configuration"
|
bl_label = "Advanced tools"
|
||||||
bl_space_type = 'VIEW_3D'
|
bl_space_type = 'VIEW_3D'
|
||||||
bl_region_type = 'UI'
|
bl_region_type = 'UI'
|
||||||
bl_category = "Bevy Components"
|
bl_category = "Bevy Components"
|
||||||
@ -86,53 +86,64 @@ class BEVY_COMPONENTS_PT_AdvancedToolsPanel(bpy.types.Panel):
|
|||||||
col.label(text="-----")
|
col.label(text="-----")
|
||||||
|
|
||||||
for object in bpy.data.objects: # TODO: very inneficent
|
for object in bpy.data.objects: # TODO: very inneficent
|
||||||
if "components_meta" in object:
|
if len(object.keys()) > 0:
|
||||||
components_metadata = object.components_meta.components
|
if "components_meta" in object:
|
||||||
comp_names = []
|
components_metadata = object.components_meta.components
|
||||||
for index, component_meta in enumerate(components_metadata):
|
comp_names = []
|
||||||
short_name = component_meta.name
|
for index, component_meta in enumerate(components_metadata):
|
||||||
if component_meta.invalid:
|
short_name = component_meta.name
|
||||||
row = layout.row()
|
if component_meta.invalid:
|
||||||
col = row.column()
|
row = layout.row()
|
||||||
col.label(text="Invalid")
|
col = row.column()
|
||||||
col = row.column()
|
col.label(text="Invalid")
|
||||||
col.label(text=short_name)
|
col = row.column()
|
||||||
col = row.column()
|
col.label(text=short_name)
|
||||||
operator = col.operator(OT_select_object.bl_idname, text=object.name)
|
col = row.column()
|
||||||
operator.object_name = object.name
|
operator = col.operator(OT_select_object.bl_idname, text=object.name)
|
||||||
|
operator.object_name = object.name
|
||||||
|
|
||||||
col = row.column()
|
col = row.column()
|
||||||
operator = col.operator(OT_select_component_name_to_replace.bl_idname, text="select for rename")
|
operator = col.operator(OT_select_component_name_to_replace.bl_idname, text="select for rename")
|
||||||
operator.component_name = short_name
|
operator.component_name = short_name
|
||||||
|
|
||||||
if not object.name in objects_with_invalid_components:
|
col = row.column()
|
||||||
objects_with_invalid_components.append(object.name)
|
operator = row.operator(RemoveComponentOperator.bl_idname, text="", icon="X")
|
||||||
|
operator.object_name = object.name
|
||||||
|
operator.component_name = short_name
|
||||||
|
|
||||||
if not short_name in invalid_component_names:
|
if not object.name in objects_with_invalid_components:
|
||||||
invalid_component_names.append(short_name)
|
objects_with_invalid_components.append(object.name)
|
||||||
|
|
||||||
|
if not short_name in invalid_component_names:
|
||||||
|
invalid_component_names.append(short_name)
|
||||||
|
|
||||||
|
|
||||||
comp_names.append(short_name)
|
comp_names.append(short_name)
|
||||||
|
|
||||||
for custom_property in object.keys():
|
for custom_property in object.keys():
|
||||||
if custom_property != 'components_meta' and custom_property not in comp_names:
|
if custom_property != 'components_meta' and custom_property not in comp_names:
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
col = row.column()
|
col = row.column()
|
||||||
col.label(text="Unregistered")
|
col.label(text="Unregistered")
|
||||||
col = row.column()
|
col = row.column()
|
||||||
col.label(text=custom_property)
|
col.label(text=custom_property)
|
||||||
col = row.column()
|
col = row.column()
|
||||||
operator = col.operator(OT_select_object.bl_idname, text=object.name)
|
operator = col.operator(OT_select_object.bl_idname, text=object.name)
|
||||||
operator.object_name = object.name
|
operator.object_name = object.name
|
||||||
|
|
||||||
col = row.column()
|
col = row.column()
|
||||||
operator = col.operator(OT_select_component_name_to_replace.bl_idname, text="select for rename")
|
operator = col.operator(OT_select_component_name_to_replace.bl_idname, text="select for rename")
|
||||||
operator.component_name = custom_property
|
operator.component_name = custom_property
|
||||||
|
|
||||||
if not object.name in objects_with_invalid_components:
|
col = row.column()
|
||||||
objects_with_invalid_components.append(object.name)
|
operator = row.operator(RemoveComponentOperator.bl_idname, text="", icon="X")
|
||||||
if not short_name in invalid_component_names:
|
operator.object_name = object.name
|
||||||
invalid_component_names.append(custom_property)
|
operator.component_name = custom_property
|
||||||
|
|
||||||
|
if not object.name in objects_with_invalid_components:
|
||||||
|
objects_with_invalid_components.append(object.name)
|
||||||
|
if not short_name in invalid_component_names:
|
||||||
|
invalid_component_names.append(custom_property)
|
||||||
layout.separator()
|
layout.separator()
|
||||||
layout.separator()
|
layout.separator()
|
||||||
|
|
||||||
@ -158,6 +169,12 @@ class BEVY_COMPONENTS_PT_AdvancedToolsPanel(bpy.types.Panel):
|
|||||||
operator.target_objects = json.dumps(objects_with_invalid_components)
|
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 ""
|
new_name = registry.type_infos[available_components.list]['short_name'] if available_components.list in registry.type_infos else ""
|
||||||
operator.new_name = new_name
|
operator.new_name = new_name
|
||||||
|
col.enabled = registry_has_type_infos
|
||||||
|
|
||||||
|
col = row.column()
|
||||||
|
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
|
||||||
|
|
||||||
layout.separator()
|
layout.separator()
|
||||||
layout.separator()
|
layout.separator()
|
||||||
|
Loading…
Reference in New Issue
Block a user