Can't run bpy.ops.anim.channels_delete() in my script

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

john.cfng
Posts: 3
Joined: Sun Sep 30, 2012 11:44 am

Can't run bpy.ops.anim.channels_delete() in my script

Postby john.cfng » Fri Oct 12, 2012 6:43 am

Hi all,

I tried to use script to remove particular animation channels of an object.
here are the scripts after setting the .select of the channels to True of those channels
area_type_original = bpy.context.area.type
bpy.context.area.type = 'GRAPH_EDITOR'
bpy.ops.anim.channels_delete()
bpy.context.area.type = area_type_original
however, channels are not deleted

Blender returns False If I replace the line bpy.ops.anim.channels_delete() to bpy.ops.anim.channels_delete.poll()

I tried changing the area type to 'DOPESHEET_EDITOR', but this also failed

Would any one please help me with this? what should I do to delete specific animation channels?

System information: Blender 2.63a, Win7 64bit English

Thank you very much.
JNg

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Fri Oct 12, 2012 8:40 am

I would rather use low-level functions like this:

Code: Select all

action = bpy.context.object.animation_data.action

for f in action.fcurves:

    # find X Location fcurve
    if f.data_path == 'location' and f.array_index == 1:
        a.fcurves.remove(f)
        break
I'm sitting, waiting, wishing, building Blender in superstition...

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Fri Oct 12, 2012 8:41 am

sorry, it's Y Location (array_index 0 = X, 1 = Y, 2 = Z / if it's a quaternion then 0-3 = wxyz)
I'm sitting, waiting, wishing, building Blender in superstition...

john.cfng
Posts: 3
Joined: Sun Sep 30, 2012 11:44 am

Postby john.cfng » Fri Oct 12, 2012 9:44 am

Hi CoDEmanX,

Thank you very much. It works great! Problem solved.


Return to “Python”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 2 guests