Hi all,
I have an idea for a distributed internet based rendering solution, but I am having problems with one little part of my Python Script.
I am able to render a single frame from the dos command line, but I am unable to start that same command externally from Python.
This is to be run from "regular" Python, not the python utilities from within Blender.
From the command line I have been able to run:
blender -B filename -f framenumber
I have tried calling this command from Python using:
os.popen('blender -B filename -f framenumber')
or
os.system('blender -B filename -f framenumber')
... with no success.
Any Ideas?
Am I doing something wrong?
Is Python able to call and run external programs?
mmabob
Thanks Jamesk,
I'll have to try that when I get home tonight.
Okay, I've retried popen, system and spawn in the Python IDLE...
Here's what I get.
I typed "import os" first of course.
When I type:
os.system('c:/Blender/farm/blender.exe -b c:\blender\projects\testp.blend -f 170')
The screen goes to a full screen black screen for a brief split second
and Python returns:
0
When I type:
os.popen('c:/Blender/farm/blender.exe -b c:\blender\projects\testp.blend -f 170')
The screen does not change like in the first example
and Python returns:
<open file 'c:/Blender/farm/blender.exe -b c:lender\projects estp.blend -f 170', mode 'r' at 0x00AA0270>
Whn I type:
os.spawnl(os.P_WAIT, 'c:/Blender/farm/blender.exe -b c:\blender\projects\testp.blend -f 170')
The screen does not change like in the first example
and Python returns:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in ?
os.spawnl(os.P_WAIT, 'c:/Blender/farm/blender.exe -b c:\blender\projects\testp.blend -f 170')
File "C:\PYTHON22\lib\os.py", line 530, in spawnl
return spawnv(mode, file, args)
OSError: [Errno 2] No such file or directory
So like I said, I'm not really getting any success...
Has anybody successfuly called a background instance of Blender from a Python script?
If so, could you please help me out with the coding...
Thanks all.
The os.popen seems to work fine in your case since it returns a open file object. So all you have to do is read every single line of that file to get blenders textual output ("Saved: Blahblahblah Blender quit") and do a close() afterwards to get the returncode.
| Code: |
>>> import os
>>> render = os.popen('blender2.26 -b muardini0024.blend -f 1')
>>> for x in render.readlines():
... print x
|
Now blender should render. Next step:
| Code: |
>>> y = of.close()
>>> print y
|
If the print statement gives you None everything is fine (termination without errors).
HTH
Stay Rude!
Okay, okay...
I figured it out.
I needed to os.chdir() to the dirctory containing blender.exe before simply running os.system('blender.exe -b ...etc.')
Thanks for your help everyone!
Hello , I am new to this forum, but maybe this will help.
In your example you did this:
| mmabob wrote: |
os.spawnl(os.P_WAIT, 'c:/Blender/farm/blender.exe -b c:\blender\projects\testp.blend -f 170')
|
The problem is with / and \ .
In python / is ok ,but \ needs to be escaped with another \ .
Like this:
| Code: |
| "c:\\windows\\temp" |
This is basic python ,but easy to goof .
| mmabob wrote: |
I needed to os.chdir() to the dirctory containing blender.exe before simply running os.system('blender.exe -b ...etc.')
|
That works because you bypassed your errored \.
Try this:
| Code: |
| os.spawnl(os.P_WAIT, 'c:\\blender\\farm\\blender.exe -b c:\\blender\\projects\\testp.blend -f 170') |
or use raw strings:
| Code: |
| os.spawnl(os.P_WAIT, r'c:\blender\farm\blender.exe -b c:\blender\projects\testp.blend -f 170') |
Hope this helps.
Thanks M.E.Farmer,
That`s exactly what the problem was.