1
$\begingroup$

I am currently working on a web app which spits out a .stl file in blender. I have used php and I am calling the script in php using exec(). Please look at the code below. I found the code from https://stackoverflow.com/questions/23563809/php-running-a-python-scrip-using-blender-from-a-php-project-using-cmd-commands

$script = "C:\\xampp\\htdocs\\test\\test.py";
$blender_path = "C:\Program Files\Blender Foundation\Blender";

$output = exec("cd $blender_path && blender -b -P $script", $data);
echo "<pre>";
print_r($data);
echo "</pre>";

And all works well locally. I uploaded the content to my site(Linux hosting), Uploaded Blender(Linux - https://www.blender.org/download/) changed the paths and nothing happens. It doesn't even output any errors. Is there a separate command line code for linux? I am not used to using Linux and I have been struggling with this for the past 3 days.

Any help is appreciated.

$\endgroup$
1
$\begingroup$

I'd start with running the script with test parameters directly from the terminal on your server using SSH. If you get the expected results from the terminal, then something with the way you're executing the script in PHP is the problem.

You might also see output that you wouldn't through your PHP script (blender spews out various output to the standard output and error streams).

Also, if your script imports from other scripts or addons, you need to include them using another pair of command line params in your script:

blender -b --addons addon1,addon2,script3 -P yourscript.py

Make sure to list all the addons and scripts after the --addons in one string without spaces (the entire comma separated list is one command line parameter).

You don't need to list standard blender or python libraries in the --addons list (bpy, bge, os, math, mathutils, etc), but if you're importing any of blender's addons, or any custom addons or libraries of your own you must include them.

Addons and script files listed in the --addons list must be present in one of the paths available to the blender script. If you're not sure what's included, save this little script locally on your server and run this it from the terminal on your server:

import sys
print( sys.path )

Assuming you saved this as "print_path.py":

>> blender -b -P print_path.py

You can either copy or create a symbolic link to these libraries and addons in one of the blender $PATH folders to make them available to your blender script.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.