Home Artists Posts Import Register

Content

Not about snakes but about trying to write some Python to help with workflow things. One of the drawbacks to using rigify is that it's cumbersome to add custom constraints to bones. It's alright if you don't plan on regenerating the rig but you can't regenerate the rig without losing the constraints (unless you follow some weird naming convention that I'm not entirely sure how it works). And even then, you can't preserve constraints added to bones that were generated by rigify itself (like tweak bones on a stretchy chain).

If I'm going to make rigify a bigger part of my workflow (which I'd love to because it's extremely powerful) I'd like to make customization of the generated rigs easier.

So I started writing an add-on that would be able to save and load constraint information on generated rigify rigs. My idea is to create a text file for the rig and go through every bone in the rig. If any of the bone constraints have the prefix "CUST-" (for custom) in the name, the constraint is written to a text file. There's a ton of variables when you account for every constraint... so it the function checks for every variable a constraint can have. Since many variables are shared, it just checks for every single one regardless of type.

The result is a file that lists each constraint and all the variables that constraint uses with it's saved values.

I've also written a function that adds constraints to bones that accounts for every variable a constraint has (so it takes a lot of parameters but it's not intended to be used directly)

I'm not great with Python and don't know if I'm going about making a function like this the way the Python gods intended but I wanted *one* function that can add *any* constraint because when a file is loaded it reads the file line by line and builds an arguments dictionary as it goes. And if you were going to use it directly, it'd be used more like this than filling parameters in directly into the parenthesis.

Also, I want my add-on to support drivers on constraints. So part of that was writing a Python function that can add a driver with enough functionality that it can create any driver that can be made by the user. I found a function on stack exchange which was a good start but made it be able to create any driver. Sort of...

It's still WIP, I need to make it work better with an arbitrary number of variables in the driver...

The problem with this stuff is it seems when you get into bone constraints/drivers and stuff, they're less widely used parts of the Blender API... so it's a lot sifting through the documentation and stack exchange for answers as opposed to like, seeing a tutorial about the specific thing you're trying to do on youtube. (Luckily I got pretty good at documentation sifting while getting my CS degree!)

It still needs a function that gets all the info on a constraint's drivers and writes it to the text file... but being able to make a driver in Python is ~half of the process.

So this add-on that I thought would be a simple undertaking isn't quite so simple (nothing is simple huh)... but would greatly extend the functionality of vanilla rigify for my needs. I'd like to make it available to everyone when it's functional enough to be useful.

Unfortunately I have absolutely nothing visually cool to show relating to this. This was a setup I was testing on though, two bones that copy the scale of another bone. The copy scale's power variable is being controlled by a driver added with python though (the y scale of a bone controls the power)

There's stuff I'd like to do like a bulk driver manager to make adding/editing drivers on many bone constraints easier but the interface I'd want to make seems tricky to program. So for a version 1 release it'll probably be this, just some buttons since buttons that execute a python function are pretty easy. Save/load buttons work! Clearing might be useless (why would you want to do that?) but I'll implement it anyway.


Files

Comments

Ormi

not about snakes :(

Adam Glenn

Have you tried using ChatGPT or Copilot to see if they can get you to answers faster than using the Blender docs?

velocirection

Haven't tried Copilot but I've attempted to ask about more complex stuff with ChatGPT before (or even code itself) but usually it can't give more than basic answers or code that doesn't work because it's using old API stuff. Sadly it's not magic, there's no guarantee you're getting complete or up to date information. So I prefer the old fashioned way. Plus I feel you retain the information better when you have to find it yourself.