2 years ago
#76178

Aleks K.
Executing console commands, Python
I have a tricky problem that I can't seem to figure out on my own.
[Goal]
I have an automation script that has a button. When that button is pressed I run Blender in background mode, use a custom script that I wrote, and then exit Blender.
[What I'm doing]
So, I'm using subprocess's Popen to run everything but the issue occurs even if I directly run everything in CMD so the problem isn't in the way the subprocess call works. SO, for easier understanding, I'll be referring directly to the CMD method. Step-by-step what I'm doing:
- I give a path to Blender's executable
- I give a path to a specific Blender scene to be opened
- I specify that I want Blender to run in background mode and to execute a Python script
- I give a path to the custom script (You can see it below)
- I give a path to a custom variable named "passed_object" that comes from the main automation script
The Custom script that I'm using is something like this:
import sys
def render(passed_object):
# Doing Blender operations
bpy.context.scene.custom_script.object_path = passed_object # I'm giving the passed_object variable to a Custom script in Blender
if __name__ == "__main__":
args = sys.argv
passed_object = args[-1]
render(passed_object)
[THE PROBLEM]
So, running things as is in the CMD (or in the main automation script using subprocess) I get things done and the result is what I expect. The problem is that after everything's done, in the end I get an error saying that Blender can't open the file that's in the "passed_object" variable.
[MY THOUGHTS]
I think that CMD/subprocess is giving the passed_object variable to the Custom script as expected, but it also gives it directly to Blender when running it because I'm giving it directly when executing Blender. So, maybe there's a better way to do this and to pass the "passed_object" variable directly to the Custom script without also passing it to the Blender execution?
python
subprocess
blender
execution
0 Answers
Your Answer