Previous Thread  Next Thread

chat icon Start External Blender Command Line from "regular"

mmabob

Posted: Tue Mar 11, 2003 7:06 pm
Joined: 04 Dec 2002
Posts: 8
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
Reply with quote


Jamesk

Posted: Tue Mar 11, 2003 8:14 pm
Joined: 14 Oct 2002
Posts: 239
mmabob wrote:

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


It is able. Try checking the python docs on the spawn-command and it's closest relatives...
Reply with quote


Schlops

Posted: Tue Mar 11, 2003 10:00 pm
Joined: 16 Oct 2002
Posts: 20
mmabob wrote:

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.


Please define "No success" Wink
Error messages? Nothing happens? XSI instead of blender starting? popen should work fine, maybe do a x = os.popen('blender -B filename -f framenumber') and a print x afterwards. What is x?
_________________
Stay Rude!
Reply with quote


mmabob

Posted: Tue Mar 11, 2003 10:00 pm
Joined: 04 Dec 2002
Posts: 8
Thanks Jamesk,

I'll have to try that when I get home tonight.
Reply with quote


mmabob

Posted: Tue Mar 11, 2003 10:20 pm
Joined: 04 Dec 2002
Posts: 8
Schlops wrote:

Please define "No success" Wink
Error messages? Nothing happens? XSI instead of blender starting? popen should work fine, maybe do a x = os.popen('blender -B filename -f framenumber') and a print x afterwards. What is x?


Depending on the comand, either nothing happens (Python accepts the command and moves on) or the "most success" I've had is using one of the commands I'll see a full screen black window try to open for a split second, then Python returns with no errors again.

In both cases, there was no evidence of Blender working in the background, and there was obviously no rendered frame in the output folder.
Reply with quote


mmabob

Posted: Wed Mar 12, 2003 6:29 am
Joined: 04 Dec 2002
Posts: 8
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.
Reply with quote


Schlops

Posted: Wed Mar 12, 2003 12:08 pm
Joined: 16 Oct 2002
Posts: 20
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!
Reply with quote


mmabob

Posted: Thu Mar 13, 2003 6:04 am
Joined: 04 Dec 2002
Posts: 8
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!
Reply with quote


M.E.Farmer

Posted: Fri Mar 14, 2003 5:45 am
Joined: 14 Mar 2003
Posts: 3
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')

Wink Hope this helps.
Reply with quote


mmabob

Posted: Wed Mar 19, 2003 10:30 pm
Joined: 04 Dec 2002
Posts: 8
Thanks M.E.Farmer,

That`s exactly what the problem was.
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group