r/blenderpython • • Oct 27 '23

Blender App Template Examples | hello world | music visualizer | grapher

2 Upvotes

Hello friends! I have a few blender app templates to show off, I think the app template feature is pretty cool and has a lot of dope uses, I have a few of samples if anyone is interested in the types of things it can do, and also a couple questions is anyone knows.

These are not polished, bug-free apps but are samples that show how to setup a dev environment and get going with these.

This template turns blender into a music player with a sound synchronized visualizer made w geo nodes: https://github.com/b-rad-c/bl-music-player

This is a stripped down hello world example: https://github.com/b-rad-c/bl-hello-donut

This is a basic app for graphing data: https://github.com/b-rad-c/bl-app-grapher

Again they don't have tons of features but are enough to see what is possible w app templates.
Two questions I have:

  1. I'm looking to get a completely blank window so I can start from scratch, if you look at the bl-app-grapher, I'm using the property area to get user input, I'd like to get rid of the pin button and the icon, but I couldn't figure out how. Not sure if it's possible to create an area from scratch or to remove these two items.

  2. Best practices for including pip dependencies? The bl-app-grapher relies on matplotlib, everything works when I run the app from source but when I package it into a zip to distribute I realized the dependencies weren't getting copied in. I tried running pip with the --target flag to install the dips into the folder that I ended up zipping but that didn't work. Not sure if there is a better method, should I call pip dynamically during the app install process?

Thanks! Hope you enjoy the app templates!


r/blenderpython • • Oct 13 '23

Free Tutorial Ground Destruction with Blender Geometry Nodes

Thumbnail
youtu.be
2 Upvotes

r/blenderpython • • Sep 18 '23

Automatic Python atlas baking gives wrong Occlusion Roughness Metallic (Blender 3.3.1 LTS)

2 Upvotes

Hi everyone!

I've been developing a tool to automatically bake texture atlases and export GLB objects. However, I've come accross a pretty strange event: the output Occlusion Roughness Metallic (ORM) atlas looks way too bright. After digging a bit deeper, I realized it was particularly the roughness that was too bright (the only difference I see in my script is thatthe roughness is baked in "Roughness" mode, whereas metallic and ambient occlusion (AO) are baked in Emit mode). What is even stranger is that I don't have this problem when baking manually.

While digging even deeper, I found out that if I apply a gamma correction of 2.2 on the ORM, it gives it the appearance it should have. So my temporary solution could be to call Pillow and add a gamma correction to the output ORM, but I would very much like to understand why my script causes that in the first place.

So that's why I decided to turn to the community's wisdom :) If anyone can help me figure out what the heck is happening, I'd be most grateful.

Just a few more info on what I tried:
- I tried fiddling with the colorspaces, I'm on "Standard" rather than Filmic, I tried turning on the 'None' option on Display Device, and the original ORM texture to be baked is in Non color mode...

- I'm using the save_render function, I'm wondering whether the problem doesn't come from there, but when trying to use 'Image.save', the filepath argument I put in is not recognized...

Thank you very much for your help :)


r/blenderpython • • Sep 02 '23

Pass list of Objects to Operator

2 Upvotes

I often deal with large CAD imports.
Now I'm working on an add-on that links all of the objects based on their names.

So, based on a selection of objects, I'm filtering through them and construct a dict in the form of:

dict = {
    '3323-310-0094_Bolt_M12_A4': [<object_00>, <object_01>, ... , <object_67>],
    '3323-310-0103_Nut_M12_A4': [<object_512>, <object_513>, ... , <object_874>],
    ....
    }

In order to build the UI, shown in the image, I iterate through the keys of the dict.

Now, I what to call two different operators and pass the list of objects to them.
The fist should just select all of the corresponding objects in the view-port and the other should link the object data.

I really struggle to find a solution to pass the list to the operators.
I've seen suggestions of using the bpy.props.IntProperty() class or similar solutions. But they all define a global variable. So in my example below, they would all just contain the last element of the dict.

I'd be grateful for any hints or suggestions!

Also, any idea how I can create a thumbnail image of an object on the fly?


r/blenderpython • • Jun 25 '23

Help with a Street-Generator Addon

2 Upvotes

I am trying to create an Addon for a Street Generator and want to add Objects along a Bezier-Curve using the Array Modifier. It worked well so far except that the Objects seem to get the angle around the y-axis depending on the angle of the z-angle as in the image. The trees are instances(faces) of planes that have the array- and a curve-modifier set on the bezier curve. The planes itself are in the correct orientation. Does anyone know if this is a problem I can fix by code? As I don't give any rotation for the instanced trees and don't know how to change it or why it changes at all?!
I'm still new to the Blender Python API and am happy for any help :)


r/blenderpython • • May 01 '23

Blender Tutorial - Procedural Modeling Masterclass Space Station Generator

Thumbnail
youtube.com
2 Upvotes

r/blenderpython • • Feb 28 '23

Is it possible to use another program as a trigger to execute a blender python script

2 Upvotes

Hi there, I am learning python and I am trying to figure how could I use the API from a program like rhinoceros to execute a blender python script

https://devtalk.blender.org/t/how-to-run-a-script-from-outside-blender-script-live-link-addon/9792/8

A user named “kaio” found a way to use notepad to write text on blender text editor in real time and shared his code. But I don’t have the knowledge to fully comprehend it.

Thanks for your attention!


r/blenderpython • • Nov 15 '21

Weird Blender Renders!!

2 Upvotes

Hi! I have been having some troubles with the. rendering of Archinterior 58 scenes by evermotion on blender. I'm getting some weird distortion and I'm not sure exactly why. I'm new to blender so if any could guide me through this then it would be really helpful.


r/blenderpython • • Oct 31 '21

Blender Assignment Help

2 Upvotes

Hi! I am in a computer science class but I am not very familiar or good at coding. I have an assignment that includes classes, and I was wondering if anyone could give me any pointers. The first 7 pictures are what was provided to me with the assignment, and the last two are what I have done so far. Thank you!

For this project, you need to modify the code of "Computer Set" by changing it into a "class" fashion instead of the function based style.  So you can create a class called "ComputerSet" as below:

class ComputerSet:

...

  1. Constructor (25%)

For the ComputerSet class, you need to define the corresponding constructor, similar to that in "Desk" class, with the default input argument of "pos" and "scale". Of course, feel free to add additional input arguments for the constructor as needed. Then you need to create the corresponding "data members" inside the constructor function. 

2. def draw(self) function (25%)

In a similar style, you need to create a "draw(self)" function to draw the computer set into the space. The draw(self) function should call three functions inside: (1) drawBox(self)  (2) drawKeyboard(self) (3) drawDisplay(self). This is similar to the style of drawTop(self) and drawLegs(self) in draw() function of the Desk class.

3. Successfully Run the code without errors (20%)

4. Demo of Result (30%)

Provide a ".pdf" file or word document ".docx" with images of the rendered results of 3D scene.

(1) Find a set of good input values for the "pos" and "scale" parameters for both constructors of the "Desk" and "ComputerSet" classes to draw the computer and desk in the same scene with appropriate ratio of their sizes.

(2) Set different colors for the computers and desks to make them have a better look.

(3) Write down a simple summary about your coding results, e.g. "they are all successfully implemented" or 

talk about which part is not achieved well.


r/blenderpython • • Sep 24 '21

Extra keys in Blender (Custom functions)

Thumbnail
youtube.com
2 Upvotes

r/blenderpython • • May 22 '21

How do I run a python script inside Blender from inside my terminal

2 Upvotes

These are my paths:

Blender is installed on C:\Program Files\Blender Foundation\Blender 2.92

My scripts are saved in C:\Blender\scripts

Yes, I know that I can simply run the scripts from inside the Blender GUI but I want to use Sublime Text as my editor.


r/blenderpython • • Feb 05 '21

Is there a way to automatically orient a mesh to it's principle axes?

2 Upvotes

I am trying to orient a number of 3d stone spear heads and I would like to automatically orient them such that they're facing the same way (i.e spear point always pointing in positive x axis or similar). Is there a way to automatically do this such that the mesh's principle axes (ranked in terms of length) are aligned?

Thanks in advance.


r/blenderpython • • Nov 28 '20

Bmesh - applying scale

2 Upvotes

Hello, hoping I can get some help with bmesh ops in Python. After changing the dimensions of a bmesh I see that the inset behaves unevenly around the edges; in the same way that you can fix in the 3d view by applying scale. Is there a way to apply scale after resizing a bmesh in python?

Thank you in advance.


r/blenderpython • • Nov 19 '20

How do I connect two vertices in python

2 Upvotes

I have randomly generated objects that I want to connect like a spiderweb. I have the coordinates of the vertices I want connected. Is there a simple way to create a line(edge?) between the two points.

I am new to blender and every solution I have found has been a manual way of connecting points.

Thanks


r/blenderpython • • Oct 19 '20

Does anyone know of a way to directly interact with the output frames when rendering to MP4?

2 Upvotes

I have been trying to find a plug-in or script for datamoshing for quite a while now, but can't seem to find one.

The only other option I can think of is to write my own because I don't want to do it manually.

The things that I would need to do is force a certain frame to be an i-frame and an arbitrary number of following frames to be p frames when rendering.

I doubt that there is a way to do this with the built-in python, but I figured I'd ask and see if any of you wizards out there know of a way to do it.

If any of you guys know of a way to do it, or better yet a plugin/add-on that is already written, I would love to hear your thoughts!


r/blenderpython • • Oct 07 '20

Need help on adding premade cloth objects to character models with Python

2 Upvotes

Hello fellow developers, I am fairly new to blender python and am trying to make an application which would allow people to drag and drop cloth objects to modify a character, from the tutorials I saw for blender, we need to shrinkwrap the cloth object to fit the character and I didn't seem to find a way to automate the whole process in python. Is there any other way to do this? Or am I missing out on something?

Thanks in Advance.


r/blenderpython • • Sep 28 '20

help with filter system for add on

2 Upvotes

r/blenderpython • • May 24 '20

Question about for loops in blender python

2 Upvotes

Is there a difference in how blender handles for loops when compared to python elsewhere? I would assume not since blender must be imported, but I can't seem to figure out why this loop isn't working.

The code:

for x in range(int(start), int(end+1)):
    #do stuff for all integers 'x' between start and end (inclusive)

The error:

TypeError: 'int' object is not callable

I'm sure I'm missing something stupid, but any help would be much appreciated!

Note: 'start' and 'stop' are enforced as a numeric data type earlier in the code.

Edit: I'm a moron. I named a variable 'range' earlier in the code. Don't code at 3am kids.


r/blenderpython • • Mar 27 '20

Enabling vertex color and texture in viewport through python

2 Upvotes

Is there a way of activating both vertex color and texture display modes via python?

Blender naturally exhibits vertex color and texture together when Vertex Paint mode is active.

I want to write a vertex color addon usable while in Edit Mode.


r/blenderpython • • Mar 26 '20

How do I get the current object transform in a modal operator while the object is moved?

2 Upvotes

For my modal operator, I need the current location, rotation and scale of an object. To have it display values and to see how values change when the object is moved, I need the current transform of the object while being grabbed.

Problem is, while I have an object grabbed (G) and move it around, I can see the values change in the UI, however, when I access e.g. the location from script, it stays the same until I place it and grab it again. Translating it with the sliders yield the same result.

I tried updating the view layer beforehand, but that did not change anything either. I had a look at the delta transform, but this isn't the right thing.

So, where are those values stored and how can I access them? They have to be somewhere, else, one wouldn't see them change in the UI and the object wouldn't move in the view.

I am using Blender 2.82a on Ubuntu 18.04.


r/blenderpython • • Sep 01 '19

Setting vertices’ median location

2 Upvotes

New blender/python user here.

As the subject line says, I’d like to set the median location of selected components through code. I can already do this from the ui from the ‘item’ tab on the right but my goal is to have a way to zero-out vertices on ‘z’ , for example, while maintaining their relative offset, using a hotkey or pie menu.


r/blenderpython • • Aug 02 '19

attaching events to buttons via blender api

2 Upvotes

How do I attach callback functions to buttons? I created button using this code:

    class RigLayers(bpy.types.Panel):
        bl_idname = 'POSE_PT_RigLayers'
        bl_label = "Rig Layers"
        bl_space_type = "VIEW_3D"
        bl_region_type = "UI"
        bl_context = "posemode"
        bl_category = CUSTOM_CATEGORY
        
        bone_groups ={
                    
                    'Root bone': 0,
                    'FK bones': 1,
                    'IK bones': 2,
                    'Facial bones':3,
                    'Manual spine':14
        }
        
        control_layers = [0,1,2,3,14]
        total_layers = 20  
    def draw(self, context):
            column = self.layout.column() #items are placed under each other in a column
            
            column.prop(context.scene, "switch_mode")
            contexts = []
            if context.scene.switch_mode==False:
                for item in self.bone_groups.keys():
    
                    column.prop(context.active_object.data, 'layers',
                     index=self.bone_groups[item],
                     toggle=True, text=item, 
                     emboss=True)  

now there are basically 5 buttons created inside the for loop. But, I'd want to associate each button with a specific callback in addition to it's behaviour of toggling the bone layers. Any help would really be appreciated.


r/blenderpython • • May 02 '19

1 Need help with creating a custom material node with python

2 Upvotes

I'm trying to make a custom node in python, and I've been able to make the input and output sockets, but I have no idea how to connect the input float values to the output float values. I've already tried learning parts of the Blender API in order to figure out how to do this, but I've made no progress. How do I connect the inputs to the outputs, or even set an output value at all?


r/blenderpython • • Jan 02 '19

How to keyframe smoke flow particle size via python script

Thumbnail
blender.stackexchange.com
2 Upvotes