Local AI For Blender 5.0 Python API

LLM TO BPY GUIDE
LLM TO BPY GUIDE

Live stream set for 2025-12-22 at 14:00:00 Eastern

Ask questions in the live chat about any programming or lifestyle topic.

This livestream will be on YouTube or you can watch below.


Simple Way to Connect AI to Blender Using Ollama Python API

Connecting local AI to Blender allows you to generate 3D scenes using natural language. This workflow uses the power of Python to bridge the gap between a Large Language Model and the Blender 3D environment. This process is entirely powered by open source software which gives you full control over your creative pipeline.

The Open Source Stack

All tools mentioned in this guide are free to use and distribute under their respective licenses:

  • Blender: The professional 3D suite licensed under the GNU GPL v2.
  • Ollama: The local model runner licensed under the MIT License.
  • Qwen2.5-Coder: A specialized LLM for programming licensed under the Apache 2.0 License.

Setup Instructions

First you must install the Ollama library into the Python environment used by Blender. Open a terminal in the Blender installation folder under the python bin directory and run the following command.

./python -m pip install ollama

Next ensure you have the Qwen model running by typing ollama pull qwen2.5-coder in your terminal. This model is optimized for technical tasks and code generation.

The Python Script

Open the scripting tab in Blender and create a new script. Use the code below to send a request to the local API endpoint.

import bpy
import ollama

def ask_ai_to_model(prompt):
    system_msg = "You are a Blender Python expert. Output ONLY the python code to complete the task. No explanation."
    
    response = ollama.chat(model='qwen2.5-coder', messages=[
        {'role': 'system', 'content': system_msg},
        {'role': 'user', 'content': prompt},
    ])
    
    code = response['message']['content']
    clean_code = code.replace("```python", "").replace("```", "").strip()
    
    try:
        exec(clean_code)
        print("AI Code Executed Successfully")
    except Exception as e:
        print(f"Error: {e}")

ask_ai_to_model("Create a 10x10 grid of cubes with random heights")

API Endpoints

Ollama creates a local server on your machine that communicates via HTTP requests. Blender uses its internal Python console to send instructions to the following API endpoints:

  • Main URL: http://localhost:11434
  • Chat Endpoint: /api/chat

📸 Screenshots & Screencast

Ollama Server
Command Line Showing Ollama Server Running

Ollama Module Python code
Blender Scripting Workspace Displaying Ollama Module Python Code

Ollama API Python code
Blender Scripting Workspace Displaying Ollama API Python Code

AI Generated Results in Blender Layout
Blender Layout Workspace Displaying AI Generated Objects

Screencast For Blender Python API AI Generated Objects

Resources for Learning Python and Blender

To master these techniques you can explore detailed educational materials that cover both basic and advanced concepts:

One on One Tutorials

Personalized instruction is available if you require help with Python or the Blender API. You can book one on one online Python tutorials to accelerate your learning process. Visit the contact page to schedule a session.

Recommended Resources:

Disclosure: Some of the links above are referral (affiliate) links. I may earn a commission if you purchase through them - at no extra cost to you.

About Edward

Edward is a software engineer, web developer, and author dedicated to helping people achieve their personal and professional goals through actionable advice and real-world tools.

As the author of impactful books including Learning JavaScript, Learning Python, Learning PHP, Mastering Blender Python API, and fiction The Algorithmic Serpent, Edward writes with a focus on personal growth, entrepreneurship, and practical success strategies. His work is designed to guide, motivate, and empower.

In addition to writing, Edward offers professional "full-stack development," "database design," "1-on-1 tutoring," "consulting sessions,", tailored to help you take the next step. Whether you are launching a business, developing a brand, or leveling up your mindset, Edward will be there to support you.

Edward also offers online courses designed to deepen your learning and accelerate your progress. Explore the programming on languages like JavaScript, Python and PHP to find the perfect fit for your journey.

📚 Explore His Books – Visit the Book Shop to grab your copies today.
💼 Need Support? – Learn more about Services and the ways to benefit from his expertise.
🎓 Ready to Learn? – Check out his Online Courses to turn your ideas into results.

Leave a Reply

Your email address will not be published. Required fields are marked *