Maxwell Render

Maxwell Render Information Repository
It is currently Mon May 20, 2013 10:52 am

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Mon Apr 02, 2012 12:50 pm 
User avatar

Joined: Sun Mar 20, 2005 5:44 pm
Posts: 2298
Location: plains of fucking gorgoroth !
hi !

is there a way (using Python) to 'call' pyMaxwell, so a specific .py file gets directly executed ?

in other words :
- start pyMaxwell instance (if needed with GUI or just as a batch process does not matter)
- execute provided code
- kill instance

:?:

any help very welcome !

cheers !

_________________
Death Metal Team

http://www.esri.com/software/cityengine/


Top
 Profile  
 
PostPosted: Mon Apr 02, 2012 3:29 pm 
User avatar

Joined: Tue Nov 24, 2009 4:52 pm
Posts: 176
PyMaxwell python editor have some command-line options (try pymaxwell.exe -help):

pymaxwell [-nogui] [-runscript] [scriptfilename]

So you can run your .py code using pymaxwell this way:

pymaxwell -nogui -runscript yourpythoncode.py

(I'll try to update the documentation for this asap!)

_________________
Next Limit Team


Top
 Profile  
 
PostPosted: Mon Apr 02, 2012 4:32 pm 
User avatar

Joined: Sun Mar 20, 2005 5:44 pm
Posts: 2298
Location: plains of fucking gorgoroth !
hi !

very cool & good to know ! :)

1 issue :

this works :
Code:
import subprocess
app = "C:/Program Files/Next Limit/Maxwell 2/pymaxwell.exe"
file = "D:/DATA/../myFile.py"
subprocess.call([app, "-runscript", file])


but this doesn't do anything :
Code:
import subprocess
app = "C:/Program Files/Next Limit/Maxwell 2/pymaxwell.exe"
file = "D:/DATA/../myFile.py"
subprocess.call([app, "-nogui", "-runscript", file])


is there something wrong with that syntax ?

let me know ..

pyMaxwell is great !

ps. is it planned to expand to maxwell studio ?

_________________
Death Metal Team

http://www.esri.com/software/cityengine/


Top
 Profile  
 
PostPosted: Mon Apr 02, 2012 6:43 pm 
User avatar

Joined: Tue Nov 24, 2009 4:52 pm
Posts: 176
If you're running the code in pymaxwell.exe (pymaxwell calling itself! :P) I'm not sure that pymaxwell.exe will be able to capture subprocess output (I'm afraid not).

If you want (and you beliebe that's will be useful, it seems that it will be), I can add a python function to pymaxwell like this:

runScript(scriptfile);

If you are running pymaxwell from python.exe, it should work fine so I need to investigate a little more.

Don't expect python scripting in studio soon, but is in the agenda ;)

_________________
Next Limit Team


Top
 Profile  
 
PostPosted: Mon Apr 02, 2012 7:35 pm 
User avatar

Joined: Sun Mar 20, 2005 5:44 pm
Posts: 2298
Location: plains of fucking gorgoroth !
hi, nope, not calling it from itself.. externally [ using Jython from within CityEngine ].

but a runScript() function would be cool, of course !

can you give me a hint then on the following :
I guess currently, it is then impossible to create any script which imports a series of obj files in Studio and then assigns a specified referenced material ?

cheers !




Brany wrote:
If you're running the code in pymaxwell.exe (pymaxwell calling itself! :P) I'm not sure that pymaxwell.exe will be able to capture subprocess output (I'm afraid not).

If you want (and you beliebe that's will be useful, it seems that it will be), I can add a python function to pymaxwell like this:

runScript(scriptfile);

If you are running pymaxwell from python.exe, it should work fine so I need to investigate a little more.

Don't expect python scripting in studio soon, but is in the agenda ;)

_________________
Death Metal Team

http://www.esri.com/software/cityengine/


Top
 Profile  
 
PostPosted: Tue Apr 03, 2012 11:30 am 
User avatar

Joined: Tue Nov 24, 2009 4:52 pm
Posts: 176
deadalvs wrote:
hi, nope, not calling it from itself.. externally [ using Jython from within CityEngine ].


The right way to run python scripts that uses the PyMaxwell module is copying it in your platform python folder for external packages. The bad news are that CitiBuilder uses Python 2.5, and we support only 2.6 and above. So it seems that the only way to run scripts that uses the PyMaxwell python module is calling an external interpreter. Calling pymaxwell.exe is a good idea, but pymaxwell.exe is not concibed to be runned from external applications, so it doesn't return the result of the script after running it (and it may fail sometimes).

You can try calling python.exe instead of pymaxwell.exe that way:

import subprocess
app = "C:/Python26/python.exe"
file = "D:/DATA/../myFile.py"
subprocess.call([app, file])

To do that, you must install Python 2.6 (if you don't have it, http://www.python.org/download/releases/2.6.6/), and copy the files pymaxwell.py and _pymaxwell.pyd from here:
C:\Program Files\Next Limit\Maxwell 2\python\pymaxwell\python2.6
to here:
C:\Python26\Lib\site-packages

Both Maxwell and Python must be 32-bits or 64-bits, no mixing!

deadalvs wrote:
but a runScript() function would be cool, of course !


I've just realized that python 2 have a function that do that: execfile(scriptfilename); ;)

deadalvs wrote:
can you give me a hint then on the following :
I guess currently, it is then impossible to create any script which imports a series of obj files in Studio and then assigns a specified referenced material ?


The only way to do that for now is implementing a python script that opens the .mxs scene, creates a new object (Cmaxwell::createMesh(..)), and populate it with the geometry readed from the .obj file using the following methods: CmaxwellObject::setVertex(...), CmaxwellObject::setTriangle(...), CmaxwellObject::setNormal(...). Is not an easy

_________________
Next Limit Team


Top
 Profile  
 
PostPosted: Tue Apr 03, 2012 10:37 pm 
User avatar

Joined: Sun Mar 20, 2005 5:44 pm
Posts: 2298
Location: plains of fucking gorgoroth !
hi !

In general, I'd not need to return a result, so calling pyMaxwell.exe is totally okay for me and this works. The only thing I noticed (couple posts above) that it just does not work with the "-nogui" flag. Do you have the feeling this could be a pyMaxwell issue (flag handling) ?

greetings and thanks for the inputs !

_________________
Death Metal Team

http://www.esri.com/software/cityengine/


Top
 Profile  
 
PostPosted: Wed Apr 04, 2012 11:13 am 
User avatar

Joined: Tue Nov 24, 2009 4:52 pm
Posts: 176
I've just try this in CitiEngine, and it works:

Code:
import subprocess
app = 'C:/Program Files/Next Limit/Maxwell 2/pymaxwell.exe'
file = 'C:/Program Files/Next Limit/Maxwell 2/scripts/python/replicate_sphere.py'
subprocess.call([app,'-nogui','-runscript', file])


I guess your script is failing someway. Maybe you can find out running the same command in ms-dos (I made a mistake in the last post, pymaxwell.exe prints the result in the console if you use the -nogui flag). Try something like this in a MS-DOS command prompt:

"C:\Program Files\Next Limit\Maxwell 2\pymaxwell.exe" -nogui -runscript "D:\DATA\yourscript.py"

It should return the same result as calling pymaxwell.exe using subprocess in python (that's what you're doing in CitiEngine), so if the MS-DOS command fails, the script you're running in CitiEngine failed too.

_________________
Next Limit Team


Top
 Profile  
 
PostPosted: Wed Apr 04, 2012 2:16 pm 
User avatar

Joined: Sun Mar 20, 2005 5:44 pm
Posts: 2298
Location: plains of fucking gorgoroth !
hi ..


as you mentioned, the same behavior as from CityEngine.

again, via console, the '-runscript' flag works --> the file is opened
but with both flags, I get this error :
Image

[ if you want, I can send you the files to reproduce .. ]

_________________
Death Metal Team

http://www.esri.com/software/cityengine/


Top
 Profile  
 
PostPosted: Wed Apr 04, 2012 4:02 pm 
User avatar

Joined: Tue Nov 24, 2009 4:52 pm
Posts: 176
That python syntax error in the line "from pymaxwell import *" is very strange. Maybe the .py file was created in an environment with different "new line" characters (like linux)?

A .py failing would be helpful!

_________________
Next Limit Team


Top
 Profile  
 
PostPosted: Wed Apr 04, 2012 4:31 pm 
User avatar

Joined: Sun Mar 20, 2005 5:44 pm
Posts: 2298
Location: plains of fucking gorgoroth !
hi !

see PM .. ;)

_________________
Death Metal Team

http://www.esri.com/software/cityengine/


Top
 Profile  
 
PostPosted: Wed Apr 04, 2012 5:36 pm 
User avatar

Joined: Tue Nov 24, 2009 4:52 pm
Posts: 176
I receive your .py script. Good news, I've found the problem! Your .py file have "carriage returns" instead of "new lines" in some lines, and it seems that Python API doesn't like strings with carriage returns as input commands... so you found a bug in pymaxwell.exe

I fixed that replacing all the "carriage returns" with "new lines" and it works. I have to check it with linux and osx, but I can send you a fixed pymaxwell.exe, see your PM inbox ;)

_________________
Next Limit Team


Top
 Profile  
 
PostPosted: Wed Apr 04, 2012 6:10 pm 
User avatar

Joined: Sun Mar 20, 2005 5:44 pm
Posts: 2298
Location: plains of fucking gorgoroth !
HA !

and it works now with the new build no my side too .. ! thanks a lot for tracking this down. that was a nice session !


GREAT support !!

have a nice easter holiday !

matt

_________________
Death Metal Team

http://www.esri.com/software/cityengine/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC + 1 hour [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group