Run animation using Python API

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
freshquiz
Posts: 0
Joined: Thu Feb 09, 2012 11:24 pm

Run animation using Python API

Post by freshquiz » Tue May 14, 2013 8:46 am

Hi guys,

I am currently using Blender to try and act as a physics simulator which gets invoked from the command line via this command:

Code: Select all

blender scene.blend --background --python script.py
My Blender file is customised to my needs and the script.py file does the following:
1) Imports various OBJ files from the file system.
2) Applies some modifiers to them (e.g. cloth)
3) Tries to play the animation, in order to get the imported objects to come under the effects of physics (i.e. morph under gravity).
4) Export the resulting scene into an OBJ file.

The problem I am having is with step 3). For some reason the exported OBJ file does not show results of being affected by physics (i.e. the animation).
I am trying to "play" the animation by progressively incrementing the current frame of the scene until the last frame.
I have tried doing this:

Code: Select all

bpy.context.scene.frame_current += 1
bpy.context.scene.update()
and I have also tried:

Code: Select all

bpy.context.scene.frame_set(bpy.context.scene.frame_current + 1)
Can someone please tell me what I am doing wrong.

Cheers,
Matt

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

Post by CoDEmanX » Tue May 14, 2013 8:48 am

frame_set() is required to have everything updated, but if that doesn't work, not sure about the problem...
I'm sitting, waiting, wishing, building Blender in superstition...

freshquiz
Posts: 0
Joined: Thu Feb 09, 2012 11:24 pm

Post by freshquiz » Tue May 14, 2013 10:03 am

OK.

Well I am not getting errors, so it's really strange why it's not working.

I don't know if this will help, but I noticed that if I used pdb to step through the frame_set() loop, the first call to frame_set() lag for a second or two, while the rest of the calls happen instantaneously.

That seems a little strange to me, but may it's nothing.

Also, it may have something to do with the fact that I am using Linux (Ubuntu Server), maybe I should try using another OS (maybe Windows).

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

Post by CoDEmanX » Tue May 14, 2013 11:15 am

does it work if you run this script in the UI (so no background mode)?
I'm sitting, waiting, wishing, building Blender in superstition...

freshquiz
Posts: 0
Joined: Thu Feb 09, 2012 11:24 pm

Post by freshquiz » Tue May 14, 2013 3:33 pm

Seeing as I am running Ubuntu Server and interacting with the machine via SSH, that is not something I can test.

I did however try running the script on my local Windows machine and it works both in GUI and command line/background modes. So this is telling me that there is an OS issue at hand, but I could be wrong.

Could you think of why that might be?

In the mean time I will try running the script in both modes on my local Ubuntu machine to see if it works.

freshquiz
Posts: 0
Joined: Thu Feb 09, 2012 11:24 pm

Post by freshquiz » Tue May 14, 2013 10:33 pm

I should also point out that the two Windows trials (GUI and command line) produced results, but quite different ones, which is very strange to me.

Why would there be a difference in results within the same version on the same OS?

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

Post by CoDEmanX » Tue May 14, 2013 10:49 pm

good question... better ask the devs, maybe there's a bug?
I'm sitting, waiting, wishing, building Blender in superstition...

freshquiz
Posts: 0
Joined: Thu Feb 09, 2012 11:24 pm

Post by freshquiz » Tue May 21, 2013 6:27 am

I tested GUI vs command line on my netbook running Ubuntu and the results were as expected and consistent between both.

I then downloaded a different build of Blender for Ubuntu server (where the physics was not occurring) and that has done the trick, it is finally working. I think it may have been because I developed the .blend file with Blender 2.61 and was using Blender 2.65 to run it on the server.

Downloaded Blender 2.61 and that did the trick.

Thanks for your help CoDEmanX.

Post Reply