Bone Layer Manager for Blender 2.8x

I’ve recently updated this addon for Blender 2.8x and extended it to add some Rig UI creation tools.

9 Likes

Added some bits and bobs… mainly bits.

BLM

2 Likes
I made some changes to the addon.
I'm using vscode as well, though you're not using pylinting or version control.

Pylinting is one thing, because if the code works, it works but version control is actually useful, even if you’re the only one using the files.

Doing version control lets you make notes of all the changes you make as well as store those changes like a backup. This history gets stored locally in the addon’s folder but the builtin Git extension doesn’t show any of them, once committed.
The Git History extension lets you view these multiple changes and with time-logging and etc.

The changes I made are:

  • Set a default value to UI Layers when you add them
    (so you don’t have to click, then manually set the number for every layer every time)

  • Display the bone name and bone icon for every bone in the Custom Properties panel.
    Otherwise, if you select multiple bones, you can’t tell which bone is the one you’re looking at.

  • Fix: modify the custom property from every selected bone, not just the active bone.

I also do some other things but I didn't include them because they're more of personal preferences:
  • Disable Swap active layers operator.
    After looking at the code to see why I was getting a cancel box, I found it’s completely useless unless you’re only viewing EXACTLY 2 layers inside your rig, which I essentially would NEVER be doing, ever.

  • Disable export script button. I have the addon, can code one myself, and aren’t trying to send anyone a rig, so I wouldn’t need this yet

  • Show the Rig UI and Bone Layers panels by default.
    I don’t want them closed initially, so when they are, I have to do extra clicking.

  • Enable Show Rig UI Setup and Hide Empty Layers by default.
    Personal defaults

Bone Layer Manager (tweaks and fix) redacted

1 Like

Hey thanks for the contribution I really appreciate it and welcome to Blender artists,

I can tell you’re not very impressed with my coding skills :wink:

My thoughts :
  • “Set a default value to UI Layers when you add them”
    (maybe this should stay at the last UI layer until incremented rare to want a new layer every time) : added to new release with = i+1

  • “Display the bone name and bone icon for every bone in the Custom Properties panel”
    Nice… but… issue with bones without properties now added to panel when not in properties edit mode : easy fix added to new release

  • Fix : modify the custom property from every selected bone, not just the active bone.”
    Excellent… good catch appreciated

  • “Disable Swap active layers operator”
    Works EXACTLY as coded… really just for swapping L and R in the UI… it’s a little odd that you would never ever ever ever have just 2 layers on… do you animate? I can look at a better implementation though…

The rest really is just personal preference… and wouldn’t even be mine :wink:

If you make any contribution add your name on the list of authors, any other ideas ?? added thanks for the contrib

Fin

…also… I know I have this on Gumroad for 0+ and literally generate no revenue from it but I would prefer if you didn’t post the addon here… thx.

Quote and Rebuttals

When you’re not in Property Edit, you still get a bunch of unlabeled properties that you can edit. I prefer seeing my bones anyway.
You could easily edit it to display labels when bones have properties and display no label when only one/active bone has any (or is selected)


Why on Mercury would you split an entire rig down the middle and disable the middle layer (that doesn’t go to either side)??? :thinking:

...

The only logic I can muster for this is that you use the whole rig like you would a mesh with the mirror modifier, where you model on one side, and mirror to the other.

I do what Rigify does, and take advantage of as many layers as I can:
Arm.L, Torso, Arm.R, Leg.L, Leg.R, Fingers (both on one because I don’t feel like splitting), Clothes, Jiggles, etc etc.
I can select any one item, then press Shift + G to select layer or group because I also group the bones (for color coordination, and splitting the fingers)

The ONLY time I have only two layers visible is like when I import a rig and all the body is on one layer and a bunch of extra+useless bones is on the second (xps/xnalara), and then I move them to more layers.

Note: Layers are for visiblity, Groups are for color and separation.
Visibility as in if you hide bones (H) of linked rigs, when you reload the file, all the hidden bones will be visible again; not the case with layers.


I didn’t put a name because I don’t care about getting credits.


An idea I've been meaning to do one day, is infinite layers for bones.

Rather than use the default limited 32 armature layers, a collection (not the new collections) could be used to store unlimited layers with the bones, as well as extra data, like UI Icons.

The bones could be all stored on one “blender layer” and the system would manage the bone visibility.
App.handlers would manage un-hiding/re-hiding bones on load and etc, and functions/operators would handle the visibility for clicking the layer visibility.

Could also do a persistent visibility property for bones, so that they will always be visible even when their layer is not.

UILayout.operator() has a parameter [depress] that can be used to mimic a property and you can either dynamically register operators (from one operator or app.handler), or you could send dynamic text to an operator to handle the changing code.
(exec and eval works great for this)


The details for that is speculation+imagination but the method/results are completely plausible as I’ve done that stuff for other things.
I just didn’t isolate that stuff for this particular task.


removed link and...

I would’ve just posted the changes but I was also trying to share the idea of Version Control with you (but you didn’t use it).


So, you probably didn’t notice it (I made a log about it) but also I changed some lines in bone_layers_panel.py (around line 146).

The change is you were using
"string %s outside the string" % (variables),
instead of the formatting string code:
F"string {variables} in the string".

Because they get the same result but F-Strings are easier to read and modify.

It’s very useful but I don’t think anyone knows about it because I don’t see it used in anyone’s code.
It’s been available since Python 3.0, which was released December 2008 and was likely added to Blender around then as well (@ the release of Blender 2.50)

1 Like

Yeah I spotted that line… had to Google it :wink:

… I’m obviously not a big coder… I only started last December… and you obviously are :wink:

I’ll read up on it only started using VSCode for the last version I put out… I appreciate what you’ve done, you can always DM me a link instead of posting it here…

Rigify uses layers for left and right control bones and uses those to create the UI… anyway you seem to have strong opinions on the matter… and I’m not in the mood for online rants… I’m glad my work has been of some use to you.

Nope, can’t. I’m not new, this is just new account, so I know there “should” be a send message button somewhere.
I didn’t know that new accounts can’t Send Messages. Don’t know if I have to be here for some time or get a certain amount of posts :stuck_out_tongue:

Apparently I can reply, I just can’t compose.


Where you removed the bone labels for custom props, when not editing:

This is so bones only show when they have properties

            if showedit == True:
                row = layout.row(align = True).split(align=True, factor=0.3)
                row.label(text=bone.name, icon='BONE_DATA')
                row.context_pointer_set('active_pose_bone', bone)
                row = row.operator("wm.properties_add", text="Add")
                row.data_path = "active_pose_bone"
            elif bone.keys():
                layout.label(text=bone.name, icon='BONE_DATA')
Also there's a glitch in that panel, where if you select all bones then deselect them with A / Alt+A

The panel will leave a big blank space until you select a bone. This is because the layout isn’t updating to the fact that nothing’s being drawn.
It could be a bug but I prefer to code than hope issues are bugs and wait for a developer to maybe fix it.
My fix here is to call call layout.label() before/after the bones.

        if not context.selected_pose_bones:
            layout.label(text="No bones selected", icon='INFO')

Of course you can leave it empty as layout.label() but that’d be one small blank space instead of the big one.

Added support for the other two panels, to use multiple objects.

Side note about try/except

You use try: / except around your code in a particular way.
I’ve seen this done in Rigify and I believe you’re doing it just because it’s the way they did it.

try:    object.data.name
except: pass

is enough for getting it to work.
Exception gets you the error as a string to make note of.

except Exception as var_str: print(f"Error box would've said {var_str}")

(AttributeError, KeyError, TypeError) and etc, are ways to “limit” the Exception.
Basically it’s like

if success:
elif problem_is_invalid_attribute:
else:

is the equivalent of

try:
except AttributeError:
except:

It would probably serve some purpose as debugging but more often than not, it’s best to include the else (“except”), rather than include or end with an elif.

Though Blender Python API documentation says it’s best to never use try/except unless it’s absolutely necessary, so it’s better to use getattr or hasattr.


Also, in a def function (like poll or whatever), if the code doesn’t reach a line with return (which exits the function), it automatically returns None
You can also just enter return, and Python will assume you meant return None

1 Like

Here’s another idea:
Add a left <> right parameter.
Right now, you can hide buttons or push them up/down but layers on the same line are ordered left-to-right, based on their internal armature layer.
If you want to change this order, you have to move all the bones on the layers around.

Another idea is moving the layers themselves.
So you can move bones in a layer to another slot, and transfer the name and etc to the new layer position.
If you do this manually, you have to add a new layer, copy the name+ui_layer, and then have to manually disable the previous layer because you already assigned it.

1 Like

Ok I just don’t like the bone labels when not in prop_edit mode I, it’s looks and works great in prop_edit mode but it just adds cluttter to the UI outside it… proper property names are all an animator needs to see as long as the properties are on sensible bones… again this is how the rigify UI works too… but maybe a toggle bone names button (or yet another checkbox) at the top of the panel could keep everyone happy???

That glitch bugs the hell out of me… thank for the code… that’s going in asap… although it’s not necessary to keep telling me what shortcut keys to use :stuck_out_tongue_closed_eyes: (I double tap A fyi)

Yeah I know I’m abusing try\except for version 0.7.1 i broke the code into smaller parts with the intention of rewriting it all as there’s a lot of code that’s pretty ghetto (was really just learning at the time)

I’ll look into the left <> right parameter… but will this play ok with layers of say 4 buttons??

… this is what the swap layers function (your favorite) is intended to do… if I add a check for rigui_id_x it would improve functionality… that’s what’s on the top of the list for me anyway.

Anyway thanks for the help and suggestions… I’ll update the code over the weekend.

Not sure what you mean here??

I mean in the code, I did that.
I didn’t post it because you asked me not to post the code/addon.

Oh…visually, all it appears to do is toggle bone selection between the visible layers.

Rig UI is a terrible place to put that button; it belongs in the Bone Layers panel with all the other Layer Modification stuff.


An idea for this function is to place a button on all the layers. When you click it once, it marks that layer as the first layer, then when you click a second layer, that layer is marked as the second.
Then the addon switches the two layers around, and you don’t even need to isolate their visibility.

When the first layer is selected, the button for it get’s the blue highlight, and if you click it again, it cancels the operator.

Remembering the state of the operator would use a custom prop in the armature.
And, UILayout.context_pointer_set() on the buttons to make it compatible with multiple objects.

…I’m going to do this today :thinking:

Ok I got ya…

Well it does actually work… i put it down there so people would understand it’s for the RigUI… which obviously didn’t work.

Swap

That said you solution sounds much better…

What do you think of this suggestion?

Sure.
You could also add those “options toggles” into a sub panel, so they don’t persistently clutter the (layers) management section…which could also be added under a sub panel.

If you're not familiar with sub panels

They’re a new concept in 2.8.
I’m not familiar with creating them but they’re these panels that get grouped under other panels:
image


The “Bone Layers” could also be renamed to “Bone Layer Management” or something, to specify it’s for editing, not layer viewing like Rig UI.
(just a thought; it’s not important)

I think I can get over this…

Yes that’ll work much better…

Maybe just Layer Management?

Works for me ¯\_(ツ)_/¯

Sooo, you’re telling me to post my mods here now? Post them then delete after you get it, post but don’t delete??
:hot_face::cold_face::face_vomiting: You’re sending me mixed messages here :crazy_face:

You can post what you want… and leave it here… you may have rubbed me up the wrong way yesterday… but overall I feel it’s a much needed tool for community… and it’ll give me an opportunity to understand version control in VScode…

Try not to lose sight of the fact that the reason I started work on this was to fill a gap in what has become a neglected area in the 2.8x release… I have a friend that uses this in training environments and I’ve tried to keep a balance between functionality and accessibility … I hope we can agree on the overall direction and this can becomes greater than the sum of it’s parts…

I redid the layer swap, to work with any two layers (visible or not).
I also added an alternative to what I suggested earlier for this button, in the form of two arrow buttons for directional pushing.

The changes, files, etc can be found at Github.
If you want, you can fork the branch or get ownership. It’s whatever :stuck_out_tongue:

I found it very difficult publishing a repository from vscode but it was very easy from the Github desktop program, which also let’s you commit changes with comments (vscode’s commit only does a title, which is limited in character length).