r/blenderpython • • May 09 '20

Advice Sought About Automating Tattoo Painting Workflow

1 Upvotes

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 • • Apr 13 '20

Moving a duplicate object

1 Upvotes

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 • • Mar 06 '20

how to delete transform_orientation

1 Upvotes

I crreated a temporary transform orientation:

bpy.ops.transform.create_orientation(name='tmp')

but calling

bpy.ops.transform.delete_orientation()

doesn't work:

File "C:\Program Files\Blender Foundation\Blender 2.82\2.82\scripts\modules\bpy\ops.py", line 199, in call ret = op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)

RuntimeError: Operator bpy.ops.transform.delete_orientation.poll() failed, context is incorrect

How can I delete the new transform_orientation?


r/blenderpython • • Nov 17 '19

Where i can find documentation for bpy_lib?

1 Upvotes

I am new to python&blender coding and i am trying to create prop_search UI which will find object inside another .blend file and will append or link it.

with bpy.data.libraries.load(filepath) as (data_from, data_to):
    print(data_to.__class__)

This code will print bpy_lib and i cant find anything on google about this class.

Btw. what is (data_from, data_to)? It is array/tuple or something like list() in php ? What is difference between _from and _to? Both says bpy_lib.

Also what is difference between first and third parameter in prop_search? Thanks


r/blenderpython • • Oct 02 '19

Python controlled robot

Thumbnail self.blenderhelp
1 Upvotes

r/blenderpython • • Aug 30 '19

I reworked that good ol' System Property Chart' addon -- https://github.com/dustractor/syspropchart2

1 Upvotes

https://github.com/dustractor/syspropchart2

I figured the original author has long since moved on. It does what the old one does, present one or more properties of selected objects, based on a string you input.

The old one: in a grid-like fashion.

This one: I ditched the grid and went with something that fits in narrower space.

The old one: dotted syntax only for attribute access

This one: dotted, keyed, indexed

The old one: Presets

This one: Also Presets (I recommend using double quotes because blender's preset system surrounds the preset string with single quotes.) It should work with either single or double quotes in the interface but the string won't make it through the preset system and back if names used for keyed access use single quotes.

In other words:

this["good"]
this['not so good']

If there are three or more objects then you can interpolate a property across them. Vector/Float/Color only so far (idk why not ints yet i'm busy lol)

So anyways, I figured I would post this here to see if I can get YOU to supply me with some good presets to include. If you have trouble coming up with the string for accessing what you want, describe what you want and I'll try and work through it with you.


r/blenderpython • • Mar 06 '19

Unable to set an active scene

1 Upvotes

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 • • Jan 04 '19

How to change the font size of a text row inside a script via python

Thumbnail
blender.stackexchange.com
1 Upvotes

r/blenderpython • • Sep 29 '18

How do I name a selected group via python script

Thumbnail
blender.stackexchange.com
1 Upvotes

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 • • Dec 13 '17

Addon doesn't throw any errors when installing, but also doesn't install

1 Upvotes

I'm pretty new to Blender's API, but not at all new to Blender or Python on their own or coding in general. I just wrote my first successful Python script in Blender that writes up a .txt file based off of the selected object's geometry. Now I am trying to turn it into an addon and running into some hitches. Based off skimming a few tutorials and weeding through various other working addons I have written the following:

bl_info = {
    "name": "Export: Statics Bridge",
    # * other parts trimmed out to save space on reddit *
    "category": "Import-Export",
}

import bpy

class ExportAsBridge(bpy.types.Operator):
    """Exports statics bridge project code"""
    bl_idname = "ExportAsBridge"
    bl_label = "Export bridge code from selected mesh"

    def execute(self, context):
        write_bridge() # < defined below, that function works fine

def menu_func(self, context):
    self.layout.operator(ExportAsBridge.bl_idname, text="Statics Bridge Code (.txt)")

def register():
    bpy.utils.register_class(ExportAsBridge)
    bpy.types.INFO_MT_file_export.append(menu_func)

def unregister():
    bpy.utils.unregister_class(ExportAsBridge)
    bpy.types.INFO_MT_file_export.remove(menu_func)

The aim is to add an option in the usual file > export menu that runs write_bridge(). But when I try to install the .py file as an addon it gives the message Modules Installed () from '<where my .py file is>\\io_export_bridge.py' into '<my user>\\AppData\\Roaming\\Blender Foundation\\Blender\\2.79\\scripts\\addons', but my addon does not appear in the list of installed addons so I can not enable it.

I am sure it is something simple and stupid but I haven't yet figured out what I am doing wrong. What am I missing?


r/blenderpython • • Oct 31 '17

Adding keyframes to custom (Python) node type

1 Upvotes

I'm working on a custom NodeTree class, with custom Node types (and also a custom NodeSocket class).

I'm running into problems when trying to add keyframes to either properties on the actual Node class itself (just stored as FloatProperty), or to the properties on the input sockets.

The call to (for example) "node.keyframe_insert('myFloatProperty', frame=10)" returns True when I run it from the Python console (and the property itself turns green in the node view), but nothing gets stored in the scene.animation_data object (it's None), and nothing shows up in the F-curve view (if I add a keyframe to a custom property on the default cube object, then this will show up there).

Is there something special that needs to be done to be able to add keyframes to custom NodeTrees?

Thanks


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 • • Jul 02 '17

Syntax issue - using range function to label axis

1 Upvotes

Hi all,

I'm having trouble with a really simple piece of code. I want to use i from my range function in the body of the text object - I'm simply numbering along an axis. I've tried i, (i), and [i] and that doesn't work so, with my limited knowledge, I'm stuck.

Be grateful for any help - code below, it's line 13 where I want to substite fixed text for the i from the range function.

import bpy

for i in range(0,18): # Add text object bpy.ops.object.text_add( location = ( i - .2, -0.5, 0 ) )

text = bpy.context.object
#text.rotation_euler.z = radians(90) # Rotate text by 90 degrees along Z axis
text.data.extrude     = 0.05        # Add depth to the text
text.data.bevel_depth = 0.01        # Add a nice bevel effect to smooth the text's edges
text.data.body        = "i here please!"       # Issue here - I want to set body to i
text.data.size = 0.5

r/blenderpython • • Jun 12 '17

Bezier Curve TILT Value?

1 Upvotes

Hey,

I am currently working on a project invloving rollercoasters in Blender. I have found a way to get my bezier curve positions / locations using the .obj export function. However I also need my Pitch / TILT Export, which I can't be able to find.

I have been browsing the web for around 2 months now, looking for a python script / scripter which might be able to help me. I havent found any available python scripters or scripts.

Reddit will help me pls?


r/blenderpython • • Feb 25 '17

Adding Vertex Color Output To OBJ Exporter

1 Upvotes

Hello,
I'm trying to modify the OBJ exporter to include vertex color in its own set of lines starting with vc. The game engine I'm using doesn't easily import models and I've already written an obj parser, I would prefer to read vertex color data from it rather than have it parse an mtl file or write a parser for another model format.

I'm still incredibly new to python but I was able to modify it to the point that it outputs a color for each vertex. Unfortunately it doesn't output correctly and a lot of the vertex colors are lost. I don't think I'm understanding the process for reading the vertex color values. The modification I made is fairly simple, the addition is below:
Code:

           # Vert Color
           vcol_data = me.vertex_colors.active.data
           for l in me_verts:
               col = vcol_data[l.index].color[:]
               fw('vc %.6f %.6f %.6f\n' % col[:])    
           subprogress2.step()    

I slipped this in between the vertex and normal output blocks within export_obj.py. It's not throwing errors and outputs a file successfully. Would somebody kindly explain where I'm messing this up?


r/blenderpython • • Feb 21 '17

How do I set the image for the Image Texture node?

1 Upvotes

I can add the Image Texture node via python, but how do I set the image file that it uses? When I mouse over the "open" button, it says bpy.ops.image.open(), but I don't think that's the right one to use?


r/blenderpython • • Sep 29 '16

How would I batch import psk files?

1 Upvotes

I'm using a pskx importer in conjunction with umodel. I'm not very good with python. I'm an artist that thinks it might help get stuff done faster. I've got big sums of files that I'd like to import.


r/blenderpython • • Sep 28 '16

How do i add this UI to an addon

1 Upvotes

http://i.imgur.com/kIQG6a3.png

I'm wondering if there is a way to copy this bit of UI. That is, the drop down menu that lists images, and the two buttons [+new] and [open] that call operations to create images, to be used in an add-on's UI.

I can get a list of images with:

layout.prop_search(bpy.context.active_object.active_material, "theChosenImage", bpy.data, "images")

but it dose not look at nice as nice as the default blender UI, and i would like to keep it recognizable to users as an image selection menu.

I've used UILayout.template_list() in my project, which is the closest menu option i could get working, but it dose not drop down, and the search is hidden by default.

Any help you can offer is appreciated.


Edit: It seems i was looking for UILayout.template_ID but didn't understand how it was used until now.

My new question becomes, how would i go about triggering an operation when the property of template_ID changes?


r/blenderpython • • Aug 11 '16

How do I get the z coordinate of a certain point on a face?

1 Upvotes

So I have a big plane that functions as a floor. All the vertices of the floor are at the corner, so in the middle of the floor is only one big face.

I want to place an object on top of the floor at a certain x, y position.

I know that you could normally use the snapping-functionality but I am working with a python script, which doesn't allow me to use that option.

So is it possible to retrieve the z coordinate of a certain point on a face if you have the x and y coordinate?

Thank you.


r/blenderpython • • Jun 25 '16

Fractal (Mandelbrot) in 3d using Blender Python

Thumbnail
slicker.me
1 Upvotes

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 • • Jan 03 '16

Exporting UV Islands in console (v2.72)

1 Upvotes

I understand how to display loop indices, polygons, edges with seams, uvs and various under information regarding meshes from the console, but I want to be able to identify list of polygon indices for all given islands.

Here is an example script I am talking about that I can run from the console:

me = D.objects['Plane'].to_mesh( C.scene, True, 'PREVIEW' )

t0 = me.uv_layers[0].data

for p in me.polygons:

      str = "%5d %5d %5d " % ( p.vertices[0], p.vertices[1], p.vertices[2] )

      str += " %+4.4f,%+4.4f " % ( t0[p.loop_indices[0]].uv.x, t0[p.loop_indices[0]].uv.y )

      str += " %+4.4f,%+4.4f " % ( t0[p.loop_indices[1]].uv.x, t0[p.loop_indices[1]].uv.y )

      str += " %+4.4f,%+4.4f " % ( t0[p.loop_indices[2]].uv.x, t0[p.loop_indices[2]].uv.y )

      print( str )

How can I in a similar fashion gather information for uv islands? I've been digging around the code looking at import/export scripts but I just can't find anything. I'm considering writing my own way of calculating this, but beyond saving a bunch of edges marked as seems, I'm struggling with the algorithm to utilize them to sort triangles by uv islands.


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.