r/blenderpython • • Mar 25 '17

Real time shape key based animation in python

3 Upvotes

Hey Guys , I want to do a real time shape key based animation based on real time data from some source. I figured out how to get the real time data but cant figure out on how to animate the meshes using shape keys in python. any links to tutorials would be helpful.


r/blenderpython • • May 06 '15

Blender Python Workflow?

3 Upvotes

So I've been researching how one writes blender scripts. I see that one can use Eclipse and Pydev and Blender together but what's the work flow?

What does a project setup look like?

I'm a seasoned developer with lots of Eclipse experience. I've been teaching myself Blender for the fun of it... I thought i would lend a hand in developing scripts... but the workflow seems a bit awkard.

Is Eclipse the best solution? Is there an IDE that works more effectively?


r/blenderpython • • Oct 09 '14

Blender Game Engine player movement in Python

Thumbnail
snippets-samples-examples.com
3 Upvotes

r/blenderpython • • Sep 02 '14

function plotter in blender

3 Upvotes

Hey, I made two scripts that plot functions. The 2D script plots a function of the form f(x) while the 3D script plots a function of the form (x,y).

2D-Plotter

import bpy
import math
scn = bpy.data.scenes[0]
mesh = bpy.data.meshes.new("me")
ob = bpy.data.objects.new("func",mesh)

start = -1
stop = 1
step = 0.1

#Put your function here:
def function(x):
    y=2
    return y

k=start
verts=[]
edges=[]

for i in range(0,math.floor((stop-start)/step)+1):
    verts.append((k,function(k),0))
    if i < math.floor((stop-start)/step):
        edges.append((i,i+1))
    k=round(k+step,5)

mesh.from_pydata(verts,edges,[])
scn.objects.link(ob)

3D-plotter

import bpy
import math
scn = bpy.data.scenes[0]
mesh = bpy.data.meshes.new("me")
ob = bpy.data.objects.new("func",mesh)

x_a = -1 #Start of x interval
x_b = 1 #End of x interval
y_a = -1 #Start of x interval
y_b = 1 #End of x interval
step = 0.1 #Stepsize

#Put your function in here:
def function(x,y):
    z = 2
    return z


verts=[]
faces=[]
x = x_a
y = y_a
for j in range(0,math.floor((y_b-y_a)/step)):
    for k in range(0,math.floor((x_b-x_a)/step)):
        verts.append((x,y,function(x,y)))
        x = round(x+step,5)
    x = x_a
    y = round(y+step,5)

DIM = math.floor((y_b-y_a)/step)
for j in range(0,DIM-1):
    for k in range(0,DIM-1):
        faces.append((k+j*DIM,(k+1)+j*DIM,(k+1)+(j+1)*DIM,k+(j+1)*DIM))
    
mesh.from_pydata(verts,[],faces)
scn.objects.link(ob)

Example plots

sin(x)*cos(y)

sinc(r), r=x^2+y^2

x2 + y^2


Tell me what you think of it :) Improvements that can be made?


r/blenderpython • • May 20 '14

Script that finds non-planar polygons, selects them and outputs total amount found.

3 Upvotes

This script checks if you object has any non-planar faces. If it does then it will select those faces so you can see which ones in edit mode. It will also output how many faces that were non-planar in the system console.


import bpy

def Vnorm(Vec):
    return (Vec[0]**2+Vec[1]**2+Vec[2]**2)**0.5

def Vdot(Vec1,Vec2):
    return Vec1[0]*Vec2[0]+Vec1[1]*Vec2[1]+Vec1[2]*Vec2[2]

scene = bpy.context.scene
ob = bpy.context.active_object
eps = 1e-3
pface = 0
planar = False

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')

if ob.type != 'MESH':
    print("Please Select a mesh object")
else:
    for face in ob.data.polygons:
        fnorm = face.normal
        for edgekey in face.edge_keys:
            tempvec = ob.data.vertices[edgekey[0]].co-ob.data.vertices[edgekey[1]].co
            if abs(Vdot(tempvec,fnorm)) < eps:
                planar = True
            else:
                planar = False
                break
        if planar==False:
            pface +=1
            face.select = True
   
    print(pface)

Any critiques or suggestion on how to write it better are more than welcome! It would be great if you guys could test out the script and report if there are any bugs or if it gives incorrect values. I've tested it here and it seems to work for me, but more tests are always a good thing.


r/blenderpython • • May 19 '14

I've got another tutorial for you guys! This one explains how to use python in order to align a sky texture in cycles with a sun lamp.

Thumbnail
youtube.com
3 Upvotes

r/blenderpython • • May 02 '14

[Meta] Useful links and info

3 Upvotes

I think we should include some helpful links and info in the sidebar(or not), how to get started and such. Here are the links I recommend

Webpages:
Blender API Python reference
The Hitchhiker’s Guide to Python!
Helpful game engine tutorials
GLSL realtime raytracer (OpengGL shading language)
Interfacing with external electronics using UART with python in blender
Python libraries

Subreddits:
/r/learnpython
/r/blender
/r/BlenderGameEngine
/r/coding
/r/gamedev
/r/opengl

Tools:
https://addons.mozilla.org/en-US/firefox/addon/chatzilla/

IRC Channels:
#blenderpython
#blendercoders

Books:
A Primer on Scientific Programming with Python, by Hans Petter Langtangen
OpenGL Programming Guide: The Official Guide to Learning OpenGL, by Dave Shreiner et al.
OpenGL Shading Language, by Randi J. Rost et al.


I guess OpenGL doesn't belong here, but I wanted to include it anyway cause its lets you do really cool stuff and more people should learn to use it in blender. There probably lots more out there that I am not aware of, so bring on suggestions I can add to the list. Some of this stuff can be added to the sidebar for easy access.

EDIT: I changed the title of the post right before I submitted and I'm not sure if [Meta] is applicable anymore. If its not then if a mod can change it then thats fine.


r/blenderpython • • Sep 09 '26

Please have a look at my Blender add-on: Oh Snap! Dynamic Snap to Mesh tool

Thumbnail gallery
2 Upvotes

r/blenderpython • • Jul 21 '26

What if Blender got a New Auto-Rigger?

Post image
2 Upvotes

Well it HAS!

Say hello to the Hero Rig! (which is FREE!! Foundation First MasterWorks on Gumroad)

A.K.A. the last Rig you'll ever use, or ever want to!

Are you tired of Bone Heat Warning?

Tired of spending Hours/Days Weight Painting?

Tired of Mesh Collapsing and CandyWrapping?

Tired of Limb Flipping?

Tired of Counter Animating?

Then YOU are the Intended Audience for the Hero

Rig because Those are the problems it intends to solve!

This Product will be undergoing Continuous Ongoing Development,

maintained by us (us referring to just me right now)

and has been tested extensively, or as extensively as I can alone,

and Perfection is Not guaranteed, but if it operates even

remotely similar for you as it does for me, then I know you'll

find many reasons to find it Helpful!

This is the First Iteration of the Beta Version. Built into the UI

is a Community HUB with links to Support, Documentation,

and Bug Report/Feature Suggest options to inform me

of any issues that may arise, and a "Co-Conspirators" tab to

keep track of everyone who Suggest features, Reports Bugs,

or Supports Development in any way,

with an Identical List on the official FFMW Discord Server!

I sincerely hope you try and Enjoy the Hero Rig,

and even if it's not the best today,

let me know how to Improve it

and we can make it the Best Together!

------------------------------------------------------------
Also, since this version of the Post is for r/BlenderPython,

what might interest you to know is that its

Open Glass-Box UI Script is 60,000 lines long!

You're completely free to do with it as you please!

Just please Consider Supporting Spread the Word

so we can get some Beta Testing al up in here

to give me more work to do,

as if 12+hrs/day wasn't enough already lol

Anyway, I hope you check it out, and Good luck out there!


r/blenderpython • • Jun 07 '26

The Breakthrough

2 Upvotes

When your python script fails so badly it actully looks cool lol. Tried to make flying cubes but got these weird planes instead due to a glitch. Decided to just roll with it and used random.uniform to drive the main cubes rotation and color based on the glitch itself. Took a whole month to figure out the math in blender 2.79 but we finally got a breakthrough! anyone else still coding in the dark ages of 2.7x? 💀


r/blenderpython • • Mar 16 '26

Mesh Fix Addon What do you think of this add-on?

2 Upvotes

Fix common mesh problems before you export your models


r/blenderpython • • Feb 18 '26

Mesh Writer : Animation, illustrations , annotations and more (UPDATE VIDEO)

2 Upvotes

Hello everyone,

I just made a new updated demo video for my addon Mesh Writer. I would love to hear your feedbacks and impressions about this demo video.

P.S. Mesh Writer is Vector animation, Vector art illustration and note annotations making tool for Blender.

Get on SuperHive (Blender Market) : Mesh Writer on SuperHive

Cheers.


r/blenderpython • • May 01 '25

How to read coordinates from a curve?

2 Upvotes

I want to use a curve object [spiral] to read from it, what are the x,y values for given z.

I can find object, but what operation do I need to use to read the mentioned values? Which properties do I need?

I can code but I wouldn't call myself developer. I was trying to comprehend API docs starting yesterday. I can add my object, call it with data, or other methods, but I am lost in understanding of the the structure of the object. Although if I understand correctly, the key to understanding is RNA? But it is confusing, because I only know this concept from biology. Is this an analogy of function in code, blender specific, or some programming concept?


r/blenderpython • • Apr 09 '25

bpy.types.NodeSocket label property as a Node Group socket's "visible name"?

2 Upvotes

I'm exploring the possibility of my shader node groups' sockets having programmer-friendly (if user-hostile) names while showing verbose, user-friendly ones in the GUI, using standard node group socket properties and no custom layouts.

I see that there is a NodeSocket label property (not to be confused with the bl_label one) which suggests a similarity with node groups' name vs. label properties. As of Blender 4.4, it is read-only on node groups created through Blender's GUI, and defaults to an empty string.

What is the purpose of this property? Could it work as an alternate, "visible name" for a socket? And is there any stage in the creation of a node group via Python in which one could assign it an arbitrary string?


r/blenderpython • • Mar 05 '25

Blender python depth map

2 Upvotes

Hello Everyone, I’ve been trying to create depth map from the python API but I have not been getting a lot of success. I try save it in EXR file but the Z channel keeps on getting saved as the V channel. Has anyone ever gotten theirs to work


r/blenderpython • • Feb 19 '25

How to add a button to operator's UI, that will call a method from within that operator (or change its property)?

2 Upvotes

So I have a addon with a master operator, that has some properties and an UI (a draw method). How do I add a button to that draw method, that will (upon click) call a method from within my master operator? What I need is to change a propery on button click -- I dont want the slider. that I get by adding standard layout.box().prop(). I have found examples on how to add a button (by defining a new operator), but how do I make that button to have a reference to my master operator and call its method (modify its property)? Thanks!


r/blenderpython • • Nov 17 '24

Help. Import/Append collections, objects and modifiers from another .blend file

2 Upvotes

Hey, im a newbie in using python, does anyone know where i can find information about how to import data from another .blend file, e.g. if i want a button that generates an object+modifier that already exists in another .blend file? Thanks in advance.


r/blenderpython • • Aug 17 '24

Edit Bones in Pose Mode without having to enter Pose Mode

2 Upvotes

Hello. I am working on a script that includes rotating and moving bones in Pose Mode. I would like to see these rotations in real time (i change the rotation on each frame) but having to always change from object to pose mode is slowing everything down.
I would also like to edit multiple different armatures per frame and my current script doesn't seem very scalable.
Is there a way to edit the rotation of the bones in Pose Mode without entering pose mode. Thanks


r/blenderpython • • Jun 29 '24

Loader/progress

2 Upvotes

I have a bpy script that can take some time to execute. It basically freezes Blender. Is there any way to show a loader or something while my bpy script is executing?


r/blenderpython • • May 18 '24

Scaling a new imported collection for LEGO!

2 Upvotes

I've managed to fix up and fine tune the old Lego LXF to Blender importer that's based on pyldd2obj version 0.4.8 - Copyright (c) 2019 by jonnysp.

The only Python and BPY API I know is that which I've learned doing this plugin tweaks, so not much at all.

During import I realised the object's where huge! The whole scale is some other unit, possibly mm to meters!

I had great difficulty resizing individual blocks as they were put in the scene - all the time I got "brick.scale isn't a method" or similar! I don't know what the constructors are making, so I was experimenting blind.

In the end, the solution I got working was some code I found on S.O.... which works great but with one problem I can't solve - the bit of code below scales the WHOLE scene!

So prior imports are shrunk repeatedly, like Russian Dolls!

Line 1421:

    # Scale the world
    scale = 0.025
    # change scale and location
    [setattr(obj, 'scale', obj.scale*scale) for obj in bpy.data.objects if ((obj.type != 'EMPTY') and (obj.type != 'CAMERA'))]
    [setattr(obj, 'location', obj.location*scale) for obj in bpy.data.objects if obj.type != 'CAMERA']

The layout of the new blocks is like below, a new collection contains empty elements that each have some brick bits and the lego mesh as children.

So what I figured was a correct course of action was to iterate through the -collection- that was just imported, not the whole scene like I am.

How can I do that?

https://github.com/Sarah-C/BlenderImportLDD/blob/main/BlenderImportLDD.py


r/blenderpython • • May 14 '24

Complete noob in need of help to do simple college assignment.

2 Upvotes

It's pretty simple stuff, but I have 0 understanding of Python so it's been hard to find things on how to do exactly what I want. The general idea is getting a few tools that I use often during rigging process inside a single add-on/panel, so I don't have to go back and forth between a bunch of tabs. Right now I'm trying to figure out how to add Icons to my panel labels instead of the row labels, and how to recreate the bone name and parent text boxes like they are in the relations tab. I've tried a few things but the general result is that nothing happens.

Edit: added some pictures of how the code is, as I said very basic stuff, I'm completely new to this, and sorry for the Portuguese comments.


r/blenderpython • • May 03 '24

Python Help! Alembic to FBX

2 Upvotes

Hi all. I'm looking into all methods (if at all possible) to convert alembic cache data into fbx format. I realize that the changing vertex count doesn't allow for conversion and imported alembics are baked animation data, but my thought process here is to convert between multiple formats.

I first made a simple geom node particle system and exported that out as a alembic, then brought that back into blender to convert to a lightwave point cache format. I did this because I thought perhaps then taking this data to fbx could provide a solution but i haven't found a working method yet. I get an export that is just the first frame of the animation.

My methodology to this point has been to somehow convert the data into shape keys to then export out. I found this script online, but it seems to crash my scene. Honestly, if someone were able to break this down into simpler terms, I may be able to edit this to my needs.

If anyone has insight or creative solutions to get this result of an alembic to an fbx format, it would be greatly appreciated. my target goal is to take a growing fluid sim and get that to an fbx.

PYTHON SCRIPT:

import bpy

ob = bpy.context
obAc = ob.active_object
mesh_data = obAc.data

start_frame = bpy.context.scene.frame_start
end_frame = bpy.context.scene.frame_end

if not obAc.data.shape_keys:
obAc.shape_key_add(name="Basis")

Create shape keys for each frame

for frame in range(start_frame, end_frame + 1):
bpy.context.scene.frame_set(frame)

Evaluate the mesh with modifiers

depsgraph = bpy.context.evaluated_depsgraph_get()
object_eval = obAc.evaluated_get(depsgraph)
mesh_eval = object_eval.data

Create a new shape key and set its points based on the current frame

shape_key = obAc.shape_key_add(name=str(frame))

Collect vertex positions for the current frame

vertices = [vertex.co for vertex in mesh_eval.vertices]

Set shape key data

shape_key.data.foreach_set('co', [c for v in vertices for c in v])

if obAc.data.shape_keys:
shape_keys = obAc.data.shape_keys.key_blocks

Iterate through shape keys and set keyframes

for frame in range(start_frame, end_frame + 1):
ob.scene.frame_set(frame)

for shape_key in shape_keys:
if shape_key.name.isdigit():
value = 1.0 if int(shape_key.name) == frame else 0.0
shape_key.value = value
shape_key.keyframe_insert(data_path='value', index=-1)


r/blenderpython • • Apr 28 '24

I made a universal(?) Multi-File Add-On self-bootstrapping __init.py__

2 Upvotes

I spent way too much time on making this __init,py__ file for use in add-on development... instead of actually working on the add-on I want to make

It scans it's directory for all sub-modules (.py files) and imports and/or reloads them. It is a very, very greedy approach and it's likely to load / reload the same file multiple times (because it got imported in an already loaded file)

Also the script that you run inside of Blender to load in the add-on is different than what I've seen around (included in the code as a text block).

Do whatever you want with this code, I donate it to the public domain as much as I can and whatnot.

bl_info = {
    # your add-on info here
}

"""
### Dev Loader Script ###
# Run from Blender's Text Editor

import sys
import importlib
import importlib.util

# https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly

module_name = "module_name"
file_path = "C:/blah/module_name/__init__.py"

if module_name in sys.modules:
    try:
        sys.modules[module_name].unregister()
    except Exception as err:
        print(err)

spec = importlib.util.spec_from_file_location(module_name, file_path)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)

module.register()
"""

# bootstrapping code based on: https://b3d.interplanety.org/en/creating-multifile-add-on-for-blender/
import importlib
import sys
from glob import glob

child_modules = {mod_name: f'{__name__}.{mod_name}' for mod_name in (
    p.replace('\\', '.').replace('/', '.').removesuffix('.py')
    for p in glob("**/[!_]*.py", root_dir=__path__[0], recursive=True)
)}

for mod_name, full_name in child_modules.items():
    if full_name in sys.modules:
        print('Reload', full_name)
        importlib.reload(sys.modules[full_name])
    else:
        print('Initial load', full_name)
        parent, name = mod_name.rsplit('.', 1)
        exec(f'from .{parent} import {name}')

del mod_name, full_name

def register():
    for full_name in child_modules.values():
        if full_name in sys.modules and hasattr(sys.modules[full_name], 'register'):
            sys.modules[full_name].register()


def unregister():
    for full_name in child_modules.values():
        if full_name in sys.modules and hasattr(sys.modules[full_name], 'unregister'):
            sys.modules[full_name].unregister()

r/blenderpython • • Nov 26 '23

Use a scipt to control an object by acceleration or velocity in real time

2 Upvotes

Hi, I'm trying to use Blender to simulate a vehicle to test the autonomous navigation I'm working on. To be able to do this you would need to be able to give, preferably, an acceleration setpoint to the vehicle, or a speed setpoint, to be able to move the vehicle through the simulation in real time. Do you know if there is any way to do it? or any addon that makes it easier?