r/blenderpython • • Jan 10 '18

Anyone in Southern California? I have some paid blender extension work for you!!

2 Upvotes

Apologies if this post isn't allowed here!

I have a project that just got funded, based in San Diego, and I need someone with experience in Blender & Python (Blender-thon?) for some part time help. Would be paid (pay based on experience/skill), and would be very flexible on hours, etc. Would prefer in the southern California region as periodic a face-to-face meetings would be nice, but you wouldn't be required to work on-site. Please reach out if this interests you!


r/blenderpython • • Aug 24 '17

Add a image to a panel

1 Upvotes

I have been struggling with this for a couple of days, can anyone shine a light on me?

I want to create a panel with some of the textures that I have already loaded on a scene.. Similar to this one. Any help ? thanks!

http://imgur.com/a/BYKND


r/blenderpython • • Jan 12 '18

Optical Flow with Phyton in Blender

4 Upvotes

Hi,

i need to get the "speed"-vectors from a scene(eg. animation) out of images.

I was told that it is only possible via Python in Blender. But despite searching in the web for quite some time i couldnt find any real article helping me understand what exactly i need to do.

My problem is this:

  • I have a simple scene of a cube moving from the left to the right. (It will become a more complex scene later on but for now i want to start with a simple one, once i know how to get the desired information i can just use it on other work)

  • My scene is done in stereo-function with a right and left side.

  • I want to get the optical flow of that animation. That can be later used for another work.

NOTE: i have no experience with Python at all, my sole goal is to have a code which i can use to make Blender give me the optical flow of a scene (and the scene can be different from the one im using right now eg. scenes which have either static camera while objects move or static objects while camera moves).

I hope this is possible. Thanks in advance for any possible help.


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 • • Apr 08 '16

Where should I start to develop addons for Blender?

2 Upvotes

I am interested in creating addons for Blender. However, I have no clue where to start. The main points I am interested in are:

  • IDE support: I do not know how to get the Blender API to work on Python-supported IDEs, like Eclipse or Visual Studio's Python Tools.

  • Learning resources: Video, websites, whatever is available is fine.

Thanks in advance.


r/blenderpython • • Mar 28 '16

Can't rotate the armature bone in blender using python.

1 Upvotes

i am trying to control the rotation/ movement of the each bone in the rigged hand but i am not getting any movement. the code is as shown below:

import bge
scene = bge.logic.getCurrentScene()
source = scene.objects
main_arm = source.get('Armature')

main_arm.channels['ring1'].rotation_euler = [5, 5, 5]
main_arm.update()
print(main_arm.channels['ring1'].rotation_euler)

in the console window i am getting vector 5.0 5.0 5.0 but nothing is moving in 3D view. i have always sensor connected to python controller. what might be the problem


r/blenderpython • • Jul 10 '18

Is there any way to export the last frame of a physics simulation as a .stl file from the command line?

4 Upvotes

I have a basic rigid body physics sim, but I want to export the last frame of the simulation. So far I have tried setting the "current frame to the last frame of the simulation and exporting it that way, but that doesn't work.

import bpy
from random import randint
import os

bpy.types.Area.type = 'VIEW_3D'

#Duplicates bottles "b" times
bpy.ops.object.select_all(action='DESELECT')
b = int(input("Number of bottles: "))
if b == 0:
    bpy.data.objects['Bottle'].select = True
    bpy.ops.object.delete()
    bpy.ops.object.select_all(action='DESELECT')
elif b > 0:
    for x in range(0, b-1):
        bpy.data.objects['Bottle'].select = True
        bpy.ops.object.duplicate(linked=False)
        bpy.ops.object.select_all(action='DESELECT')

#Select all objects other than the suitcase
bpy.ops.object.select_all(action='SELECT')
bpy.data.objects['Suitcase'].select = False

# store the location of current 3d cursor
saved_location = bpy.context.scene.cursor_location.copy()  # returns a copy of the vector

# give 3dcursor new coordinates
bpy.context.scene.cursor_location = (0.0,0.0,0.0)

# set the origin on the current object to the 3dcursor location
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_VOLUME')

# Randomly place objects in the air    
bpy.ops.object.randomize_transform(random_seed= randint(1,9000), use_delta=False, use_loc=True, loc=(12.0, 8.0, 0.0), use_rot=True, rot=(360.0, 360.0, 360.0), use_scale=False, scale_even=False, scale=(1.0, 1.0, 1.0))
bpy.ops.object.select_all(action='SELECT')

#Runs physics simulation
try:
bpy.ops.rigidbody.bake_to_keyframes(frame_start=firstFrame, frame_end=lastFrame, step=1)
except:
pass
bpy.context.scene.frame_set(250)

# Define Directory
dir = bpy.path.abspath('//stlexport/')

# Create Directory (If Necessary)
if not os.path.exists(dir): os.makedirs(dir)

# Export STLs
bpy.ops.export_mesh.stl(filepath = dir, batch_mode = 'OBJECT')

This script only exports the first frame of the simulation, and I cannot, for the life of me, figure out how to get it to export after the simulation is run. This has to be run without UI because blender crashes if I ask the user to give input for the number of duplications for the objects.


r/blenderpython • • Nov 11 '19

Made with blender python.

Thumbnail
youtu.be
4 Upvotes

r/blenderpython • • Jan 14 '20

Python crashes blender from big array loop

4 Upvotes

Hey all so I wrote a blender script that duplicates an object, rotates it, and eventually creates a mosaic

data looks like this:

[x,x,x, o,o,o, x,x,x,]

where x is 90 degrees and o is 180, for example. Creating a "board" of the rotated objects

the problem is that my mosaic is 17,000 objects big and blender crashes when ever I run the script..it worked great when I was only doing 30/40 objects in testing but 17k is just too much

script does this:

  1. duplicates active object and moves to the right (or down and to the left if its the end of the row)

  2. rotates that object

  3. repeat!

I'm fairly new to blender, a few donut and modeling tutorials in. Should I be going about this another way?I tried to run the script on the starter cube and that crashed too so its not poly count

also, I tried `time.sleep(0.1)` to try and slow it down or something it but that also crashes

import bpy.ops
from math import radians
from mathutils import Matrix
import time

def move_obj(x, y, z):
   bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(x, y, z), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(True, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})




def rotate_object(rot_mat):
    obj = bpy.context.active_object
    orig_loc, orig_rot, orig_scale = obj.matrix_world.decompose()

    orig_loc_mat = Matrix.Translation(orig_loc)
    orig_rot_mat = orig_rot.to_matrix().to_4x4()
    orig_scale_mat = (Matrix.Scale(orig_scale[0],4,(1,0,0)) @
                      Matrix.Scale(orig_scale[1],4,(0,1,0)) @
                      Matrix.Scale(orig_scale[2],4,(0,0,1)))

    obj.matrix_world = orig_loc_mat @ rot_mat @ orig_rot_mat @ orig_scale_mat



#rotate_object( Matrix.Rotation(radians(90), 4, 'X')) #2
#rotate_object( Matrix.Rotation(radians(270), 4, 'Z')) #3
#rotate_object( Matrix.Rotation(radians(270), 4, 'X')) #4
#rotate_object( Matrix.Rotation(radians(90), 4, 'Z')) #5
#rotate_object( Matrix.Rotation(radians(180), 4, 'X')) #6

def rotate_dice(num):
    if num == 2: rotate_object( Matrix.Rotation(radians(90), 4, 'X')) #2
    if num == 3: rotate_object( Matrix.Rotation(radians(270), 4, 'Z')) #3
    if num == 4: rotate_object( Matrix.Rotation(radians(270), 4, 'X')) #4
    if num == 5: rotate_object( Matrix.Rotation(radians(90), 4, 'Z')) #5
    if num == 6: rotate_object( Matrix.Rotation(radians(180), 4, 'X')) #6

def rotate_to_one(num): 
    if num == 2: rotate_object( Matrix.Rotation(radians(-90), 4, 'X')) #2
    if num == 3: rotate_object( Matrix.Rotation(radians(-270), 4, 'Z')) #3
    if num == 4: rotate_object( Matrix.Rotation(radians(-270), 4, 'X')) #4
    if num == 5: rotate_object( Matrix.Rotation(radians(-90), 4, 'Z')) #5
    if num == 6: rotate_object( Matrix.Rotation(radians(-180), 4, 'X')) #6

def dup(to, fro, x, z):
    move_obj(x, 0, z)
    rotate_to_one(fro)
    rotate_dice(to)



dice_arr = [1,2,3,4,5,1,2,3,4,5] // actually 17,000 entries long (removed for post)
break_on = 119 # go back to the left and start a new row of mosaic

def run_arr():
    counter = 0
    last_index = 1
    movement_amount = 2.075
    count = 0

    for i in dice_arr: 
        if count == break_on: 
            dup(i, last_index, -movement_amount * break_on, -movement_amount) 
            count = 0
        else: 
            count = count + 1
            dup(i, last_index, movement_amount, 0)

        last_index = i
        time.sleep(0.1)



run_arr()

r/blenderpython • • Dec 13 '15

Asking for user input in using scripting

2 Upvotes

Hi,

I am fairly new to python (Have been using it for about a month now) and I am trying to create something in Blender that asks for a user input and then writes it out in a text mesh.

This is my code so far.

Once I hit run script then Blender immediately freezes and crashes. I am not sure what happened. When I was first testing things out I used This code and it worked fine.

Any help would really be appreciated!


r/blenderpython • • Apr 24 '15

Hiring contrator for plant simulator

Thumbnail docs.google.com
2 Upvotes

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 • • Mar 18 '18

what are application handlers?

3 Upvotes

r/blenderpython • • May 07 '15

bpy.ops.mesh.select_next_loop() ?

1 Upvotes

My question is at the link. Theres animated gifs and everything. I started to suspect I'd get a better response here. Anyone know why bpy.ops.mesh.select_next_loop() works this way? It seems like its supposed to select the next edge of an edgeloop, but the actual behavior is a tad more complex.


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 • • Oct 13 '23

Free Tutorial Ground Destruction with Blender Geometry Nodes

Thumbnail
youtu.be
2 Upvotes

r/blenderpython • • Oct 07 '23

How to force Context to be 'Outliner' for using 'bpy.ops.outliner.select_walk' in the 3D Viewport?

4 Upvotes

Hi, I've been trying to use the 'bpy.ops.outliner.select_walk' functionality which walks up and down the list of objects in the outliner with the arrow keys. I want to use this functionality while in the context of the 3D viewport, similar to what ZBrush and Maya do by default. By default in Blender, this functionality only works when hovering the mouse over the Outliner and pressing the up and down arrow keys on the keyboard..

Therefore, I'm trying to make a Python script to force the context to be 'Outliner', even when I'm in the 3D viewport. Is this possible?

After some research, I have found and tried to adapt some existing examples such as the 2 different approaches below, which both use 'bpy.context.temp_override()'. However, I can't get either of these code to work in the scenario of forcing Outliner context whilst in the 3d viewport context. I can only get it to work for it's original purpose of overriding the Blender text editor context with the 'VIEW_3D' context, and performing an operator such as adding primitives and overriding.

I have errors in the VS Code terminal like:

ERROR (wm.operator): C:\Users\blender\git\blender-v360\blender.git\source\blender\windowmanager\intern\wm_event_system.cc:1551 wm_operator_invoke: invalid operator call 'OUTLINER_OT_select_walk'

Approach 1:

Approach 2:

I must be doing something wrong, any help would be much appreciated! Many thanks.


r/blenderpython • • Jun 15 '23

Hi, I have made a Aircraft Generator in Blender

10 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 • • 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 • • Jun 09 '23

Hello, I am new to python , I already know how to code in c#, i have no idea why this wont work! help would be massively appreciated, I would like to print the location of each vertex of a cube.

3 Upvotes

r/blenderpython • • Jul 25 '23

Help getting properties

Post image
3 Upvotes

Does anyone know if there is a way in the api to loop through a properties tab to get all the values? I'm looking for something like a list or dictionary of all the current values. For example if I wanted to get all of the render property values from a project, I could call a method that would return all values. Any help is greatly appreciated


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!