No project description provided
Project description
Basilisp Blender Integration
Basilisp is a Python-based Lisp implementation that offers broad compatibility with Clojure. For more details, refer to the documentation.
Overview
basilisp-blender is a Python library designed to facilitate the execution of Basilisp Clojure code within Blender and manage an nREPL server for interactive programming from within your editor of choice.
This library provides functions to evaluate Basilisp code from Blender's Python console, file or Text Editor and to start an nREPL server, allowing seamless integration and communication with Basilisp.
Installation
For Blender >= 4.2.0, download the basilisp_blender_extension-<version>.zip extension file from the releases page.
Install in Blender by navigating to:
Edit > Preferences > Get Extensions > Install From Disk...
Then, enable it by ticking the checkbox under:
Edit > Preferences > Add-ons > ☐ Basilisp Blender Extension
Alternatively, you can also install and enable the extension (-e) via the command line:
$ blender --command extension install-file basilisp_blender_extension-<version>.zip -r user_default -e
After installation, the extension will appear as activated under the Get Extensions tab in Preferences.
For Blender versions < 4.2.0, refer to Manual Installation and Setup.
Usage
Basilisp Interface
Refer to the basilisp-blender API.md, and the Blender API for for details on interoperability with Python.
nREPL Server Control Panel
The library includes an nREPL server control panel accessible in Blender’s Properties editor, under the Output panel (icon resembling a printer). From here, users can:
- Start and stop the server.
- Configure the local interface address and port.
- Specify an optional
Basilisp Project Directory.
The Basilisp Project Directory is the location where your Basilisp code resides.
When the server starts, this directory is:
- Set as the current working directory for the duration of the nREPL session.
- Added to
sys.path, allowing Basilisp code files within it to be seamlessly require'd.
Additionaly, the following files will also be created in the directory for convenience if they do not already exist:
basilisp.edn: Marks the directory as a Basilisp Project for code editors.scratch.lpy: A Basilisp file for users to experiment with writing code..nrepl-port: The port number where the nREPL server is listening. This will overwrite any existing file.
A minimal Project Directory would include these files:
<project root directory>
├── .nrepl-port (N)
├── basilisp.edn (B)
├── yourcode.lpy (1)
🄝 Created by the nREPL server upon startup.
🄑 An empty file to indicate to Clojure-enabled editors that this is a Basilisp Project.
① Your Basilisp code.
Connecting through your Editor
[!NOTE] While it’s not necessary to open the project in your editor to connect to the nREPL server, doing so simplifies setup.
Open the basilisp.edn file to enable Clojure-specific features in your editor.
Both Emacs/CIDER and VSCode/Calva offer explicit support for Basilisp.
If you are using a different Editor, refer to its documentation for instructions on connecting to a running nREPL server.
CIDER (Emacs)
- Run
M-x cider-connect-clj - Select
localhost. - Select the
<project-dir>:<port number>option.
Calva (VSCode)
- Press
Ctrl-Alt-Pto open the Command Palette. - Select
Calva: Connect to a Running REPL Server, in your project>basilisp. - The editor will automatically find the port using
.nrepl-port.
The Editor should now connect seamlessly to the nREPL server.
Pythonic Interface
Evaluating Basilisp Code
From a Code String
from basilisp_blender.eval import eval_str
eval_str("(+ 1 2)")
# => 3
From a File
from basilisp_blender.eval import eval_file
eval_file("path/to/your/code.lpy")
From Blender’s Text Editor
To evaluate Basilisp code contained in a Blender text editor block:
from basilisp_blender.eval import eval_editor
# Replace `text_block` with your Blender text block name
eval_editor("<text-block-name>")
Starting an nREPL Server
To start an nREPL server manually within Blender:
from basilisp_blender.nrepl import server_start
shutdown_fn = server_start(host="127.0.0.1", port=8889)
The host and port arguments are optional.
If not provided, the server will bind to a random local port.
It will also creates an .nrepl-port file in the current working directory containing the port number it bound to.
The return value is a function that you can call without arguments to shut down the server.
For a more convenient setup, you can specify to output .nrepl-port file to your Basilisp's project's root directory.
This allows some Clojure editor extensions (such as CIDER or Calva) to automatically detect the port when connect'ing to the server:
from basilisp_blender.nrepl import server_start
shutdown_fn = server_start(nrepl_port_filepath="<project-root-path>/.nrepl-port")
Replace <project-root-path> with the path to your project's root directory.
Examples
Also see the examples directory.
Here is an example of Basilisp code to create a torus pattern using the bpy Blender Python library:
(ns torus-pattern
"Creates a torus pattern with randomly colored materials."
(:import bpy
math))
(defn clear-mesh-objects []
(.select-all bpy.ops/object ** :action "DESELECT")
(.select-by-type bpy.ops/object ** :type "MESH")
(.delete bpy.ops/object))
(clear-mesh-objects)
(defn create-random-material []
(let [mat (.new bpy.data/materials ** :name "RandomMaterial")
_ (set! (.-use-nodes mat) true)
bsdf (aget (.. mat -node-tree -nodes) "Principled BSDF")]
(set! (-> bsdf .-inputs (aget "Base Color") .-default-value)
[(rand) (rand) (rand) 1])
mat))
(defn create-torus [radius tube-radius location segments]
(.primitive-torus-add bpy.ops/mesh **
:major-radius radius
:minor-radius tube-radius
:location location
:major-segments segments
:minor-segments segments)
(let [material (create-random-material)]
(-> bpy.context/object .-data .-materials (.append material))))
#_(create-torus 5, 5, [0 0 0] 48)
(defn create-pattern [{:keys [layers-num radius tube-radius]
:or {layers-num 2
radius 2
tube-radius 0.2}}]
(let [angle-step (/ math/pi 4)]
(dotimes [i layers-num]
(let [layer-radius (* radius (inc i))
objects-num (* 12 (inc i))]
(dotimes [j objects-num]
(let [angle (* j angle-step)
x (* layer-radius (math/cos angle))
y (* layer-radius (math/sin angle))
z (* i 0.5)]
(create-torus (/ radius 2) tube-radius [x y z] 48)))))))
(create-pattern {:layers-num 5})
Manual Installation and Setup
The library and the nREPL control panel can be manually installed to support Blender versions earlier than 4.2.
To install the basilisp-blender library, use pip install from Python console within the Blender's Scripting workspace:
import pip
pip.main(['install', 'basilisp-blender'])
Adjust the command as needed for your environment. For instance, use -U to upgrade to the latest version or --user to install to your user directory. For additional options, refer to pip options.
Some Blender distribution use a "managed" Python environment, which restricts package installation to the standard directories. To identify a suitable intsallation path, inspect Blender's Python sys.path list:
>>> import sys
>>> sys.path
['/usr/share/blender/scripts/startup', '/usr/share/blender/scripts/modules', '/usr/lib/python312.zip',
'/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/usr/local/lib/python3.12/dist-packages',
'/usr/lib/python3/dist-packages', '/usr/share/blender/scripts/freestyle/modules',
'/usr/share/blender/scripts/addons/modules', '/home/ikappaki/.config/blender/4.0/scripts/addons/modules',
'/usr/share/blender/scripts/addons', '/home/ikappaki/.config/blender/4.0/scripts/addons']
The most suitable directory is likely scripts/addons/modules. In the example provided, this corresponds to ~/.config/blender/4.0/scripts/addons/modules.
Use this path as a --target directory when running pip install:
>>> import pip
>>> pip.main(['install', 'basilisp_blender', '--target', '/home/ikappaki/.config/blender/4.0/scripts/addons/modules'])
...
Successfully installed attrs-24.2.0 basilisp-0.2.4 basilisp_blender-0.3.0 immutables-0.21 prompt-toolkit-3.0.48 pyrsistent-0.20.0 typing-extensions-4.12.2 wcwidth-0.2.13
0
Troubleshooting
If you encounter unexplained errors, enable DEBUG logging and save the output to a file for inspection. For example:
import logging
from basilisp_blender import log_level_set
log_level_set(logging.DEBUG, filepath="bblender.log")
Blender scripting is not hread safe.
As a result, the nREPL server cannot be started into a background thread and still expect calling bpy functions to work without corrupting its state.
To work around this limitation, the nREPL server is started in a thread, but client requests are differed into a queue that will be executed later by a bpy custom timer function.
The function is run in the main Blender loop at regular intervals, avoiding parallel operations that could affect Blender's state.
If necessary, you can adjust this interval to better suit your needs by passing the interval_sec argument to the server_start function:
from basilisp_blender.nrepl import server_start
shutdown_fn = server_start(port=8889, interval_sec=0.05)
Development
This package uses the Poetry tool for managing development tasks.
Testing
You can run tests using the following command:
$ poetry run basilisp test
Integration testing
To run integration tests, set the $BB_BLENDER_TEST_HOME environment variable to the root directory of the Blender installation where the development package is installed. See Installing Blender and the Development Package on how to facilitate the installation.
$ export BB_BLENDER_TEST_HOME="~/blender420"
# or on MS-Windows
> $env:BB_BLENDER_TEST_HOME="c:\local\blender420"
Then run the integration tests with
$ poetry run basilisp test --integration -v
Generating the extension
Set the $BB_BLENDER_TEST_HOME environment variable to point to your Blender installation directory:
$ export BB_BLENDER_TEST_HOME="~/blender420"
# or on MS-Windows
> $env:BB_BLENDER_TEST_HOME="c:\local\blender420"
Run the script to generate the extension.
Include --and-install to install it:
$ poetry run basilisp run scripts/bb_extension_create.lpy --and-install
Installing Blender and the Development Package
To download and install Blender in the directory specified by $BB_BLENDER_TEST_HOME, use:
$ poetry run python scripts/blender_install.py 4.2.0
To install the development version of the package at the same location, use:
$ poetry build # build the package
$ poetry run python scripts/bb_package_install.py # install it in Blender
To enable the control panel, download the latest nrepl_panel_addon_<version>.py file from the releases and install viaEdit>Preferences>Add-ons>Install From Disk.
The add-on should appear in list--be sure to check its box to activate it.
License
This project is licensed under the Eclipse Public License 2.0. See the LICENSE file for details.
Extension License
The extension is licensed under the GNU General Public License v3.0.
See the LICENSE_EXTENSION file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file basilisp_blender-0.5.0.tar.gz.
File metadata
- Download URL: basilisp_blender-0.5.0.tar.gz
- Upload date:
- Size: 45.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
462a7681b16015eb661315431377cfce338f809a10a105b663d342c3caf45528
|
|
| MD5 |
5546b8702fce45bf65f3168aca0707c3
|
|
| BLAKE2b-256 |
ade8cb06f3d18e5f279c2e5d0ab9dd77e5ea52dffe7f7965ed839aee005aeee1
|
Provenance
The following attestation bundles were made for basilisp_blender-0.5.0.tar.gz:
Publisher:
release.yaml on ikappaki/basilisp-blender
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
basilisp_blender-0.5.0.tar.gz -
Subject digest:
462a7681b16015eb661315431377cfce338f809a10a105b663d342c3caf45528 - Sigstore transparency entry: 485240094
- Sigstore integration time:
-
Permalink:
ikappaki/basilisp-blender@96f0d3efa59dd1025d001655c1322aa7fb740864 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/ikappaki
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@96f0d3efa59dd1025d001655c1322aa7fb740864 -
Trigger Event:
release
-
Statement type:
File details
Details for the file basilisp_blender-0.5.0-py3-none-any.whl.
File metadata
- Download URL: basilisp_blender-0.5.0-py3-none-any.whl
- Upload date:
- Size: 44.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9784dfd7fb894192c3cf4026ad62a72b086c4338e264c884643cb63c9c69cf16
|
|
| MD5 |
05e4916a55a7193ad9e305c1df2a41ea
|
|
| BLAKE2b-256 |
506e5235dc5d743f3d52b470f495160c80996c4945b30a9872ed7f25d599d58f
|
Provenance
The following attestation bundles were made for basilisp_blender-0.5.0-py3-none-any.whl:
Publisher:
release.yaml on ikappaki/basilisp-blender
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
basilisp_blender-0.5.0-py3-none-any.whl -
Subject digest:
9784dfd7fb894192c3cf4026ad62a72b086c4338e264c884643cb63c9c69cf16 - Sigstore transparency entry: 485240123
- Sigstore integration time:
-
Permalink:
ikappaki/basilisp-blender@96f0d3efa59dd1025d001655c1322aa7fb740864 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/ikappaki
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@96f0d3efa59dd1025d001655c1322aa7fb740864 -
Trigger Event:
release
-
Statement type: