r/blenderpython • • Oct 29 '23

Interjecting a python script within the "render" path.

1 Upvotes

When you click "render" or "render animation" (or use the command line -f or -a) is there a way you can hook into those using python? I have multiple cameras with different rendering resolution for X and Y. So I need to mess with bpy.data.scenes["Scene"].render.resolution_y and bpy.data.scenes["Scene"].render.resolution_x before the render.

I can write a script to mimic -a or -f via the command line, but it would be nicer to hook into the existing UI buttons and CLI options.


r/blenderpython • • Oct 25 '23

My simple add-on won't install - traceback error

1 Upvotes

Hello, so I have a very simple add-on. If I run it in the Scripting workspace, all is well.

If I try to install the .py file as an add-on through Preferences, I receive this error. Any ideas as to what's happening here?

Thanks in advance


r/blenderpython • • Apr 12 '23

[Help Needed] Blender Script to bake texture into a GLTF Scene $45 Reward

1 Upvotes

r/blenderpython • • Apr 01 '23

Low-code machine-learning PyCaret

Thumbnail
satyakide.com
1 Upvotes

r/blenderpython • • Oct 14 '21

Blender 2.8 Scenes Compatibility in Blender 2.79

1 Upvotes

Hi all, I wanted to ask that are the 3D scenes that are native to blender 2.8 cycles are also compatible with the blender 2.79 version? I'll be accessing these scenes using the bpy python API of blender 2.79.

An example scene: Archinteriors vol. 58 for Blender - BLENDER Collection - Evermotion


r/blenderpython • • Oct 14 '21

Need Realistic Looking Blender Scenes!!!

1 Upvotes

Hi all! I'm currently a part of a computer vision-based research lab and we are looking into using blender for making realistic-looking synthetic datasets for training models. We need at least 100 such scenes for creating a large diverse dataset and have bought all the blender-based Evermotion ArchInterior scenes(~40 scenes) but now are having a hard time finding more realistic-looking blender scenes. So I was hoping that you guys can point me to the right place for buying some more dope-ass realistic looking blender scenes.


r/blenderpython • • Oct 08 '21

Weird Rendered Images

1 Upvotes

I'm currently trying to render an emotion ArchInterior scene using blender python bpy but am getting something weird and am not sure what's going on. Nearly half of the image is abruptly grayed out or not rendering at all I guess. So can someone help me?


r/blenderpython • • Sep 12 '21

question about modal operators

1 Upvotes

hey guys I'm new to scripting . I wanted to make a script run continually without blender pausing or loosing functionality.
to my understanding I need to make a modal operator that does this.
however when in run blenders modal operator template that moves the object left and right,
I can no longer add an object to the scene, "shift+a" doesn't work anymore even if I comment out the line that makes left click finish and click on object or add menus nothing happens
to me this is loosing functionality
so wanted to know if there is a way to make something continually happen without loosing any functionality .
any help is greatly appreciated thanks.


r/blenderpython • • Jul 10 '21

Question about separate blender 3d viewports

Thumbnail self.learnpython
1 Upvotes

r/blenderpython • • Jun 19 '21

Adding a CollectionProperty to Spline

Thumbnail self.blender
1 Upvotes

r/blenderpython • • Jun 15 '21

Does anyone have any tips for speeding up scene.ray_cast() on very large scenes

1 Upvotes

I am running the scene raycast function on a bunch of different objects in a scene with thousands of objects and it can take a half a second to a second per ray, which seems incredibly slow to me. I'm wondering if anyone here might have tips on how I can optimize this a bit. Please note, I'm raycasting to collection instances so I don't think I can use object.ray_cast since non mesh object types aren't supported (if I'm wrong about this please let me know)


r/blenderpython • • Apr 26 '21

The align objects tool has 3 buttons (x, y, and z) that you can toggle on and off but it also lets you select more than one at a time. How can I make something like that?

1 Upvotes

r/blenderpython • • Mar 30 '21

Scipy Function as Node (sverchok addon)

1 Upvotes

Hello,

I am trying to use the scipy.interpolate.interpn function within blender. I assumed the only way to do this is to utilize the sverchok addon, so my first attempt at using this function is with the sverchok addon, but let me know if there is a better way to do this.

Although I have some basic knowledge of python, I think I am a bit out of my depth here. Nonetheless, I tried writing a script to use with the Scripted Node Lite node in sverchok:

"""
in in_points v
in values s
in xi v
out out_values s
"""

import numpy as np
import sys

from sverchok.utils.logging import exception, info
from sverchok.data_structure import zip_long_repeat

try:
    import scipy
    from scipy.interpolate import interpn
except ImportError as e:
    info("SciPy module is not available. Please refer to https://github.com/nortikin/sverchok/wiki/Non-standard-Python-modules-installation for how to install it.")
    raise e

out_values = []

for everypoint in xi:
    new_values = interpn(points, values, xi, method='linear', bounds_error=True, fill_value=0)

    out_values.append(new_values)

Here is what I get when I try to use the script as a scripted node in blender:

error screenshot

here are the files I am working with: https://drive.google.com/file/d/1a2a0l3rghzAbP91JEAb-mZXQZYpiLEsG/view?usp=sharing

If anyone could help me utilize this function in blender, or have any improvements for the script above, I would greatly appreciate it! Thanks,


r/blenderpython • • Jan 05 '21

XYZ Coordinates to Mesh

1 Upvotes

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.5

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

'new_from_object' and shape key data

1 Upvotes

Hi,

I'm porting a third-party import/export plugin from Blender 2.79 to 2.8. However, I'm having issues adapting its handling of temporary meshes and shape key data.

In preparation for export, it creates a copy of the mesh to operate upon without altering the original:

[Blender 2.79; 'object' is the currently selected model]

# Make a copy of the mesh to keep the original intact
mesh = object.to_mesh(bpy.context.scene, False, 'RENDER', False, False)

temp_obj = bpy.data.objects.new('temp_obj', mesh)

2.9's 'Object.to_mesh' no longer works in this context. To quote the doc, "the result is temporary and can not be used by objects from the main database."

My solution was to use:

# Make a copy of the mesh to keep the original intact
depsgraph = bpy.context.evaluated_depsgraph_get()
object_eval  = object.evaluated_get(depsgraph)
mesh = bpy.data.meshes.new_from_object(object_eval, preserve_all_data_layers=True, depsgraph=depsgraph)

temp_obj = bpy.data.objects.new(name='temp_obj', object_data=mesh)

Problem, this isn't copying the mesh's shape key data. Is there something I missed, or should I just rethink this whole process?


r/blenderpython • • Oct 09 '20

Speaker has no sound attribute

1 Upvotes

When trying to access the sound attribute of a Speaker object in Blender like so

Verify first

if obj.type='SPEAKER': path = obj.sound.filename

it throws an exception saying there is no attribute with the name 'sound'.

Have i misread the documentation or is there anything fundamentally wrong with my code? Thanks in advance guys :)


r/blenderpython • • Sep 23 '20

I am trying to finish this addon but the part of the chousen path to run the EXE files not working because of the \\ that is needed to accept the path in phyton

Thumbnail
youtu.be
1 Upvotes

r/blenderpython • • Sep 22 '20

how to link objects or collections for importing using python script

1 Upvotes

so basically i am creating a asset pack, and i would like to create a add on that imports or appends the models into the scene. I've found a template that includes the import code, but i need to somehow connect the assets so the code knows what to import


r/blenderpython • • Sep 21 '20

Logic controller node PYTHON

1 Upvotes

I have some code that adds a premade python script then makes a linked always and python controller but how do i assign a script to it?

bl_info = {
    "name": "Move X Axis",
    "blender": (2, 90, 0),
    "category": "Object",
}

import bpy


class ObjectMoveX(bpy.types.Operator):
    """My Object Moving Script"""      # Use this as a tooltip for menu items and buttons.
    bl_idname = "object.move_x"        # Unique identifier for buttons and menu items to reference.
    bl_label = "Move X by One"         # Display name in the interface.
    bl_options = {'REGISTER', 'UNDO'}  # Enable undo for the operator.

    def execute(self, context):        # execute() is called when running the operator.

        # The original script
        bpy.ops.text.open(filepath='D:\\test.py')


        obj = bpy.context.object
        sensors = obj.game.sensors
        controllers = obj.game.controllers
        

        bpy.ops.logic.sensor_add(type="ALWAYS", object=obj.name)
        bpy.ops.logic.controller_add(type="PYTHON", object=obj.name)
        
        

        # Newly added logic blocks will be the last ones:
        sensor = sensors[-1]
        controller = controllers[-1]
        

        sensor.link(controller)
        
        

        return {'FINISHED'}            # Lets Blender know the operator finished successfully.

def register():
    bpy.utils.register_class(ObjectMoveX)


def unregister():
    bpy.utils.unregister_class(ObjectMoveX)


# This allows you to run the script directly from Blender's Text editor
# to test the add-on without having to install it.
if __name__ == "__main__":
    register()

r/blenderpython • • Sep 20 '20

Looking for someone to write me 2 simple addons (PAID)

1 Upvotes

I'm looking for someone that can write me 2 simple addon templates. I don't really have time to learn python and i can't get what i want from the short tutorials on YT so i want to pay someone to write me 2 relatively customizable templates.

First one - N-Panel that allows me to append specific collection from a .Blend.

Good example of that would be Botaniq (https://blendermarket.com/creators/polygoniq) addon that has pretty much everything i would like. Only talking about "Spawn Asset" button.

If possible, button should be skipped directly into the "spawn asset" menu removing top 4 checkboxes and "make editable" checkbox.

All i need from this is to just have that kind of menu for appending collections with assets. I'm not asking for 100% copy of course, this is just an example of what i'm looking for. Main purpose for that is so i can have 1 blend file in the addon folder with my assets and append them easily. Bonus points if i can also append brushes with custom icons, i don't know if that's possible in a one addon but it would be great if it was possible. Mainly talking about texture draw brushes but sculpt brushes are appreciated too. It all should work like a normal addon so i can share it with friends.

In the code itself i'd like to have descriptions for segments of the code and it should be most importantly easy to change up so i can reuse it for different addons.

Second Addon - N-Panel like above but this time just really really simple including only 3 tabs found in the armature tab, "Skeleton", "Pose Library" and "Custom Properties"

nothing more nothing less. Should take that data from the active armature. Simply want it to make my personal rigs a bit easier to use for external users. All 3 tabs should be collapsible.

I hope i'm not asking for too much and it all should be relatively easy to write.

PayPal only, price will be discussed privately. If you're interested in working on those addons for me either add me on Discord DanteBoi#3228 or just leave your contact info here. Please straight up show me what did you do in Python so far just so i can see if i can trust you and tell me the pay you expect for it. Thank you ^^

If i'm posting this in a wrong place, please forward me to a correct one. I tried to look around for some kind of addon commissions but i couldn't really find anything.

Originally posted in r/blender but decided to post here too.


r/blenderpython • • Aug 26 '20

How to link attributes of two objects?

1 Upvotes

I think I just don't know the terminology to be able to find this solution. Here's an example of what I'd like to achieve -

Link the focal length of Camera B to the focal length of Camera A, so whenever A changes focal length, B changes as well. I can parent the two objects together, but can't figure out how to link other properties.

What am I missing here? Thanks!


r/blenderpython • • Aug 16 '20

Novice question here, and I probably just don’t understand the limits of python, but I’m trying to script an panel that will allow me to import premade models from a library I created, I can’t find info about this anywhere

1 Upvotes

I’m likely searching with the wrong terminology, but I don’t know what to search for if I don’t... know what to search for haha. Can anyone help?

To go on a bit more detail - I want to use the add on to create an import list of a variety of screws / nuts and bolts to add to scenes, as they’re a bit tedious to model or track down from old files every time.

It seems like it should be relatively simple, even at my skill level, and I’m struggling! Any help appreciated :)


r/blenderpython • • Jul 17 '20

Pie question. Newb with Python and need advice please XD

1 Upvotes

Pie menu question. Attempting to make a pie menu for my addon in Blender. I've got 8 operators defined, one for each of the rows in the pie and that works great. But i'd like to have some kind of menu button to switch the operators over to a different set, without completely calling an entirely different pie. I assume this requires replacing the operators with a variable that references a list in which case you can use matrix integers to determine which listed object appears as the operator the pie menu is calling at the time? let's just say each operator is a type of modifier or basic tool to perform a function like add a cube for now. I'd like to be able to cycle through which toolset is being called up to give the pie a bit more multi-purpose if that makes sense.


r/blenderpython • • May 14 '20

Activate Gizmo without clicking an axis?

1 Upvotes

I can't seem to find a way to do this.