r/blenderpython • • Apr 26 '25

Copying Grease Pencil Keyframes in Blender 4.4

1 Upvotes

Hello, I've been developing a rigging system that would allow me to rig a 2D grease pencil character with different views, making up a 360 degree turn around.
As part of this I've been trying to make a script that copies a keyframe, but I can't figure it out. Asking chat GPT they said that since updating to Grease Pencil 3, the python API is incomplete and it's impossible to copy a keyframe through code. Is this true? if so is there a work around? Any help would be greatly appreciated.


r/blenderpython • • Dec 14 '24

How do I interact with elements in Blender using Python

1 Upvotes

I'm trying to create an abacus in Blender and I want to select individual beads and interact with them using Python. I thought it'd be easier to model the abacus on Blender, instead of using stuff like three.js to code each shape individually. But I know next to nothing about Blender. Is there a way I'm able to select each bead, or the frame of the abacus, and make it a Python object? So I can use a Python script to interact with them, like move them across the rod.

Is this a foolish thing to do? I mean, is there a way better way to go about it?


r/blenderpython • • Dec 12 '24

Blender UI status !!

1 Upvotes

Hello, i want to know is blender API can send Interface statues
which mean if user switch between modes like from modeling to sculpting
i want to read the interaction with UI window in blender


r/blenderpython • • Nov 09 '24

Python to open/close side (N) panel addon tabs?

1 Upvotes

Hey everyone, I’m wanting to try and make a simple addon to search the side (N) panel for addons (as my addon layout is getting out of hand.)

Can I open and close these individual addon tabs with python?

I had a quick google and could only find ways to open and close the entire side panel, not individual tabs within. Claude.ai also couldnt find a solution so thought Id ask here. If someone could point me in the right direction I would be really grateful.

Thanks!


r/blenderpython • • Oct 30 '24

[HELP] Cant get proper obj copies from alembic frames

1 Upvotes

I am currently working on a vertex animation texture generation inside blender and I got pretty far, I specifically was working on remeshing water simulations to always use constant amount of vertecies/polygons.

But now I wanted to debug it with a simple Icosphere rolling down from a slope,

The problem is Bender refuses to make correct copies and get the correct vertex position data even tho it fully works for imported alembic files of water drops but not a simple rigid body simulation?

They both are mesh cash animated objects inside blender and the script expects them to be

relevant function from my script:

https://pastebin.com/cc96nB5j


r/blenderpython • • Oct 02 '24

Custom ui panel : advanced IK FK switch

1 Upvotes

r/blenderpython • • Sep 27 '24

Trying to use vscode with blender. Anyone know to fix this?

Post image
1 Upvotes

I already installed python extension by Microsoft, blender development plug-in by Jacques Lucke, Fake byp module. Python version on my system is 3.11.7 which is same what is used by blender 4.2.2

I have not clue where to go from here.


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 • • Sep 13 '24

Use s3 as your storage easily right from blender UI

Thumbnail
reddit.com
1 Upvotes

r/blenderpython • • Jul 29 '24

Get list of objects in camera view

1 Upvotes

I´m working on a project where there is a scene with objects spread across it, simulating a simple warehouse.

I have a camera object that will be placed in several points and render images. Right now I want to check if the camera has an object in its view, before rendering the image. I also want to return a list of the objects that are in camera view, to save in a separate JSON file. But I´m having trouble getting the correct objects in the view, there may be problems with obtaining the camera frustum.

Can someone help me or provide me code that does what I intend to do?


r/blenderpython • • Jul 25 '24

[HELP] Script to add control handles to bendy bones, need help figuring out 1 weird bug!

1 Upvotes

This is my first attempt at Blender Python scripting. I am following this tutorial on bendy bones. I'm focusing only on the first part of the video which goes all the way to around 3 minutes.

I am trying to automate this process, and with ChatGPT doing the heavy lifting, I got most of the script working. What you do is select a bendy bone, and when you run the script it:

  1. creates control bones at each end

  2. reparents the original bone to the "start" bone

  3. aligns the Roll of these new bones to the original

  4. creates a Stretch To constraint to the "end" bone

  5. changes the bendy bone's start and end handle attributes to "Tangent"

  6. puts these new bones into the "custom" section of start and end handle attributes

Miraculously, the script mostly works how I want it to, but then I noticed something strange and incredibly irritating. It makes no sense, which is why I'm here: the bone that gets placed into the start and end handle section is completely random. Sometimes they are correctly placed, sometimes "start" gets put into the end handle, and sometimes even the original bone gets placed in these sections!

Someone please put me out of my misery!


r/blenderpython • • May 19 '24

Transform modal map

1 Upvotes

I'm making an addon that has some remapping of the keyconfigurations how would you guys edit the transform modal map trough coda I want Y axis to be overriden by SPACE and SHIFT + SPACE

These are the specific keys that I want to override with code:

This is an extract from the code I´m trying to put together:

wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:  
    
    # Handling modal keymap changes
    km_transform_modal = kc.keymaps.get('Transform Modal Map')
    if km_transform_modal:
        # Add a modal keymap item for Y axis constraint during translation
        kmi = km_transform_modal.keymap_items.new_modal('CONFIRM', 'SPACE', 'PRESS')
        kmi_props = kmi.properties
        kmi_props.name = 'axis_y'
        addon_keymaps.append((km_transform_modal, kmi))
    else:
        print("Modal keymap 'Transform Modal Map' not found")

    km_edit_mode = kc.keymaps.new(name='Mesh', space_type='EMPTY')
    # LOOP CUT
    kmi = km_edit_mode.keymap_items.new(HP_OT_loopcut.bl_idname, type='R', value='PRESS', ctrl=True, shift=False)
    addon_keymaps.append((km_edit_mode, kmi))

    # SMART PUSH AND SLIDE
    kmi = km_edit_mode.keymap_items.new(HP_OT_PushAndSlide.bl_idname, type='G', value='PRESS', ctrl=False, shift=True)
    addon_keymaps.append((km_edit_mode, kmi))

    kmi = km_edit_mode.keymap_items.new('mesh.select_prev_item', type='WHEELOUTMOUSE', value='PRESS', ctrl=False, shift=True)
    addon_keymaps.append((km_edit_mode, kmi))

    kmi = km_edit_mode.keymap_items.new('mesh.select_next_item', type='WHEELINMOUSE', value='PRESS', ctrl=False, shift=True)
    addon_keymaps.append((km_edit_mode, kmi))
    
    kmi = km_edit_mode.keymap_items.new('mesh.loop_select', type='LEFTMOUSE', value='PRESS', ctrl=False, shift=False, alt=True)
    addon_keymaps.append((km_edit_mode, kmi))
    
    kmi = km_edit_mode.keymap_items.new('mesh.edgering_select', type='LEFTMOUSE', value='DOUBLE_CLICK', ctrl=False, shift=False, alt=True)
    addon_keymaps.append((km_edit_mode, kmi))

r/blenderpython • • May 18 '24

I've got a (free) plugin user getting "AttributeError: 'Converter' object has no attribute 'scene'"

1 Upvotes

I'm doing my best, but so far no breakthroughs.

It's a classic case of "It works on my PC", and it doesn't work on theirs.

When they try and use the new "Import lego" menu item, they tell me of the AttributeError: 'Converter' object has no attribute 'scene' error.

total = len(self.scene.Bricks)

This is where I get stuck.

I googled it, and there's clear instructions that the BPY Scene object isn't available during registration of a plugin, and only when it's triggered, and is passed through to the execute function via a "context" attribute.

That's just what the code is doing! (and it works on my PC)

I wonder if it's because the users scene is empty, Null? Whereas mine default Blender scene has a Plane, light, etc... I'm waiting for them to get back to me.

If not that, that's where I lose it completely, is Pythons "self" / "context" things not passing "scene" through?

https://github.com/Sarah-C/BlenderImportLDD/issues/1

Traceback (most recent call last):
  File "C:\Users\Jack\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\BlenderImportLDD.py", line 1481, in execute
    return convertldd_data(context, self.filepath, self.lddLIFPath, self.useLogoStuds, self.useLDDCamera)
  File "C:\Users\Jack\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\BlenderImportLDD.py", line 1416, in convertldd_data
    converter.Export(filename=filepath, useLogoStuds=useLogoStuds, useLDDCamera=useLDDCamera)
  File "C:\Users\Jack\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\BlenderImportLDD.py", line 955, in Export
    total = len(self.scene.Bricks)
AttributeError: 'Converter' object has no attribute 'scene'

Many thanks for your help!


r/blenderpython • • Apr 20 '24

Split mesh but connect split vertices?

1 Upvotes

I’m working on a project where I’ve got a mesh that I want to split into chunks. The splitting part is easy. I’m using bmesh so I can just use split_edges to break it up and that works great.

So now it’s split into chunks and all the vertices on the boundary of each chunk has a matching vertex on the other chunk it was split from. I want to join those matching vertices on the different chunks with an edge, but there doesn’t seem to be an easy way to do that. I could loop through all the boundary points until I find all matching pairs and then call a function to connect them with edges one at a time but that seems ridiculous. Any suggestions?


r/blenderpython • • Apr 13 '24

Alternative to draw function in gpu Module?

1 Upvotes

I want to use the blender gpu Module. In the examples they say that the draw function is only there to make the code short. The problem is that I want to remove (or update) the lines without restarting blender. How would that be possible?

Example: https://docs.blender.org/api/current/gpu.html#d-lines-with-single-color

Thank you


r/blenderpython • • Mar 23 '24

New BPY user trying to define a problem about managing rig & animation data for a game project im working on.

1 Upvotes

Building a fighting game, here's the system I'd like to build: a shared human rig, using other blends to import corresponding meshes of characters so that there arent a ton of unneeded characters sitting in the file. animation groups so that I can specify which animations are shared between characters and which are unique to a particular character for export. Does this sound possible? And if anyone has any guidance about implementation or other words of wisdom I'd really appreciate it.
edit: oh and do people use this or the Blender Artists: Python Support Forum thats linked in the docs? wheres the place 2 be basically ;p


r/blenderpython • • Mar 21 '24

How to create a bool type socket input for shader node groups in Blender 4.0

1 Upvotes

Hi there, I'm not very experienced with python but I used:

import bpy bpy.data.node_groups['MyGroupName'].inputs.new('NodeSocketbool', 'SocketName')

to create custom boolean socket inputs for shaders. This used to work in 3.5 but doesn't in 4.0 anymore. I tried to understand the documentation on what changed but I don't really find the solution but that might be due to my inexpience with python.

It says there's not inputs attribute anymore. Can someone help?


r/blenderpython • • Feb 21 '24

Waiting for compositor to finish before saving image to file. Tips on asynchronous processes?

1 Upvotes

I'm trying to write a script that will tweak some settings in the compositor, then save the resulting image.

However, The resulting image is NOT receiving the changes that are being made in the compositor. I suspect that blender is not, "waiting for the compositor to finish" before saving the image.

I've tried using Application handlers, but I don't really understand how to use them in this case.

Any help? Here's the code in question, without attempting to use application handlers:

    #get the render result
    render = bpy.data.images["Render Result"]
    
    #set the value of a compositor node to 0
    bpy.data.scenes["Scene"].node_tree.nodes["color vs. depth"].inputs[0].default_value = 0
    #change the colorspace to filmic
    bpy.context.scene.view_settings.view_transform = 'Filmic'
    
    #save the image
    render.save_render(filepath = tool.my_path + tool.my_string + " COLOR.png")

r/blenderpython • • Feb 01 '24

rationale for changes in bpy 4.0

1 Upvotes

Hi, I was wondering why bpy.ops.export_scene.obj is no longer in version 4.0 ? Any links that would explain the changes ?


r/blenderpython • • Jan 28 '24

identifiers for BezierCurve points

1 Upvotes

I'm working on an addon that creates a smooth surface bazed on Bezier curves wireframe. I want to give to the user an ability to manually adjust the surface, and for this ideally that they
- selects a Bezier segment
- adjusts the values in the pop-up menu or drags the specific handle that apparates for this purpose
- the value is stored linked to this segment when the user edits the curve: drags points and creates/deletes segments.

I'm new in Blender scripting (nearly all my experience is writing the part that actually generates surface mesh) and my plan for now is this:
- generate an id for each point and store it in weight_softbody attribute (I don't like this part because the user may want to actually do the softbody simulation, but I didn't found better way)
- in my code, create a mapping of these ids and my custom surface parameters for the segments on the right and on the left of this point, and also ids of neighbour points on the right and on the left
- when the user selects for example right handle, they can summon a menu with input fields (or maybe I can create a temporary segment that can be used as a handle)
- my code verifies that the id on the right is what is enregistred. If yes, we edit segment to the right property, if no, the user has changed segment direction and we edit segment that is enregistred as to the left
- After this, the surface is updated, the value is stored in my code and all values are saved in Curve custom property as dictionnary.

Is there a way to do this without using a built-in attribute?

Sorry for giving such a lot of context, but maybe there is a way to achieve what I want completely differently.


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 • • Dec 11 '23

Script Update 4.0 Component Space

1 Upvotes

Hello,
I have this script from blender 3.3 that I would like to use in 4.0. Select a face and the script will move the orientation to the face.

3.6

import bpy

class ComponentSpace(bpy.types.Operator):

bl_label = 'Component Space'

bl_idname = 'wm.setcomponentspace'

def execute(self, context):

for area in bpy.context.screen.areas:

if area.type == 'VIEW_3D':

ctx = bpy.context.copy()

ctx['area'] = area

ctx['region'] = area.regions[-1]

orientName = 'tempOrientation'

bpy.ops.transform.create_orientation(name=orientName)

bpy.context.scene.transform_orientation_slots[0].type = orientName

bpy.ops.object.editmode_toggle()

bpy.context.scene.tool_settings.use_transform_data_origin = True

matrix = bpy.context.scene.transform_orientation_slots[0].custom_orientation.matrix

bpy.ops.transform.transform(mode='ALIGN', orient_matrix=matrix)

bpy.ops.object.editmode_toggle()

bpy.ops.view3d.snap_cursor_to_selected(ctx)

bpy.ops.object.editmode_toggle()

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

bpy.context.scene.tool_settings.use_transform_data_origin = False

bpy.ops.transform.delete_orientation()

bpy.context.scene.transform_orientation_slots[0].type = 'LOCAL'

break

return {'FINISHED'}

addonKeymaps = []

def register():

bpy.utils.register_class(ComponentSpace)

windowManager = bpy.context.window_manager

keyConfig = windowManager.keyconfigs.addon

if keyConfig:

keymap = keyConfig.keymaps.new(name='3D View', space_type='VIEW_3D')

keymapitem = keymap.keymap_items.new('wm.setcomponentspace', type='F', shift=True, value='PRESS')

addonKeymaps.append((keymap, keymapitem))

def unregister():

for keymap, keymapitem in addonKeymaps:

keymap.keymap_items.remove(keymapitem)

addonKeymaps.clear()

bpy.utils.unregister_class(ComponentSpace)

if __name__ == '__main__':

register()


r/blenderpython • • Nov 22 '23

MatLayer 2

1 Upvotes

Hi everyone,

I’ve been working for the past 5 months, putting roughly 6 – 10 hours a day (in addition to some of my heart and soul) to create the next version of my Blender add-on.

I’m very proud to announce the release of MatLayer 2!

For those who are not familiar, MatLayer is a 100% free Blender add-on that wraps the material nodes with a layer based user interface. This allows instant mixing of full PBR materials, emulation of industry leading material creation workflow, and implementation of many essential features for a fast and efficient material editing workflow.

Some of the main features of this add-on currently includes:

- A one-click mesh map baker for baking ambient occlusion, curvature, thickness, world space normals, and high to low poly normal maps, all heavily optimized to bake mesh maps as fast as possible.

- Fast, full PBR material layering, with lots of control, and built-in filters like blurring.

- Fast, optimized masking and multi-masking for materials.

- A toggle for true tri-planar projection (with corrected normals)!

- Auto-corrections for normal map projections.

- Decal layers for non-destructive projection of text / stickers.

- Basic support for merging materials.

- Fast effects for edge wear and dirt.

- Fast importing of full PBR texture sets.

- One-click exporting for texture sets with automatic channel packing for commonly used software applications and formats.

- An exporting options for baking multiple material slots to a single texture set.

The main focus of this release was initially better performance, bug fixes and stability, but I’ve implemented some massive improvements to workflow, quality and many new features!

To get MatLayer 2, and to see a full list of features and new changes in this version you can check out the latest release on the Github - https://github.com/LoganFairbairn/matlayer/releases

I plan on creating a new tutorial series, within the near future to help explain workflow and features available in the software.

Although MatLayer is still not a perfect software, I really hope you enjoy this add-on, I’ve put many long days and nights into this. I’m hoping this gives users the freedom to create some new amazing materials for their 3D models within Blender.

This add-on is my personal thank you to the Blender developers for making such an amazing software, and to the community for keeping it charged.

Cheers, and happy blending!


r/blenderpython • • Nov 14 '23

Getting text data from geometry nodes

1 Upvotes

I've created a modifier that creates shapes using the bounding box data of an object. I now need to write the parameters (size, rotation, etc) of those shapes to a text file. I figured the best way to do that would be to grab the data from the node outputs but I'm having trouble with that. I can't seem to get anything to print using python.

For instance I have the X length of the bounding box using a "Separate XYZ" node which is a float. When I enter "bpy.data.node_groups["Modifier"].nodes["Separate XYZ.001"].outputs[0].default_value[1]" I get "'float' object is not subscriptable". When I try to convert it to a string in the text editor using "str()" I just get the same error. When I use the convert float to string node and try to print that the value is empty. I just get " ".

Any thoughts on how I can write the outputs of nodes to text?