Last active
March 21, 2025 08:14
-
-
Save cdsousa/d820d27174238c0d48e5252355584172 to your computer and use it in GitHub Desktop.
Julia inside Python inside Blender
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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