How to delete an fcurve modifier

Hi once again :slight_smile:

I’m trying to add a driver through .add_driver() But, the funny thing is that the default behavior is to add a generator modifier, although I need the fcurve. How do I delete that through code, cuz when I hover over the remove button, I can get no pyhton help from Blender :frowning:

Thanx and cheers;

AJ

I see what you mean. It is not as easy as a single line, but you can drill down into fcurves and examine their modifier stack. The only way I could detect a modifier for deletion was by comparing to it’s RNA_PATH.

This code expects the default cube to have a location animation with a noise modifier applied to the fcurve.


import bpy

ob = bpy.data.objects.get("Cube")
ad = ob.animation_data
fcurves = ad.action.fcurves
print("

")
print(ad.action.name)
for f in fcurves:
    mod_to_remove = None
    for mod in f.modifiers:
        if str(mod.rna_type) == '<bpy_struct, Struct("FModifierNoise")>':
            mod_to_remove = mod
    if mod_to_remove != None:
        print ("Attempting to remove the noise modifier")
        f.modifiers.remove(mod_to_remove)
    else:
        print ("Failed to detect the noise modifier")

After running the code, the fcurve modifier should be removed.

Thanx a mil Atom, appreciate it :slight_smile:

Cheers;

AJ