r/blenderpython • • Aug 07 '24

I just released my most complex addon yet: BlendAI! It comes with many powerful AI features and works based on a credit system. Link in the video description

Thumbnail
youtu.be
0 Upvotes

r/blenderpython • • Aug 29 '24

i need help finishing this addon

0 Upvotes

I don't know much about coding i kinda understand the very basics so i am using chatgpt and other AIs to help me make it but i got stuck and the AI is just giving me the same code without any difference so basically i am trying to make an addon that takes the selected 3d model and takes each part and laies it out inside a mesh that i input the dimensions of basically like maxcut (i cant use max cut because it doesnt use weird shapes and i want it tin blender) so right now i cant get the xyz input field to work and there is a bunch of errors that i cant get the AI to fix

here is what i have so far

import bpy

import mathutils # Use mathutils for Blender math functions

class MyAddonSettings(bpy.types.PropertyGroup):

"""Stores dimensions for the addon"""

dimensions_x = bpy.props.FloatProperty(name="Dimension X", default=1.0)

dimensions_y = bpy.props.FloatProperty(name="Dimension Y", default=1.0)

dimensions_z = bpy.props.FloatProperty(name="Dimension Z", default=1.0)

class CopyPasteFlatOperator(bpy.types.Operator):

"""Copy and Paste Flat Operator"""

bl_idname = "object.copy_paste_flat" # Unique identifier

bl_label = "Copy Paste Flat" # Label displayed in the menu

def execute(self, context):

Get the selected meshes

selected_meshes = bpy.context.selected_objects

Create a new empty collection to store the copies

new_collection = bpy.data.collections.new("Copied Meshes")

bpy.context.scene.collection.children.link(new_collection)

Create a new mesh with specified dimensions (from panel properties)

container_mesh = bpy.data.meshes.new(name="Container Mesh")

container_mesh.from_pydata(coords=[], edges=[], faces=[]) # Empty mesh data

container_object = bpy.data.objects.new(

name="Container", object_data=container_mesh

)

bpy.context.collection.objects.link(container_object)

container_object.scale = (

context.scene.my_addon.dimensions_x,

context.scene.my_addon.dimensions_y,

context.scene.my_addon.dimensions_z,

)

Copy and paste each mesh, adjusting its location within the new mesh

for mesh in selected_meshes:

mesh_copy = mesh.copy()

mesh_copy.data = mesh.data.copy()

Link the copy to the new collection

new_collection.objects.link(mesh_copy)

Adjust location to be flat and centered within the container mesh

mesh_copy.location = container_object.location + (

context.scene.my_addon.dimensions_x / 2,

context.scene.my_addon.dimensions_y / 2,

context.scene.my_addon.dimensions_z / 2,

)

Ensure copied mesh stays within container boundaries (basic approach)

max_x, max_y, max_z = (

context.scene.my_addon.dimensions_x,

context.scene.my_addon.dimensions_y,

context.scene.my_addon.dimensions_z,

)

min_x, min_y, min_z = -max_x, -max_y, -max_z

mesh_copy.scale = (

min(1.0, max_x / mesh_copy.dimensions.x),

min(1.0, max_y / mesh_copy.dimensions.y),

min(1.0, max_z / mesh_copy.dimensions.z),

)

return {'FINISHED'} # Indicate successful execution

class LayoutDemoPanel(bpy.types.Panel):

"""Creates a Panel in the scene context of the properties editor"""

bl_label = "Blender addon"

bl_idname = "SCENE_PT_layout"

bl_space_type = 'PROPERTIES'

bl_region_type = 'WINDOW'

bl_context = "object"

Define the properties for dimensions

u/classmethod

def get_settings(cls):

return bpy.context.scene.my_addon

def draw(self, context):

layout = self.layout

settings = self.get_settings()

Add input fields for dimensions (using FloatProperty)

layout.prop(settings, "dimensions_x")

layout.prop(settings, "dimensions_y")

layout.prop(settings, "dimensions_z")

Big button to trigger operator

layout.label(text="Create Mesh and Paste Copies:")

row = layout.row()

row.scale_y = 3.0

row.operator("object.copy_paste_flat")

def register():

Ensure LayoutDemoPanel is registered before Scene

bpy.utils.register_class(MyAddonSettings) # Register the property group first

bpy.utils.register_class(LayoutDemoPanel)

bpy.utils.register_class(CopyPasteFlatOperator)

Now register the property in the Scene

bpy.types.Scene.my_addon = bpy.props.PointerProperty(type=MyAddonSettings)

def unregister():

del bpy.types.Scene.my_addon

bpy.utils.unregister_class(CopyPasteFlatOperator)

bpy.utils.unregister_class(LayoutDemoPanel)

bpy.utils.unregister_class(MyAddonSettings)

if __name__ == "__main__":

register()


r/blenderpython • • Apr 01 '23

Low-code machine-learning PyCaret

Thumbnail
satyakide.com
1 Upvotes

r/blenderpython • • Aug 24 '20

Open varios programs portables like a calculatoran so on, in a panel interface blender

0 Upvotes

I am trying to make the script but l can't manage to open more than one.

I am using de 3dview panel and it only works with one os link

I got the def and invoke it however it only works for the first app

I need some ideas to solve this because I am relatively new in script in phyton

Thanx you in advance


r/blenderpython • • Nov 12 '17

Helicopter script

0 Upvotes

I want python script for helicopter game any one know that help me


r/blenderpython • • Feb 14 '26

Mesh Writer: 20% Launch discount for limited time!!

Thumbnail
reddit.com
0 Upvotes

r/blenderpython • • Apr 12 '23

[Help Needed] Blender Script to bake texture into a GLTF Scene $45 Reward

1 Upvotes

r/blenderpython • • Sep 22 '24

Would love some help fixing this script that AI generated

1 Upvotes

Sorry, I don't know if it's annoying to ask for help with ChatGPT generated code. I gather it's a little imperfect. I myself am not a coder (hence ChatGPT).

import bpy
import os

# Define the directory to search for .gltf files
directory_path = r"D:\STOCK IMAGES\3D Stock Models\Buildings_RUINED WALLS\07 Brick wall scan (great detail but no tops or sides)"

# Search for .gltf files in the directory
gltf_file = None
for file_name in os.listdir(directory_path):
    if file_name.endswith(".gltf"):
        gltf_file = os.path.join(directory_path, file_name)
        break  # Stop after finding the first .gltf file

if gltf_file:
    # Import the found GLTF file
    bpy.ops.import_scene.gltf(filepath=gltf_file)

    # Unparent all objects while keeping their transformation
    for obj in bpy.context.scene.objects:
        if obj.parent is not None:
            obj.select_set(True)
            bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM')

    # Delete all empties
    for obj in bpy.context.scene.objects:
        if obj.type == 'EMPTY':
            obj.select_set(True)
    bpy.ops.object.delete()

    # Join all mesh objects into one
    bpy.ops.object.select_all(action='DESELECT')
    for obj in bpy.context.scene.objects:
        if obj.type == 'MESH':
            obj.select_set(True)
            bpy.context.view_layer.objects.active = obj  # Set one of the meshes as the active object

    bpy.ops.object.join()  # Join the selected meshes

    # Weld vertices by removing doubles
    bpy.ops.object.mode_set(mode='EDIT')  # Switch to edit mode
    bpy.ops.mesh.select_all(action='SELECT')  # Select all vertices
    bpy.ops.mesh.remove_doubles(threshold=0.001)  # Merge vertices that are very close
    bpy.ops.object.mode_set(mode='OBJECT')  # Return to object mode

    print(f"Imported and cleaned: {gltf_file}")
else:
    print("No .gltf files found in the specified directory.")

I simply want to automate the importing of sketchfab scans so they unparent and merge.


r/blenderpython • • Nov 16 '16

Extract 2d views of a 3d model

0 Upvotes

Is it possible to extract a 2d view (top, side view etc) from a 3d view in blender?

If yes then could you direct me towards the solution. I complete newbie.


r/blenderpython • • Sep 20 '20

Looking for someone to write me 2 simple addons (PAID)

1 Upvotes

I'm looking for someone that can write me 2 simple addon templates. I don't really have time to learn python and i can't get what i want from the short tutorials on YT so i want to pay someone to write me 2 relatively customizable templates.

First one - N-Panel that allows me to append specific collection from a .Blend.

Good example of that would be Botaniq (https://blendermarket.com/creators/polygoniq) addon that has pretty much everything i would like. Only talking about "Spawn Asset" button.

If possible, button should be skipped directly into the "spawn asset" menu removing top 4 checkboxes and "make editable" checkbox.

All i need from this is to just have that kind of menu for appending collections with assets. I'm not asking for 100% copy of course, this is just an example of what i'm looking for. Main purpose for that is so i can have 1 blend file in the addon folder with my assets and append them easily. Bonus points if i can also append brushes with custom icons, i don't know if that's possible in a one addon but it would be great if it was possible. Mainly talking about texture draw brushes but sculpt brushes are appreciated too. It all should work like a normal addon so i can share it with friends.

In the code itself i'd like to have descriptions for segments of the code and it should be most importantly easy to change up so i can reuse it for different addons.

Second Addon - N-Panel like above but this time just really really simple including only 3 tabs found in the armature tab, "Skeleton", "Pose Library" and "Custom Properties"

nothing more nothing less. Should take that data from the active armature. Simply want it to make my personal rigs a bit easier to use for external users. All 3 tabs should be collapsible.

I hope i'm not asking for too much and it all should be relatively easy to write.

PayPal only, price will be discussed privately. If you're interested in working on those addons for me either add me on Discord DanteBoi#3228 or just leave your contact info here. Please straight up show me what did you do in Python so far just so i can see if i can trust you and tell me the pay you expect for it. Thank you ^^

If i'm posting this in a wrong place, please forward me to a correct one. I tried to look around for some kind of addon commissions but i couldn't really find anything.

Originally posted in r/blender but decided to post here too.


r/blenderpython • • Dec 13 '23

Can anyone help me make this addon compatible with 4.0?

1 Upvotes

Report: Error igme Froxy owap vjun. Python: Traceback (most recent call last): File "C:\Users\censored\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\FZRandomizer_3_0_3.py", line 3039, in execute multiOBJ(context) File "C:\Users\censored\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\FZRandomizer_3_0_3.py", line 1114, in multiOBJ buildChars(name, generations, genCodesList, proxyParametersList) File "C:\Users\censored\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\FZRandomizer_3_0_3.py", line 1186, in buildChars ng= buildHostProxy(genCodesList) File "C:\Users\censored\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\FZRandomizer_3_0_3.py", line 1493, in buildHostProxy ng= make_hostcollgroup(host, proxy, genCodesList) File "C:\Users\censored\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\FZRandomizer_3_0_3.py", line 646, in make_hostcolLgroup hostcoll_group.inputs.new("NodeSocketGeometry", "Input") AttributeError: 'GeometryNodeTree' object has no attribute 'inputs'


r/blenderpython • • Sep 26 '18

How can I use a boolean property inside of a custom operator class as a conditional for a set of commands.

Thumbnail
blender.stackexchange.com
1 Upvotes

r/blenderpython • • May 17 '21

Blender keeps crashing after opening the System console + save

3 Upvotes

Title. Sometimes it's fine if I toggle the system console off again but sometimes it still crashes. Why does this happen ? It makes the scripting experience pretty bad


r/blenderpython • • Jun 25 '21

Which Python.

4 Upvotes

Hi,

I have watched a couple of tutorials on setting up an IDE (VSCode) with blender. In one video the presenter uses Python that comes with Blender. In another, he downloads the latest python and uses it.
Is there any reason to do one or the other?

Thanks,
Robb


r/blenderpython • • Dec 04 '18

Python Tutorial: 3D Wrecking Animation With 14 Lines of Code

Thumbnail
youtube.com
4 Upvotes

r/blenderpython • • Oct 28 '18

Python Tutorial: 3D Wrecking Animation With 14 Lines of Code

Thumbnail
youtube.com
4 Upvotes

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 • • 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 • • 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 • • 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 • • May 14 '26

Mesh Writer — Search. Mesh. Animate. 5,000+ Symbols & 3700+ SVGs for Mesh and Geometry Nodes

4 Upvotes

Mesh Writer is a searchable symbol library (with a built-in SVG editor) that turns symbols, SVGs, math characters and emojis,  into Geometry Nodes curves or 3D mesh or 3D Curves.

With over 5,000+ symbols and 3,700+ SVG assets, Mesh Writer streamlines the full workflow — search, insert, import materials, and convert to mesh or Geometry Nodes,

Get it now on Superhive: Get Mesh Writer


r/blenderpython • • Apr 15 '26

Blender Python Cheatsheet v2.0 Released

Post image
11 Upvotes

r/blenderpython • • Jun 28 '25

Blender Scripting Cookbook

Thumbnail
gallery
13 Upvotes

r/blenderpython • • Jun 08 '20

Questions on exporting unique vertex attributes

3 Upvotes

I'm working on a custom exporter. I'm not too familiar with blender and its API, so I looked at the obj exporter and got a bit confused at what it's trying to do.

I'm only interested in exporting basic geometry (for now) in a way that makes sense for a 3d game engine, so vertices can't have multiple values for the same attribute etc, but also I want to use as few vertices as possible. I'm not interested in export performance yet as my meshes are meant to be generally small.

Currently I have a working solution that works like this:

  1. Create an empty dictionary that maps vertex information to an index

  2. For each entry in the mesh loops:

    1. Gather all attributes (vertex index, normal, uvs, etc) into a single object and check if it exists in the dictionary.

    2. If it doesn't:

      1. Add the entry as the key and set value to be the current dictionary size. The value will also be used as the output index for this loop entry.

      2. Add the attributes as a new Vertex in the output vertices list.

    3. If it does exist, use that value as the output index of this loop entry.

    4. Add the output index to the output indices list.

I don't feel very good about hashing and comparing floating point numbers, but then again I assume blender explicitly uses the exact same floating point value when the normal is supposed to be the same so hashing and equality checking will work as expected.

Is what I'm doing the right way or is there a more proper way to do this? Does blender have an integer id for unique normals, colors, uvs, etc the way it does for positions that I can use instead of hashing floats?