r/blenderpython • • Sep 05 '20

I did it! I made my first little add on. I’m working on a project with lots of forest particle systems and wanted something that could illustrate which particles would appear in the camera’s field of view to help avoid unnecessary particles. It’s not very optimized yet but it’s getting there!

19 Upvotes

r/blenderpython • • Jun 17 '21

After a bit of code, ~165 lines, I have a method that can draw trapezoids on acute angled points and have the trapezoid's edges touch at a tangent to the existing line, creating sharp corners on grease pencil lines.

Post image
17 Upvotes

r/blenderpython • • Oct 09 '24

Hi, I have made a Aircraft Generator in Blender

15 Upvotes

r/blenderpython • • Jun 28 '25

Blender Scripting Cookbook

Thumbnail
gallery
13 Upvotes

r/blenderpython • • Feb 25 '22

My new addon | Procedural Building Design and Construction

Thumbnail
youtu.be
12 Upvotes

r/blenderpython • • Apr 15 '26

Blender Python Cheatsheet v2.0 Released

Post image
11 Upvotes

r/blenderpython • • Jul 15 '21

This is how you add hooks to a lattice using python.

Post image
11 Upvotes

r/blenderpython • • Sep 29 '19

Made a tutorial about Blender Addon programing! With a preset addon.

Thumbnail
youtu.be
11 Upvotes

r/blenderpython • • Jun 15 '23

Hi, I have made a Aircraft Generator in Blender

10 Upvotes

r/blenderpython • • Nov 23 '19

Better UI in Blender 2.81 [Python;Free Addon] | English

Thumbnail
youtube.com
9 Upvotes

r/blenderpython • • Oct 11 '19

/r/blenderpython hit 1k subscribers yesterday

Thumbnail
redditmetrics.com
9 Upvotes

r/blenderpython • • Jun 15 '21

Can you help? I wrote a script to add sharp corners on grease pencil lines on the points that have angle smaller than a defined value. I need to know how to get the radius of that point, as of now, I can read the stroke.line_width and the point.pressure, but their product is way (x100+) too big.

Post image
8 Upvotes

r/blenderpython • • Mar 15 '23

Star Connect - Smart Mesh Triangulation Blender Addon (+FREE version)

Thumbnail
youtube.com
7 Upvotes

r/blenderpython • • Jun 05 '21

Hypercube/Tesseract script in blender 2.93

7 Upvotes

People have been asking for it so here it is.

The hypercube script that was originally written for blender 2.41, that I ported to 2.66 and now 2.93 (I'm not the original author). I have provided the script here and the pasteall link. Follow the instructions in the script or watch the vid at the end. Make sure that 'Developer Extras' is enabled in the preferences.

#!BPY
# SPACEHANDLER.VIEW3D.EVENT
"""
Name: 'Hypercube'
Blender: 241
Group: 'Add'
Tooltip: 'Creates a Hypercube and lets you rotate it.'
"""
 
#    Copyright (C) 2010 Wanja Chresta
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
__author__ = "Wanja Chresta"
__url__ = ["www.identi.ca/brachiel"]
__version__= '0.1'
__bpydoc__= '''\
This simple script creates a hypercube and binds keys so that you'll be able to rotate the Hypercube in the forth dimension.
'''
# the comment in line 1 tells blender to send us the events
 
        # Ported to Blender 2.66.0 r54697 with Python 3.3, by Meta_Riddley
        # Ported to Blender 2.93 by Meta_Riddley
        
        #------- How to use ----------
        # New blend file, delete default cube. Go to camera view.
        # New text document, paste code.
        # Run script.
        # In settings make sure that spacebar opens the search menu
        # In 3D-view, press space-bar and write hypercube and select hypercube in the list.
        # Now the hypercube can be rotated using the q,w,e,a,s and d keys.
        # Press ESC to exit without deleting the hypercube
        
#TODO: Completely rewrite the script to follow modern operator conventions and api
 
import bpy
import math
import mathutils
import bgl
import blf
#editmode = Window.EditMode()    # are we in edit mode?  If so ...
#if editmode:
#        Window.EditMode(0) # leave edit mode before getting the mesh
 
HYPERCUBE = None
HYPERCUBE_VERTS = []
 
GLOBAL_ANGLES = [0., 0., 0.]
 
 
def project(vec4):
        """projects [x,y,z,t] to Mathutils.Vector(x',y',z') in a fancy non-isometric way"""
        cx, cy, cz = [0., 0., 0.] # center
       
        x,y,z,t = vec4
               
        return mathutils.Vector([ x + (cx - x)*t/4., y + (cy - y)*t/4., z + (cz - z)*t/4.])
 
        # with this transformation we get a fancy image of our hypercube. If you want isometric, just
        # do this instead:
        # return Mathutils.Vector(vec4[0:3])
def rotate_hypercube(a=0, b=0, c=0):
        global GLOBAL_ANGLES
        rotate = mathutils.Matrix(((
                        (math.cos(a),0,0,-math.sin(a)),
                        (0,math.cos(b),0,-math.sin(b)),
                        (0,0,math.cos(c),-math.sin(c)),
                        (math.sin(a),math.sin(b),math.sin(c),math.cos(a)*math.cos(b)*math.cos(c)))))      
        # only used to display angles in gui
        GLOBAL_ANGLES[0] += a
        GLOBAL_ANGLES[1] += b
        GLOBAL_ANGLES[2] += c
        transform_hypercube(rotate)
       
      
       
def transform_hypercube(transformation):
        global HYPERCUBE, HYPERCUBE_VERTS
        transform_hypercube_from(HYPERCUBE, HYPERCUBE_VERTS, transformation)
        
def transform_hypercube_from(ob, hypercube_vert, transformation):
        for i in range(len(hypercube_vert)):
                #print(hypercube_vert[i])
                hypercube_vert[i] = transformation @ hypercube_vert[i]
               
        mesh = ob.data
        i = 0
        for v in mesh.vertices:
                v.co = project(hypercube_vert[i])
                i += 1 
       
def update_hypercube():
        global HYPERCUBE, HYPERCUBE_VERTS
       
        mesh = HYPERCUBE.data
        i = 0
        for v in mesh.vertices:
                v.co = project(HYPERCUBE_VERTS[i])
                i += 1 
               
 
def create_hypercube(name="hyperCube"):
        global HYPERCUBE_VERTS, HYPERCUBE
               
        HYPERCUBE, HYPERCUBE_VERTS = create_hypercube_(name)
 
       
def create_hypercube_(name="hyperCube"):
        # define vertices and faces for a pyramid
                       
        hypercube = [ [i, j, k, l] for i in [0,1] for j in [0,1] for k in [0,1] for l in [0,1] ]
        hypercube_verts = list(map(mathutils.Vector, hypercube))
       
        # TODO: find a better (and working) way to do this
        faces = []
        for k in [0,1]: # tries (and fails) to create the faces with normals pointing to the outside
                for l in [0,1]:
                        faces.append(list(map(hypercube.index, [ [i^j,j,k,l] for j in [k,k^1] for i in [l,l^1] ])))
                        faces.append(list(map(hypercube.index, [ [i^j,k,j,l] for j in [k,k^1] for i in [l,l^1] ])))
                        faces.append(list(map(hypercube.index, [ [i^j,k,l,j] for j in [k,k^1] for i in [l,l^1] ])))
                        faces.append(list(map(hypercube.index, [ [k,i^j,j,l] for j in [k,k^1] for i in [l,l^1] ])))
                        faces.append(list(map(hypercube.index, [ [k,i^j,l,j] for j in [k,k^1] for i in [l,l^1] ])))
                        faces.append(list(map(hypercube.index, [ [k,l,i^j,j] for j in [k,k^1] for i in [l,l^1] ])))
                                               
       
        #print "We got %i vertices and %i faces" % (len(hypercube), len(faces))
       
        me = bpy.data.meshes.new(name)          # create a new mesh
        Iter_Coords = map(project, hypercube)
        me.from_pydata(list(Iter_Coords),[],[])          # add vertices to mesh
        me.from_pydata([],[],faces)           # add faces to the mesh (also adds edges)
       
#        me.vertex_colors = 1              # enable vertex colors
#        me.faces[1].col[0].r = 255       # make each vertex a different color
#        me.faces[1].col[1].g = 255
#        me.faces[1].col[2].b = 255
       
        scn = bpy.context.scene         # link object to current scene
        ob = bpy.data.objects.new("cube", me)
        scn.collection.objects.link(ob)
       
        return ob, hypercube_verts
 
 
 
def drawHandler(x,y):
        blf.position(0, 15, 30, 0)
        blf.draw(0,"""Hypercube: Point here and use the {q,w,e,a,s,d} keys to rotate the hypercube""")
               
        blf.position(0, 15, 40, 0)
        blf.draw(0,"""Angles: %s""" % GLOBAL_ANGLES)
               
        blf.position(0, 15, 50, 0)
        blf.draw(0,"""Press ESC to quit (without deleting the Hypercube)""")
     
        bgl.glEnable(bgl.GL_BLEND)
        #bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
        bgl.glLineWidth(2)
      
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        #bgl.glColor4f(0.0, 0.0, 0.0, 1.0)

def buttonHandler(evt):
        return # ignore the rest; we don't need that 
 
#if editmode:
#        Window.EditMode(1)  # optional, just being nice
create_hypercube()
 
# center the hypercube
for v in HYPERCUBE_VERTS:
        v[0] = 2*v[0] - 1
        v[1] = 2*v[1] - 1
        v[2] = 2*v[2] - 1
        v[3] = 2*v[3] - 1
 
update_hypercube()  
class Hyper(bpy.types.Operator):
    """Rotate the HyperCube"""
    bl_idname = "view3d.hyper"
    bl_label = "hypercube"

    def modal(self, context, event):
        context.area.tag_redraw()
        
        #Controls how fast the hypercube is rotated
        d = math.pi/300     #Hi-res rotation
        #d = math.pi/30     #Low-res rotation
       
        if event.type == "ESC": # Example if esc key pressed
            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')  # then exit script
            return {'FINISHED'}
        elif event.type == "A":
                rotate_hypercube(d, 0., 0.)
                print("test")
        elif event.type == "D":
                rotate_hypercube(-d, 0., 0.)
        elif event.type == "W":
                rotate_hypercube(0., d, 0.)
        elif event.type == "S":
                rotate_hypercube(0., -d, 0.)
        elif event.type == "Q":
                rotate_hypercube(0., 0., d)
        elif event.type == "E":
                rotate_hypercube(0., 0., -d)  
        else:
                return {"RUNNING_MODAL"}
        
        return {'RUNNING_MODAL'}
    
    def execute(self, context):
        print("Executed")
        return {'PASS_THROUGH'}
        
    def invoke(self, context, event):
        if context.area.type == 'VIEW_3D':
            args = (self, context)
            self._handle = bpy.types.SpaceView3D.draw_handler_add(drawHandler, args, 'WINDOW', 'POST_PIXEL')
            self.mouse_path = [] 
                        
            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "View3D not found, cannot run operator")
            return {'CANCELLED'}

def register():
    bpy.utils.register_class(Hyper)

def unregister():
    bpy.utils.unregister_class(Hyper)

if __name__ == "__main__":
    register()

Pasteall link: https://pasteall.org/du4K


r/blenderpython • • May 29 '20

Script to normalize the size and position of an object

Post image
7 Upvotes

r/blenderpython • • Feb 09 '17

Easy Blender script debugging with Eclipse!

7 Upvotes

I've built a setup for debugging Blender Python code using Eclipse. I think it's quite neat, and it has a couple of advantages over existing options, so I thought I'd share it: https://github.com/georgevdd/blender-eclipse/blob/master/README.md

I'd like to continue to polish it until it is really easy to set up and It Just Works. Please let me know what you think!


r/blenderpython • • Apr 03 '26

Spent the week learning Blender 2.79 Python API to build this procedural Neon Jumpanimation. Physics based landings + Dynamic Emission pulsing. What do you think?

6 Upvotes

I’ve been pushing myself to learn the scripting side of Blender for a freelance goal on June 5th. This project uses bpy to generate the text, convert it to mesh, separate the letters, and then 'hand off' the animation from keyframed movement to a Rigid Body physics simulation.

Each letter has a unique material instance so I could pulse the Emission strength individually during the jump. Proud of how the 'squash and stretch' logic combined with the physics hit!

Shoutout to 'Mc kenzie for some loop logic and that rigid body physic part too ,

I got it from one of his tutorials en my AI thought partner for helping me debug the node-tree logic!..


r/blenderpython • • Nov 02 '24

Is it possible to control these properties of Simulation node in Python?

Post image
6 Upvotes

r/blenderpython • • Jun 23 '23

Help I am a marine biologist not a programmer

6 Upvotes

I have this project I am trying to automate, but I know next to nothing about programming, especially python. This is my first time using python. The lab I am in basically runs on R which I am in the process of learning, but no one else in my lab knows any python. Basically, I am trying to automate the process so that blender imports a file, remeshes it, triangulates it, then exports it. Heres the codes I have so far that works:

import bpy

bpy.ops.object.delete(use_global=False)

bpy.ops.import_mesh.stl(filepath="C://Users//aedan//Downloads//OneDrive_1_6-22-2023//Fish_1_bladder.stl")

bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='MEDIAN')

bpy.context.scene.unit_settings.length_unit = 'MILLIMETERS'

bpy.ops.object.modifier_add(type='REMESH')

bpy.context.object.modifiers["Remesh"].voxel_size = 0.00025

bpy.ops.object.modifier_add(type='TRIANGULATE')

bpy.context.space_data.overlay.show_wireframes = True

The part I am having trouble is when I go to export it. I do not know how to write the code so that it gets exported as an .stl. Also it has to be an ascii file. When I export it manually there is a little box in the right hand corner I check off to indicate that it is ascii.

Here is the code I try unsuccessfully. I am trying to export it into a file named export:

bpy.ops.export_scene.stl(filepath="C://Users//aedan//Downloads//export",export_format=.stl)

There error I usually get is invalid syntax. How would I write the code in a way that specifies the file as a .stl, specifies it as ascii, specifies the name I want for the exported file(Fish_1_swimbladder_voxel_0.25.stl) and specifies which folder i want the exported file to go into.

Any advice is greatly appreciated. Again I am not a programmer, I just like fish. I am a fish programmer. I do fish stuff. Not computer stuff. STRIICTLY fish stuff. Fish dont have computers. Why do I have to have a computer I hate computers. I love fish. Fish hate computers. I love fish. Yet, I still need to do computer fish stuff from time to time. Even if they had computers how would that work? They dont have fingers. What kind of keyboard would they use? An octopus, sure, but they arent a fish. Techinically humans are fish. I mean thats an inaccurate statement, but it wouldnt be inaccurate to say we fall under the umbrella of fish. No thats not really accurate but again not inaccurate. I mean what even is a fish, huh? You tell me mr fish man. Mr I know all about fish FUCK YOU, Mr walkway. Mr walk me to the docks to go see some fish am I right? But what is a fish? Is it just cause its in the water, NO. Because then a fucking otter would be a fish wouldnt it. DO NOT even get me started with those little greedy no good backstabbing little fucks. A poikilothermic aquatic chordate covered scales with fins for appendages and gills for respiration? Well what about Tuna, they are homeothermic. Eels dont have appendages fucko. Cyclostomes dont have scales. Lungfish can breath out water using their physostomous swimbladder. Why arent sharks considered fish? Cause they are cartilaginous? But they have gills and are chordates and are poikilotherms. They even have scales and fins! You know what else "fish" dont have, .... d e f i n i t i o n s. All they know is swim n eat. but if we are fish(kinda) then we shouldnt have comupters right? right? Or definitions. I guess we are just shitty fish. I bet other fish see us flailing about in the water and think "jeez, blub blub blub". Fuck it mammals are fish too. There are plenty of aquatic mammals, like dugongs, whales, and dolphins. I think they got their shit together. We should go back to the sea. Become the fish we were really meant to be. No definitions or god forbid computers. I think if I was a fish I would be a reallly really cool fish like Will Smith fish. God I love Will Smith fish. Will Smith fish is sooooo cool. But this is the real world. I am not that cool. I am not a fish. God I with I was a fish. I love fish.


r/blenderpython • • Nov 21 '22

Optic flow in Blender Python 2.79

6 Upvotes

Hey All! I am making some motion animation videos through blender python and was wondering if getting the optic flow for the objects moving in the animation video created could be retrieved somehow through blender python.

I am using blender python version 2.79.


r/blenderpython • • Jun 03 '21

What is your favourite devolopment env for Blender Python dev? This Visual Studio plugin by Jaques Lucke is often breaking on me, but it is the best I have found so far. Any suggestions?

6 Upvotes

I am making a multi file python addon as you do. Often when the code breaks the plugin needs me to shut down Blender then restart it from the Visual Studio pallette. Reload addons and reload scripts just gives errors about trying to register already registered classes.


r/blenderpython • • Sep 23 '20

After spending the last week trying to learn scripting in Blender, I've come here to ask for help.

6 Upvotes

Im not a coding person, im a 3d modelling person, it took 7 years to get a basic understanding of that and scripting/animating is beyond me.

what I would like to learn is this:

Object moves to a point then stops.

ideally i need some sort of script which has vairables I could expeirment with, such as the speed etc.

then I could add bits on as needed and work out what each bit does. (thats how I learn!)

could some one copy paste a bit of code below to help us out?

thank you!


r/blenderpython • • Mar 10 '17

Blender Python script to create animation with numerous cubes randomly changing colors and going up and down

Thumbnail emalis.com
6 Upvotes

r/blenderpython • • Sep 24 '16

Intro to scripting and gif making tutorial

6 Upvotes

I recently used Blender for a project and thought I would share my notes on using Python scripting. Would love some feedback!

https://github.com/fhoehl/blender-python-gif