0

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Please avoid placing irrelevant information for the post such as your profession, etc. Here we focus on the question and we will answer it the same way whether you are an expert or a novice. Please read [ask] and review the [tour] – eyllanesc Mar 22 '22 at 23:46

1 Answers1

0

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']
YadneshD
  • 396
  • 2
  • 12