bpy.ops.action.new() does nothing when invoked from script
Open, NormalPublic


System Information
Win 8.1, GTX1070

Blender Version
Broken: 2.78c e92f235283

Short description of error
bpy.ops.action.new() does nothing when invoked from a script. Maybe you're not supposed to but then why is it listed in the API?

Exact steps for others to reproduce the error
Create some object. Create an action in the action editor. Open a text editor and write

import bpy
bpy.context.area.type = 'DOPESHEET_EDITOR'
bpy.context.space_data.mode = 'ACTION'
bpy.context.area.type = 'TEXT_EDITOR'

and click run script. Nothing happens. I would expect the same thing happening that happens when you click the add action button in the UI: a new action is created with identical keyframes and then selected in the action editor list automatically.

edit: changed from Addons to BF Blender tag.



to test:
On default cube, insert keyfame 0, move timeline to 100, scale & move the cube, insert keyframe.
run this:

import bpy
bpy.context.area.type = 'DOPESHEET_EDITOR'
bpy.context.space_data.mode = 'ACTION'

A new action is created as expected.

Closing as invalid.

What? You created the action when inserting the keyframes...

But I guess I can be more clear about what's wrong.

  1. Default cube, insert keyframe on 0, move to 100, insert another keyframe.
  2. Open the action editor and confirm that an action called CubeAction was created when inserting the keyframes.
  3. Click the + sign in the action editor to create a new action. A new action called CubeAction.001 is created.
  4. Now in the text editor, paste the code I wrote at the top and run it. No new action is created. This is a bug, what I expect is that a new action called CubeAction.002 is created, just like when pressing the + button in the action editor.

hi, ok, getting it now.
I think probably this is a more a python support issue, I see now that indeed you are correct & your code does fail.
have you looked at blender stackexchange for similar questions?
it would seem to be that to do this by py you need to set a keyframe first?
also unsure if contexts for this operator are correct or need to be set.

I saw in the Blenderartist forums that someone had the same problem, the advice that was given was to "not use the operator", which seems like a bad workaround if you really want the same behavior. I really like the + button operator, it creates a new action with the same name+.001, selects it in the action editor automatically and even copies all of the keyframes from the previous animation. Basically great for when you're making for example looping variations. The only problem with it is that it doesn't work in scripts right now.

I think the context for the operator should be correct, if you remove the bpy.context.area.type = 'DOPESHEET_EDITOR'
bpy.context.space_data.mode = 'ACTION' stuff you get a polling error. But if you execute those commands you don't get an error. To me this means that it should be correct. Nothing happens though which is a bit strange. If you're not supposed to be able to use the operator in scripts I would expect an error explaining why it can't be used. But if it's really a bug that it doesn't do anything right now I would be happy if it could be fixed.

reopening for more investigation

Brendon Murphy (meta-androcto) triaged this task as Normal priority.Apr 7 2017, 8:26 AM
Henrik Berglund (cyaoeu) edited projects, added BF Blender; removed Addons.