sourceextensions/blender/demos/hello.xtl
1⍝│ Blender, 1: X_eTaL runs Blender. The program writes two Python files
2⍝│ -- the launcher, which runs Blender in the background (with its
3⍝│ factory settings, so the run never depends on yours), and the script
4⍝│ Blender runs inside, which writes a report -- then runs the launcher
5⍝│ with python3 and reads the report back. The chain: X_eTaL, the
6⍝│ extension, python3, Blender, Python inside Blender.
7⍝│ Run: just demo blender hello
8
9"bl:" u̲se< "Blender"
10
11⍝│ the launcher: python3 run.py SCRIPT ARGS runs Blender in the
12⍝│ background on SCRIPT, passing ARGS after "--"; Blender's exit status
13⍝│ is its own (a Python error inside makes it 1)
14launcher ← "import os, subprocess, sys\nblender = os.environ.get(\"XETAL_BLENDER\") or sys.exit(\"no Blender found\")\nrun = [blender, \"--background\", \"--factory-startup\", \"--python-exit-code\", \"1\", \"--python\", sys.argv[1], \"--\"] + sys.argv[2:]\nsys.exit(subprocess.run(run).returncode)\n"
15
16⍝│ the script Blender runs: the objects of the scene it starts with,
17⍝│ written to the file named after "--"
18inside ← "import bpy, sys\nout = sys.argv[sys.argv.index(\"--\") + 1]\nnames = sorted(o.name for o in bpy.data.objects)\nopen(out, \"w\").write(\"objects: \" + \" \".join(names) + \"\\n\")\n"
19
20"Blender found:"
210 < t̲ally ᵇˡb̲lender @
22_ ← "work/hello/run.py" ᵇˡw̲rite! launcher
23_ ← "work/hello/hello.py" ᵇˡw̲rite! inside
24r ← "work/hello/run.py" ᵇˡr̲un! "work/hello/hello.py work/hello/report.txt"
25"the run, and the error lines in Blender's log:"
26lines ← (n̲ot r = f̲irst "\n") p̲artition r
27d̲isclose 1 s̲elect lines
28d̲isclose 2 s̲elect lines
29"what Blender wrote:"
30ᵇˡr̲ead "work/hello/report.txt"