fix(Blenvy:Blender): fixed issues with delete operator for "custom property" style components

This commit is contained in:
kaosat.dev 2024-07-16 11:03:11 +02:00
parent e394edade2
commit c1e2bb6ecf
2 changed files with 16 additions and 7 deletions

View File

@ -152,12 +152,21 @@ class BLENVY_OT_component_remove(Operator):
print("removing component ", self.component_name, "from object '"+target.name+"'")
if target is not None and 'bevy_components' in target :
component_value = get_bevy_component_value_by_long_name(target, self.component_name)
if component_value is not None:
remove_component_from_item(target, self.component_name)
else :
self.report({"ERROR"}, "The component to remove ("+ self.component_name +") does not exist")
if target is not None:
if 'bevy_components' in target:
component_value = get_bevy_component_value_by_long_name(target, self.component_name)
if component_value is not None:
remove_component_from_item(target, self.component_name)
else :
self.report({"ERROR"}, "The component to remove ("+ self.component_name +") does not exist")
else:
# for the classic "custom properties"
if self.component_name in target:
del target[self.component_name]
else:
self.report({"ERROR"}, "The component to remove ("+ self.component_name +") does not exist")
else:
self.report({"ERROR"}, "The target to remove ("+ self.component_name +") from does not exist")
return {'FINISHED'}

View File

@ -372,7 +372,7 @@ class BLENVY_PT_component_tools_panel(bpy.types.Panel):
operator.target_name = target_component_name
col.enabled = internal and registry_has_type_infos and component_name != "" and target_component_name != "" and component_name != target_component_name
#print("target", target, target.name, "component_name", component_name, "item type", get_selection_type(target))
col = row.column()
operator = col.operator("blenvy.component_remove", text="", icon="X")
operator.item_name = target.name