3
$\begingroup$

I am experimenting with the Import CSV node in Blender. I have Blender open alongside a text editor where I edit my CSV file, and I would like an easy way for the new data to update automatically in Blender. How can I refresh or reload the Import CSV node data whenever the CSV file changes? At the moment, I have to reselect the file in the file browser each time I make an edit. Ideally, the data would update automatically every time I save the CSV file.

$\endgroup$
1
  • $\begingroup$ There’s a pull request for automatic CSV refresh, but it hasn’t been approved or merged yet. In the meantime, you can use the workarounds I outlined in my answers. $\endgroup$ Commented Nov 23 at 13:08

2 Answers 2

5
$\begingroup$

As far as I know, the Import CSV node does not refresh automatically and evaluates the data only once when the file path is set. You can implement automatic updates using the socket-based method I described in my other answer, though it's a more involved approach.

If you prefer a simpler workaround, you can use a Python script to periodically update the node's file path, for example every 2 seconds, so the node re-evaluates the CSV data automatically. Simply copy the following script, paste it into the Text Editor, and click Run Script. Make sure to run it only once per Blender session.

import bpy

def find_csv_nodes():
    csv_nodes = []
    for node_tree in bpy.data.node_groups:
        for node in node_tree.nodes:
            if node.bl_idname == "GeometryNodeImportCSV":
                csv_nodes.append((node_tree, node))
    return csv_nodes

def update_csv_node_inputs(csv_nodes):
    for tree, node in csv_nodes:
        path = node.inputs[0].default_value
        node.inputs[0].default_value = path

def run_csv_update():
    nodes = find_csv_nodes()
    update_csv_node_inputs(nodes)
    return 2.0  # Set the number of seconds between each update

run_csv_update()  # manually update
bpy.app.timers.register(run_csv_update)  # automatically update every X seconds

You can either call run_csv_update() manually to update all Import CSV nodes immediately, or use a timer to call that function periodically with bpy.app.timers.register(run_csv_update). The script loops through all existing Import CSV nodes in your node groups and updates their input values automatically. If you use the timer, this process repeats at the interval specified by the return value in run_csv_update(). To change how often the update runs, simply modify the return value. For example, return 5.0 will run the update every 5 seconds instead of 2.

Be careful not to run the script multiple times, as each run will create additional timers and cause the function to execute repeatedly. To ensure any previous timers are stopped before starting a new one, you can follow the approach described in this thread. If you are not sure if you started a timer or how to use that approach, just close the Blender session and open it again then run the script again.

You can also register the script so that it runs automatically the next time you open Blender, eliminating the need to run it manually.

$\endgroup$
0
4
$\begingroup$

Auto-Refresh via UDP Socket (Advanced Method)

The Import CSV node evaluates the data only once when the file path is set. To automatically refresh it, you can either use this simple workaround with a periodic timer, or opt for a more advanced solution using UDP network sockets to enable inter-process communication for automatic CSV reloading in Blender. For a full introduction on sending data to Blender from an external application, see this guide on client-server communication with Blender.

The idea is to set up a background listener thread inside Blender that continuously waits for UDP messages. Whenever it receives a message, it triggers a Python function to refresh your Import CSV nodes.

For editing the CSV files, you can download and use Visual Studio Code (VSCode), which provides a convenient workflow through the Run on Save extension, which allows you to execute a custom Python script automatically every time you save a CSV file.

In our setup, this script sends a UDP message to Blender’s listener, effectively notifying Blender that the CSV has changed and prompting it to reload the data. That way you can create a fully automated CSV workflow, eliminating the need to manually refresh your node trees whenever you edit your data.

Setting Up the File Structure in Visual Studio Code

For testing, you can quickly set up the following file structure in the Explorer panel (Ctrl+Shift+E):

my_csv_project/
│
├─ .vscode/
│   └─ settings.json      # VSCode Run On Save config
│
├─ send_reload.py         # Python script to send UDP message to Blender
├─ test.csv               # Example CSV file you want to auto-reload

VS Code File Structure in Explorer Panel

Installing the "Run on Save" Extension

Next, open the Extensions panel (Ctrl+Shift+X), search for Run on Save, and click Install.

Extensions Panel

File Contents Setup

Then, create a folder named .vscode (folder name starts with period) which will contain the settings.json file. Next, open settings.json and fill it with the following content. Make sure the path to your Python executable is correct. In my setup, it is:

C:/Program Files/Blender Foundation/Blender 5.0/5.0/python/bin/python.exe

Adjust this path if your Blender installation is in a different location:

{
    "emeraldwalk.runonsave": {
        "commands": [
            {
                "match": "\\.(csv|txt)$",
                "cmd": "\"C:/Program Files/Blender Foundation/Blender 5.0/5.0/python/bin/python.exe\" send_reload.py",
                "isAsync": true
            }
        ]
    }
}

This settings.json file instructs VSCode to execute the command defined in the cmd parameter whenever a file matching the specified match pattern (in this case, .csv or .txt) is saved. The command runs the Python script send_reload.py, which opens a UDP socket (using an arbitrary port 5005 in this example) and sends a message to Blender’s listener, which we will setup later to trigger a CSV reload. Next, create send_reload.py with the following content:

import socket

UDP_PORT = 5005  # Make sure this matches the port your Blender listener is using
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto(b"reload", ("127.0.0.1", UDP_PORT))
print("Reload signal sent!")

Checking the "Run on Save" Output

Next, open the Terminal via View > Terminal and click Output panel, or press Ctrl+Shift+U to open it. Make sure the dropdown on the right is set to Run on Save so you can see the output of the commands triggered when saving files.

Terminal Output

Setting Up the Blender UDP Listener

Finally, in Blender’s Text Editor, paste the following script into the Text Editor and click Run Script. It starts a background listener on a UDP port. We use port 5005 in this example because it is generally free on most systems and matches the port used by send_reload.py.

Just make sure the port you choose is not already in use. Many ports are reserved or commonly used by other applications (see the list of port numbers).

import bpy
import socket
import threading
import time

UDP_PORT = 5005

def find_csv_nodes():
    csv_nodes = []
    for node_tree in bpy.data.node_groups:
        for node in node_tree.nodes:
            if node.bl_idname == "GeometryNodeImportCSV":
                csv_nodes.append((node_tree, node))
    return csv_nodes

def update_csv_node_inputs(csv_nodes):
    for tree, node in csv_nodes:
        path = node.inputs[0].default_value
        node.inputs[0].default_value = path

def run_csv_update():
    nodes = find_csv_nodes()
    update_csv_node_inputs(nodes)

def listen_udp():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind(("127.0.0.1", UDP_PORT))
    print(f"[Listener] Listening on UDP port {UDP_PORT}…")

    while True:
        try:
            data, addr = s.recvfrom(1024)
            run_csv_update()
        except Exception as e:
            print("UDP listener error:", e)

threading.Thread(target=listen_udp, daemon=True).start()  # Start the listener in a background thread

The script iterates over all Import CSV nodes in your node groups and, whenever send_reload.py sends a signal, automatically updates their input values to ensure the latest CSV data is loaded.

You can also register the script so that it runs automatically the next time you open Blender, eliminating the need to run it manually.

Demo: Editing the CSV and Seeing the Refresh

Now, whenever you edit your CSV file and press Ctrl+S to save, VSCode will automatically send a UDP signal to Blender. The listener inside Blender receives this signal and refreshes all Import CSV nodes instantly.

Demo

Restarting the Blender UDP Listener

This script creates a persistent socket listener inside Blender, which means you cannot run the script multiple times simultaneously on the same port. Normally, closing Blender will terminate the listener and free the port.

However, sometimes Blender may not shut down cleanly, leaving the socket process running even after the application is closed. In such cases, you must manually terminate the process that is holding the port before restarting the listener.

To find which process is using the port, open PowerShell (or any terminal appropriate for your OS) and run:

netstat -ano | findstr 5005

This command lists all network endpoints and filters for port 5005.
In the example below, the last column shows the PID (Process ID):

netstat

Once you have the PID (e.g., 26044), terminate it by running:

taskkill /PID 26044 /F

The /F flag forces the process to close, which also closes Blender:

taskkill

Additional Notes on Using Excel Viewer Extension

You can install the Excel Viewer extension to work with CSV files in a more user-friendly, spreadsheet-style interface.

Excel Viewer Extension for VSCode

After installing the extension, right-click the CSV file you want to edit and select Open With:

From the menu, choose CSV Editor:

Select CSV Editor dropdown

I found the Edit CSV extension works really well for editing CSV files. After installing it, simply open your CSV file, right-click it in the Explorer, and choose Edit CSV to start editing in a spreadsheet-like view.

Edit CSV Extension

$\endgroup$
2
  • 1
    $\begingroup$ Harry, thank you so much for your extensive answers! This one worked the first time I tried, and it helps me a lot with my workflow. $\endgroup$ Commented Nov 23 at 16:15
  • 1
    $\begingroup$ Hey @Alex, you are welcome! Glad this helped you out :) If you feel it completely solved your issue, consider marking it as accepted. $\endgroup$ Commented Nov 23 at 16:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.