Results 1 to 3 of 3
  1. #1

    help: apply modiifer options with python

    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:

    Code:
    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.



  2. #2
    Member Darcvizer's Avatar
    Join Date
    Jan 2014
    Location
    Ukraine
    Posts
    135
    17 line replace
    bpy.context.object.modifiers["Decimate"].decimate_type = 'DISSOLVE'

    Code:
    import bpy
    
    
    
    sel = bpy.context.selected_objects
    for i in sel:
        bpy.ops.object.mode_set(mode='EDIT')
        bpy.ops.mesh.select_all(action='SELECT')
        bpy.ops.mesh.remove_doubles()
        bpy.ops.mesh.select_all(action='SELECT')
        bpy.ops.mesh.dissolve_degenerate()
        bpy.ops.mesh.select_all(action='SELECT')
        bpy.ops.mesh.customdata_custom_splitnormals_clear()
        bpy.ops.mesh.select_all(action='SELECT')
        bpy.ops.mesh.normals_make_consistent(inside=False)
        bpy.ops.mesh.select_all(action='SELECT')
        bpy.ops.mesh.tris_convert_to_quads()
        bpy.ops.mesh.select_all(action='DESELECT')
        bpy.ops.object.mode_set(mode='OBJECT')
        bpy.context.scene.objects.active = i
        bpy.ops.object.modifier_add(type='DECIMATE')
        bpy.context.object.modifiers["Decimate"].decimate_type = 'DISSOLVE'
        bpy.context.object.modifiers["Decimate"].angle_limit = 0.034907
        bpy.ops.object.convert(target='MESH')
    Last edited by Darcvizer; 18-Mar-17 at 23:57.



  3. #3
    Thanks.. It works nicely.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •