Home

Awesome

Blender-ZMQ-add-on (BlendZMQ)

Blender 2.8x - 3.6 add-on that allows streaming of data (from another computer) into Blender over ZeroMQ sockets, without freezing the interface (publisher-subscriber pattern).

Update

Overview

Blender is very powerful software, but if you run your own code that's a bit heavy, you quickly make the interface unresponsive. I.e freezing the interface. This could be solved with Threading/Async, however, this is difficult due Blender's internal loop (which is more like a game engine). Also, in case of threading, you can't manipulate objects in the main loop of Blender without using e.g. a queue system.

Why not take the program logic and manipulation of data outside Blender, and possibly run heavy code on another PC? Enter ZeroMQ.

ZeroMQ (pyzmq - Python wrapper of ZMQ) is a communication protocol library that allows the sending of data packages between programs (even when written in different languages) by using sockets. Therefore, the data can be send over the network (e.g. TCP), meaning you can even run the software on different machines.

This add-on works by setting a timer function (Blender 2.80+) that checks if a ZeroMQ socket has received a message from outside (using zmq.Poller()). If so, process that data to move selected objects. This timer keeps being invoked until the socket has been disconnected. See for a demonstration:

BlendZMQ demo]

You can take this add-on as an example on how to connect your own programs with Blender.

Prerequisite

How to use

  1. Download this repository as a .zip by:
  2. Start Blender with Administrator right (at least on Windows) to allow enabling of pip and installing pyzmq (does NOT work with a Snap package install of Blender on Linux, see troubleshooting)
  3. In Blender, add this add-on by selecting Edit -> Preferences -> Add-ons ->
    1. Install... -> select downloaded ZIP from step 1 -> Install Add-on
    2. Search: blendzmq -> click checkbox to activate
  4. Open side panel in 3D view by
    • Pressing n on your keyboard
    • Dragging < to the left
  5. Click "bZMQ" -> "Enable pip & install pyzmq" button
  6. Click "Connect socket" button. Now it's waiting for data message from outside.
  7. Start outside script to send data into blender (Get the script by downloading from the GitHub repo / unzip previously downloaded ZIP):
    1. Get script by:
      • Unziping the .zip downloaded in step 1
      • In terminal: git clone https://github.com/NumesSanguis/Blender-ZMQ-add-on
    2. Open a terminal and navigate to cd *path*/Blender-ZMQ-add-on/utils
    3. Make sure conda / virtual env is active (e.g. conda activate bzmq) with pyzmq
    4. Execute: python zmq_pub_number_gen.py (Change ip or port by adding --ip 192.168.x.x and/or --port 8080)
  8. See objects moving!
    • "Dynamic objects" can be selected to update location of current selected objects

    • "Dynamic objects" can be deselected to keep updating only the objects that were active at deselection time.

Troubleshooting

Notes

Acknowledgement