I'm trying to write a script that would delete all custom attributes for multiple selected objects except the 'backed' ones such as position. With some Chat-GPT help I ended up with this code
But the problem with this code is that it behaves differently depending on what attribute you've selected, and if you have attributes with different Domain types, it will only work for the attributes of the domain type that you've selected in the active object, leaving the attributes of other domain types present.
import bpy
selected_objects = bpy.context.selected_objects
for obj_index, obj in enumerate(selected_objects):
bpy.context.view_layer.objects.active = obj
for i in range(9999):
try:
bpy.ops.geometry.attribute_remove()
except:
break
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.shade_smooth()
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.mark_sharp(clear=True)
bpy.ops.object.mode_set(mode='OBJECT')
for i in range(9999):
try:
bpy.ops.mesh.uv_texture_remove()
except:
break
if obj_index + 1 < len(selected_objects):
bpy.context.view_layer.objects.active = selected_objects[obj_index + 1]