OSArch Community

TypeError: ‘NoneType’ object is not subscriptable

  1. O

    I'm making a Blender script to decimate each selected object from an IFC file. But in some IFC files appears the following error: TypeError: ‘NoneType’ object is not subscriptable

    `import bpy

    def is_valid_mesh(obj):

    if obj.type == 'MESH' and obj.data and len(obj.data.vertices) > 0 and len(obj.data.polygons) > 0:
    
        return True
    
    return False

    for obj in bpy.context.selected_objects:

    if is_valid_mesh(obj):
    
        try:
    
            decimate_modifier = obj.modifiers.new(name="Decimate", type='DECIMATE')
    
            decimate_modifier.ratio = 0.1
    
            bpy.context.view_layer.objects.active = obj
    
            bpy.ops.object.modifier_apply(modifier=decimate_modifier.name)
    
            print(f"Decimate modifier applied to {obj.name}")
    
        except RuntimeError as e:
    
            print(f"Failed to apply Decimate modifier on {obj.name}: {e}")
    
    else:
    
        print(f"Skipping {obj.name} (invalid geometry)")

    try:

    bpy.ops.bim.update_representation()
    
    print("Update Representation executed successfully.")

    except RuntimeError as e:

    print(f"Failed to execute 'Update Representation': {e}")

    output_path = "route/to/output/path"

    try:

    bpy.ops.bim.save_project(filepath=output_path)
    
    print(f"IFC file exported successfully to {output_path}")

    except RuntimeError as e:

    print(f"Failed to export IFC file: {e}")`

Login or Register to reply.