r/blenderpython • u/[deleted] • Sep 29 '19
r/blenderpython • u/rajeshpra241997 • Nov 28 '19
Race Charts using Blender Python
Anyone has idea about Race Bar charts using Blender Python ?
I am very new to blender
r/blenderpython • u/Rclub • Feb 08 '16
error in communicating blender with arduino
I am new to blender and i want to communicate b/w arduino and python.first i wrote the code in Arduino it prints values like this
Serial.print("Val");
Serial.print(AN[0]);
Serial.print(",");
Serial.print(AN[1]);
Serial.print(",");
Serial.print(AN[2]);
Serial.println(); and it is working fine.. after that i went to blender and opened text editor and wrote python code as below import serial import bpy ser = serial.Serial(port='COM15',baudrate=9600, timeout=100)
accel=[None]*3
while 1:
line = ser.readline()
print(line)
ser.close after that i pressed atl+P but i am getting error like bpy.ops.text.run_script() Python script fail, look in the console for now... (my python code indentation is correct only) if i execute the same code(except import bpy) in the externall python it is working fine what might be the problem?
r/blenderpython • u/Decim00 • Jul 29 '24
Get list of objects in camera view
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 • u/3Dmaven • Jul 25 '24
[HELP] Script to add control handles to bendy bones, need help figuring out 1 weird bug!
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:
creates control bones at each end
reparents the original bone to the "start" bone
aligns the Roll of these new bones to the original
creates a Stretch To constraint to the "end" bone
changes the bendy bone's start and end handle attributes to "Tangent"
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 • u/leomartinch • Aug 17 '24
Edit Bones in Pose Mode without having to enter Pose Mode
Hello. I am working on a script that includes rotating and moving bones in Pose Mode. I would like to see these rotations in real time (i change the rotation on each frame) but having to always change from object to pose mode is slowing everything down.
I would also like to edit multiple different armatures per frame and my current script doesn't seem very scalable.
Is there a way to edit the rotation of the bones in Pose Mode without entering pose mode. Thanks
r/blenderpython • u/keggerz1 • Feb 05 '21
Is there a way to automatically orient a mesh to it's principle axes?
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 • u/LightArchitectLabs • Dec 29 '20
How to add Boid brain settings to a particle system via python script? Question.
r/blenderpython • u/Fizzzle42 • Jan 05 '21
XYZ Coordinates to Mesh
Hi there!
I am absolute new to python but managed to get this badboy running:
(But sadly not as expected and now i am searching for help.)
import bpy
import csv, os, bmesh, math
#filepaths
filepath = bpy.data.filepath
directory = os.path.dirname(filepath)
verts = []
edges = []
faces = []
csvpoints= "C:\\test.csv"
pointsReader = csv.reader(open(csvpoints, newline=''), delimiter=';')
with open(csvpoints, 'rt', encoding="utf8") as csvfile:
pointsReader = csv.reader(csvfile, delimiter=';')
for idx, row in enumerate(pointsReader):
if (idx > 0):
vert = (float(row[0]), float(row[1]), float(row[2]))
verts.append(vert)
obj = bpy.context.object
#create mesh and object
mesh = bpy.data.meshes.new("wave")
object = bpy.data.objects.new("wave",mesh)
#create mesh from python data
mesh.from_pydata(verts,[],[])
mesh.update(calc_edges=True)
#set mesh location
bpy.context.scene.cursor.location = [0,0,0]
object.location = bpy.context.scene.cursor.location
bpy.data.collections["Collection"].objects.link(object)This code runs without an error and i also get a new mesh in my >Scene Collection<, but it seemes that there are no Vertexes created in my mesh.
The coordinates i try to load look like this: (1,25 Mio lines)
521250.500;163999.501;440.6
521250.500;163998.501;440.6
521250.500;163997.501;440.6
521250.500;163996.501;440.5If there is another (maybe simpler way) to load this Data into Blender and get a 3D File let me please know ;)
Thank you very much for reading!
r/blenderpython • u/deaf_fish • Jan 08 '21
Isometric Camera Setup
I made an Operator (I think) to automatically setup and align a camera for pixel perfect Isometric stuff.
https://github.com/hansonry/blender-isometric-scripts/blob/master/BlenderIsoCameraUpdate.py
It works best if your image width = 2 * image height - 2 and image height is even.
You can set your background to transparent and your Rendering Samples to 1 to really see it. If you want to maintain your high sampling count you can generate a mask for a clean cut.
I have no idea what I am doing when it comes to scripting for blender, but if you know and you could sanity check my integration, I would appreciate that. Also I am trying to figure out how to enforce that image width = 2 * image height - 2 and that the image height is even. Any hints there would be helpful.
Thanks
r/blenderpython • u/Ragingrahul17 • Jan 22 '21
Python code on dividing a mesh into smaller meshes consisting of a particular number of tris.
Can anybody help me with writing a code for a taking a pre existing mesh with suppose 1000 tris. Then breaking down the bigger mesh into smaller meshes which consist of maybe 10 tris. So at the end for the above case there will be 100 different mesh each consisting of 10 tris.
r/blenderpython • u/rmarbertin • Apr 19 '20
A step towards 3d L1 voronoi
Seems missing from the internets, 3d taxi/manhattan voronoi. So, here's a step in that direction, a function to create a mesh to be intersected with other HalfCubes until a cell is completed (all verts are equal-L1-distant to c1 as c2)
def HalfCube(c1,c2,S):
d = c1-c2
cc = (c2-c1)/2
bm = bmesh.new()
bmesh.ops.create_cube(bm, size=1)
bmesh.ops.scale(bm, vec=[abs(n) for n in d], verts=bm.verts[:])
bmesh.ops.translate(bm,vec=cc,verts=bm.verts[:])
# corner of box at (0,0,0) is c1
geom = bm.verts[:] + bm.edges[:] + bm.faces[:]
bmesh.ops.bisect_plane(bm, geom=geom,
plane_co=cc, plane_no=[sgn(n) for n in d],
use_snap_center=False,clear_inner=True)
c12 = [(0,0,0),(c2-c1)]
for vert in bm.verts:
x,y,z = vert.co
p = [x,y,z]
for c in c12:
for i in [0,1,2]:
if abs( p[i]-c[i] ) < epsilon:
p[i] = c[i]
vert.co = p
SSS = mathutils.Vector((S,S,S))
pMin = cc-SSS
pMax = cc+SSS
b1 = [(pMin[i] if c1[i]<c2[i] else pMax[i]) for i in [0,1,2]]
b2 = [(pMin[i] if c1[i]>c2[i] else pMax[i]) for i in [0,1,2]]
b12 = b1,b2
for j in [0,1]:
c = c12[j]
b = b12[j]
for i in [0,1,2]:
cn = c[i]
bn = b[i]
geom = set()
pci = None
for f in bm.faces:
p = f.calc_center_median()
pn = p[i]
if abs(pn-cn) < epsilon:
geom.add(f)
for v in f.verts: geom.add(v)
for e in f.edges: geom.add(e)
d = [0,0,0]
d[i] = b[i]-c[i]
ret = bmesh.ops.extrude_face_region(bm, geom=list(geom))
va = [v for v in ret['geom'] if type(v) is bmesh.types.BMVert]
bmesh.ops.translate(bm,vec=d,verts=va)
bound_edges = [e for e in bm.edges if e.is_boundary]
bmesh.ops.edgeloop_fill(bm, edges=bound_edges)
me = bpy.data.meshes.new('mesh');bm.to_mesh(me);bm.free()
obj = bpy.data.objects.new('halfCube', me)
bpy.context.collection.objects.link(obj)
obj.location = c1
return objI'm still working on the full voronoi generator, but crazy times we live in, who knows what tomorrow holds, so I'll just leave this here. The world needs 3d printed voronoi crap in non-euclidean metrics, too!
r/blenderpython • u/docclox • May 09 '20
Advice Sought About Automating Tattoo Painting Workflow
I have a pile of tattoo overlays for a 3D body mesh, and I need to replicate them for a different body.
The workflow is straight-forward in Blender: I load a save with the model already positioned and a brush with the correct position and transformation. Then I load the background texture and the image I want to paint, paint it, and save the texture as a copy. Lather, rinse, repeat.
It's straightforward, but it's tedious and prone to human error on my part, and I can't help thinking that a blender script should be able to do most, if not all of that. So I'm thinking about having a script with a big list of brush files and loping over them and painting the lot in one session.
Does that sound feasible? I'm not a Blender expert, but I speak fluent python, and if the APIs exist for what I want to do, I'm confident I can make it work. I just want a sanity check before I dive in, and if anyone wants to volunteer a couple of pointers, that would be great.
Also, can I change the viewport programatically? I have some tats that need to go front and back, and if I could do both in one go, that would save time as well.
r/blenderpython • u/samuel1212703 • Apr 13 '20
Moving a duplicate object
I've made a conveyor belt scene where a cardboard box needs to be placed at a point in the start of the conveyor belt. I've made a cardboard box object and it needs to be duplicated every so and so seconds. I've searched around for a while with no luck of making it work.
def duplicateObj():
print("duplicate")
#I want to somehow set a location where this object is duplicated to
bpy.ops.object.duplicate()I want to somehow set a location where the duplicated object is duplicated to. I have the code running every 5 seconds with this:
t = Timer(5.0, duplicateObj)
t.start()How do i correctly duplicate the object at a certain location?
r/blenderpython • u/dgm1g15 • Apr 14 '20
Live visualisation of Coronavirus cases - in Blender! Just uses a script to download data and the pandas library to manipulate it
thumbs.gfycat.comr/blenderpython • u/[deleted] • May 14 '20
Activate Gizmo without clicking an axis?
I can't seem to find a way to do this.
r/blenderpython • u/[deleted] • May 02 '20
Creating animations / curves from simulations in python.
Most things for now I have seen regarding python with Blender is connected to Artists trying to automatize repetitive workflow. I'm interested in doing simulations with python and then python to create curves / animations from this simulation data.
As a first project I had a simple pendulum in mind.
If somebody could point me into the right direction it would be wonderful.
r/blenderpython • u/[deleted] • Oct 09 '14
Blender Game Engine player movement in Python
r/blenderpython • u/antirabbit • Jul 18 '17
Why is mesh.from_pydata() resulting in segmentation faults?
I am trying to randomly generate meshes with slight modifications computed before the objects are created. Below is some code that creates the mesh, but right now it crashes unless the number of vertices is small.
I have vertex and face data loaded from a cube that was subdivided many times, with a total of 26138 vertices and slightly fewer faces.
I am loading the object in a script, and whenever I try to load it with mesh.from_pydata, I get a segmentation fault (core dumped) error.
mymesh = bpy.data.meshes.new(mesh_name)
myobject = bpy.data.objects.new(mesh_name, mymesh)
bpy.context.scene.objects.link(myobject)
print('loading from pydata...')
mymesh.from_pydata(vertices,[],faces)vertices is either a numpy array or a list object. I've tried both, and the segmentation fault occurs in both. faces is a standard list of tuples corresponding to vertex indices.
Here is the log from /tmp/blender.crash.txt
Blender 2.78 (sub 0), Commit date: 2017-02-24 14:33, Hash e92f2352830
bpy.context.space_data.bookmarks_active = 0 # Property
backtrace
./blender(BLI_system_backtrace+0x1d) [0x19aad1d] ./blender() [0x104e2e6] /lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7f720bccf4b0] ./blender() [0x19abc88] ./blender() [0x19ab12d] /lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba) [0x7f720d2df6ba] /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7f720bda13dd]
r/blenderpython • u/Xtynger • Nov 30 '17
new to python but with one target in mind from now: Creating a bot to do my Job :D
to all of you guys that are more than experts at Python, could it be possible to build a code to "read-write", in my job I have to fill LOTS of information about people, im a touristic guide, I want the bot to fill every field bassed on my whatsapp lists, I know it can be done but FOR NOW i dont have idea of how, to recognize the field "name" then recognize the first name on my list, and put it on the list, and so on, name, surname, age, country, gender, email, booking number, and such... it takes hell of 2-3 hours of my precious time (after my 9-12 hours of work) every single day, so I trully need to improve that.
r/blenderpython • u/georgevdd_ • Feb 09 '17
Easy Blender script debugging with Eclipse!
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 • u/[deleted] • Mar 06 '19
Unable to set an active scene
Hi! I'm working on Blender 2.79
Essentially I'm unable to set an active scene for my Blender script. I'm importing STLs into a context, then attempting to run some functions on it, but I keep getting 'incorrect context' errors. Reading a scene from a file isn't an option; is there a way to make a new scene, set it active, then import meshes into it for the script to work?
r/blenderpython • u/laxlover1753 • Feb 18 '20
Is there a way to access the python scripts in a blender file in a python script to save them?
I’m trying to write a script to save all my scripts but I can’t figure out if it’s possible to even access that with the blender api. Does anyone know if this is possible?
r/blenderpython • u/TrendingB0T • Oct 11 '19