This document outlines the plan for creating a simple client-server application. The client is a Blender addon, and the server is a Flask application. The goal is to send the name of the currently selected active object from Blender to the Flask server, which then echoes this name back to Blender.
Note: SSH authentication has been set up for this repository.
Create a minimal setup to demonstrate:
- Data extraction from Blender.
- Sending data from a Blender addon (client) to a web server.
- A simple Flask server (backend) receiving data and sending a response.
- The Blender addon receiving the server's response and displaying it.
This project is designed for users new to Flask and client-server networking.
- Framework: Flask
- Functionality:
- A single API endpoint:
/api/echo_name(accepts POST requests). - Expects a JSON payload:
{"object_name": "YOUR_OBJECT_NAME"}. - Extracts the
object_namevalue. - Returns a JSON response:
{"message": "Server received: YOUR_OBJECT_NAME"}. - Listens on all available IP addresses (
0.0.0.0) and port5000.
- A single API endpoint:
- Instructions for Running (Backend - Vast.ai or similar):
- SSH into your server instance.
- Save the Flask server code as
server.py. - Install Flask:
pip install Flask(include this in comments inserver.py). - Run the server:
python server.py(include this in comments inserver.py). - The server will indicate it's running (e.g.,
* Running on http://0.0.0.0:5000/). - Note the public IP address of your server instance and the port it's running on (e.g.,
5000). Ensure this port is accessible externally. If your hosting provider (like Vast.ai) maps an external port (e.g.,XXXXX) to your container's internal port5000, you will useYOUR_SERVER_PUBLIC_IP:XXXXXwhen configuring the client.
- Functionality:
- A simple Blender panel in the 3D View's "N" panel, titled "Server Test".
- A button labeled "Send Object Name".
- Button Click Action:
- Gets the name of
bpy.context.active_object.name. - If no object is selected, prints "No active object selected." to the Blender system console.
- If an object is active, constructs JSON:
{"object_name": "THE_ACTIVE_OBJECT_NAME"}. - Sends this JSON via POST to the server. The server URL (
http://YOUR_SERVER_IP:PORT/api/echo_name) is constructed dynamically using the IP address and port configured in the addon's UI panel.- Default IP is
127.0.0.1and default port is5000.
- Default IP is
- Uses the
urllib.requestlibrary (built-in). - Prints the server's full response (or specific message field) to the Blender system console.
- Includes basic
try-exceptfor network errors (e.g.,requests.exceptions.ConnectionError).
- Gets the name of
- Structure:
bl_infodictionary.- Operator class for the button.
- Panel class for the UI.
register()andunregister()functions.
- Instructions for Use (Client - Your Local Blender):
- Save the Blender addon code as
blender_addon.py. - Open Blender:
Edit > Preferences > Add-ons > Install...and selectblender_addon.py. Enable it. - In Blender's 3D View, add an object (e.g., a Cube) and ensure it's selected.
- Press "N" to open the side panel. Find the "Server Test" panel.
- In the "Server Test" panel, configure the "IP Address" and "Port" fields to match your running Flask server. (Defaults are 127.0.0.1 and 5000 for local testing).
- Click "Send Object Name".
- Open Blender's system console (
Window > Toggle System Console) to view the server's response.
- Save the Blender addon code as
sequenceDiagram
participant User
participant BlenderAddon (Client)
participant FlaskServer (Backend)
User->>BlenderAddon (Client): Clicks "Send Object Name" button in UI
BlenderAddon (Client)->>BlenderAddon (Client): Gets bpy.context.active_object.name
alt No active object
BlenderAddon (Client)->>BlenderAddon (Client): Prints "No active object selected." to Blender console
else Active object exists
BlenderAddon (Client)->>BlenderAddon (Client): Constructs JSON payload: {"object_name": "ObjectName"}
BlenderAddon (Client)->>FlaskServer (Backend): POST http://YOUR_SERVER_IP:PORT/api/echo_name with JSON
FlaskServer (Backend)->>FlaskServer (Backend): Receives request, extracts "object_name"
FlaskServer (Backend)->>FlaskServer (Backend): Constructs JSON response: {"message": "Server received: ObjectName"}
FlaskServer (Backend)-->>BlenderAddon (Client): Sends JSON response
BlenderAddon (Client)->>BlenderAddon (Client): Receives response
BlenderAddon (Client)->>BlenderAddon (Client): Prints server response to Blender console
end
- Python 3.
- Complete, runnable code for
server.pyandblender_addon.py. - Clear comments, especially for networking parts.
- Minimal and simple code to achieve the described functionality.
This setup will demonstrate the fundamental flow: Blender UI -> Data Extraction -> Network Send (Client) -> Network Receive (Server) -> Processing (Server) -> Network Send (Server) -> Network Receive (Client) -> Display Result.