All posts related to V2
User avatar
By deadalvs
#354491
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 !
User avatar
By Brany
#354500
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!)
User avatar
By deadalvs
#354503
hi !

very cool & good to know ! :)

1 issue :

this works :
Code: Select all
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: Select all
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 ?
User avatar
By Brany
#354506
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 ;)
User avatar
By deadalvs
#354511
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 ;)
User avatar
By Brany
#354538
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
User avatar
By deadalvs
#354566
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 !
User avatar
By Brany
#354581
I've just try this in CitiEngine, and it works:
Code: Select all
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.
User avatar
By deadalvs
#354583
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 .. ]
User avatar
By Brany
#354587
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!
User avatar
By Brany
#354589
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 ;)
User avatar
By deadalvs
#354590
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
Help with swimming pool water

I think you posted a while back that its best to u[…]

Sketchup 2026 Released

Considering how long a version for Sketchup 2025 t[…]

Greetings, One of my users with Sketchup 2025 (25[…]

Maxwell Rhino 5.2.6.8 plugin with macOS Tahoe 26

Good morning everyone, I’d like to know if t[…]