bpy.ops.action.new() does nothing when invoked from script #51011

Closed
opened 2017-03-20 17:52:36 +01:00 by Henrik Berglund · 14 comments

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.ops.action.new()
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.

**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.ops.action.new() 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.
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @cyaoeu

Added subscriber: @cyaoeu
Member

Added subscriber: @BrendonMurphy

Added subscriber: @BrendonMurphy
Member

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Brendon Murphy self-assigned this 2017-04-07 01:20:01 +02:00
Member

hi,
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.

hi, 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.
Author
Member

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.
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.
Member

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.

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.
Author
Member

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.

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.
Member

Changed status from 'Archived' to: 'Open'

Changed status from 'Archived' to: 'Open'
Member

reopening for more investigation

reopening for more investigation
Brendon Murphy was unassigned by Dalai Felinto 2019-12-23 16:36:45 +01:00

Added subscriber: @mano-wii

Added subscriber: @mano-wii

Analyzing the bpy.ops.action.new's code, I could see that it only works when it is called from a button.
This is because it reads the button context and gets the current action through it.
This is a bad assumption, as this operator is totally useless if called in python.

Analyzing the `bpy.ops.action.new`'s code, I could see that it only works when it is called from a button. This is because it reads the button context and gets the current action through it. This is a bad assumption, as this operator is totally useless if called in python.

This issue was referenced by 24ebed4d84

This issue was referenced by 24ebed4d841ea9828a869d917a5718c829f09430

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Germano Cavalcante self-assigned this 2020-01-23 14:45:09 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#51011
No description provided.