Giter Club home page Giter Club logo

bpylib's Introduction

bpylib – An intuitive API for Blender

The idea is to create an API that is intuitive to use. By intuitive, I mean, anyone who has an understanding of Blender should be able to write scripts easily to automate or build their own tools.

Often times, when you try the Blender API for the first time, you will realize there is a lot of conventions that you need to know to use it properly. And, the conventions are very different or not straightforward compared to how you use Blender through the GUI.

from bpylib import EditMode
from bpylib import Bool

# Create an Edit Mode context to perform mesh operations
with EditMode(mesh_object) as obj:
    obj.select_all()
    obj.face_mode_set()
    obj.merge_by_distance(0.01)
    obj.deselect_all()

# Create a Bool context to do boolean operations
with Bool(mesh_obj) as obj:
    obj += data.objects['Cube']

Also, just like how I select an object, go to the material tab, click on a material and edit material properties, I need to be able to do the same using the API.

Something like:

import bpylib

obj = bpylib.objects['Cube']

# Change Base Color of a material
# (assuming there's a Principled BSDF and only one)
obj.materials['Wood'].base_color = (0.1, 0.2, 0.2, 0)

# Local transforms
obj.translate_local(0, 0, -1)  # Move 1 unit back in local Z axis
obj.rotate_local(0, 0, 90)  # Rotate 90 degrees in local Z axis

context = bpylib.context
context.objects_mesh  # Get all mesh objects
context.objects_curve
context.selected

Node tree operations:

# Connect two nodes
node_image_tex.Image >> node_principled.basecolor  # connect sockets
node_image_tex.Image | node_principled.basecolor  # cut sockets

# Alternative interface
node_image_tex.Image.connect(node_principled.basecolor)
node_image_tex.Image.cut(node_principled.basecolor)

bpylib's People

Contributors

salaivv avatar

Stargazers

Neil Pullman avatar Gorro_Rojo avatar  avatar Jonathan-David Schröder avatar SpectralVectors avatar

Watchers

 avatar

bpylib's Issues

EasyBPY

Hi, feel free to delete this issue, I just saw your repo pop up on my feed and I wondered if you were already aware of the EasyBPY project by Curtis Holt?
https://github.com/curtisjamesholt/EasyBPY
https://curtisholt.online/easybpy
It is aiming for a similar type of functionality, but started ~2 years ago.

This may not be relevant to your purposes, but I thought you might find it interesting, if you weren't already aware of it.
Thanks for Modifier Stack Manager, by the way, it's a great addon!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.