'Is it possible to use an external python file to execute a blender python script inside Blender?
I am trying to figure how could I execute a python script that would ask Blender to execute a Blender Python script.
I found this forum where its users made a plugin/addon that enables a user to write code in an external program like sublimetext and it automatically updates the blender text editor and whenever they write "EXECUTE" in that text editor, they are able to execute the blender Python script inside Blender.
https://devtalk.blender.org/t/how-to-run-a-script-from-outside-blender-script-live-link-addon/9792/8
A user named “kaio” found a way to use notepad to write text on blender text editor in real time and shared his code. But I don’t have the knowledge to fully comprehend it.
Additional information:
Rhinoceros 3D is a geometric 3d modeler used by architects, designers and engineers for ex.
Blender is a free wonderful 3D program that is able to do a lot used by architects, designers and 3Dartists for ex.
SublimeText is a text editor used by programmers or engineers for ex
Notepad is a text editor used by programmers or engineers for ex
I want to connect two different programs through their API's. When I create a 3D object on Rhinoceros, I could push a button that would execute a Rhinoceros script that would trigger/ask Blender to execute a Blender Python script.
Solution 1:[1]
You can use the in built subprocess module of python to run blender as subprocess. Refer this - Control blender from python script outside of blender Use the below code in your python script to run blender as subprocess.
import subprocess
subprocess.run(['blender', '-b', '-P', 'path/to/your/script.py'])
If blender is executed in headless mode, then it executes the whole script. One must store the final output as blend file or export the final 3D object to see the output. There are different blender python commands for that. Don't specify '-b' flag to execute the script and open blender's GUI after executing python script.
import subprocess
subprocess.run(['blender', '-P', 'path/to/your/script.py']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Y_D |
