Hi people:
I’m having a little problem with cleaning some meshes with python. I’m trying to:
- remove doubles
- clean the mesh from degenerate geometry
- delete any custom mesh normals imported from another software
- convert quads to tris
- decimate the object using the planar option with angle of 2º
So far, so good… The problem is when i try to setup the modifier options. It doesn’t work
The script:
import bpy
if bpy.context.selected_objects != []:
for obj in bpy.context.selected_objects:
if obj.type == 'MESH':
print(obj.name)
bpy.context.scene.objects.active = obj
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.remove_doubles()
bpy.ops.mesh.dissolve_degenerate()
bpy.ops.mesh.customdata_custom_splitnormals_clear()
bpy.ops.mesh.normals_make_consistent(inside=False)
bpy.ops.mesh.tris_convert_to_quads()
bpy.ops.object.editmode_toggle()
bpy.ops.object.modifier_add(type='DECIMATE')
bpy.data.objects[obj.name].modifiers["Decimate"].decimate_type["Planar"]
bpy.data.objects[obj.name].modifiers["Decimate"].angle_limit[2]
bpy.ops.object.modifier_apply(type='DECIMATE')
Blender throws me an error at the line 17 (bpy.data.objects[obj.name]…) saying: “TypeError: string indices must be integers”. I know the code ask for a string or a number, obj.name has the name of the mesh, but i’m somewhat confused by the error.
What i’m doing wrong??.. And thanks for the answers.