Skip to content

Instantly share code, notes, and snippets.

@cdsousa
Last active April 20, 2024 14:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdsousa/d820d27174238c0d48e5252355584172 to your computer and use it in GitHub Desktop.
Save cdsousa/d820d27174238c0d48e5252355584172 to your computer and use it in GitHub Desktop.
Julia inside Python inside Blender
bl_info = {
"name": "Julia console",
"blender": (4, 0, 0),
"category": "Scripting",
}
def register():
# install JuliaCall within Blender's Python environment (if not already installed)
import importlib
if importlib.util.find_spec('juliacall') is None:
import pip
pip.main(['install', 'juliacall'])
# set number of Julia threads to 1 (otherwise bpy usage will crash)
import os
os.environ["PYTHON_JULIACALL_THREADS"] = "1"
# load Julia with JuliaCall
import juliacall
# start Julia REPL in the terminal
juliacall.Main.seval('import REPL; import Pkg; Base.active_repl = REPL.LineEditREPL(REPL.Terminals.TTYTerminal(get(ENV,"TERM",""),stdin,stdout,stderr), true); Threads.@spawn :interactive REPL.run_repl(Base.active_repl, backend->(Base.active_repl_backend = backend));')
# load PythonCall and bpy Python module within Julia
juliacall.Main.seval('using PythonCall; bpy = pyimport("bpy")')
# schedule a Blender timer to allow Julia run
import bpy
def julia_work():
juliacall.Main.sleep(0.01)
return 0.01
julia_timer = bpy.app.timers.register(julia_work, persistent=True)
def unregister():
pass
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment