Nested Mirror Bone Collections Script

Scripting

I personally prefere working with nested collections simply because its faster for my eye to find stuff plus you can collapse them once there are too many that you dont need anyways.

Unfortunately the original script from the course files didnt affect them so I decided to try my hand at doing it myself.
Now this took way longer than I want to admit, but I got it working.

Script(fixed) - PasteBin
(You can change what suffix you would like to use via two variables at the top of the code)



--------------
Script(old) - PasteBin
It CAN crete Duplicate collections in this old version, if they have a bone in them with the SuffixR in their name.

For anyone more experienced with this, since im new to python in blender, can someone help me figure out how to avoid creating duplicates of child collections? In general, that is. My way is a workaround, and bothers me. The .get() function only works on a given collection, and I dont think I can make use of blenders Unique Name system that kicks in when you create or rename a collection via the UI, at least that I know of.
A simple name 'not in' armature.collections check unfortunately only limits you to top-level collections...

1 love
Reply
  • Wayne Dixon replied

    Hi Pascal,
    The get function will return the object you are getting or "None" if it doesn't exist.

    So you can do a little check to see if it already exists first.

    I'm paraphrasing because I'm away from my normal machine at the moment, but....

    if not get(collection):
        #create the collection
    #then move the bones to that collection


    Hope that makes sense.
    It won't create the collection with the 001 on the end of it already exists.


    2 loves
  • Pascal Schovanez(Pascal) replied

    Hey Wayne,
    unfortunately this doesnt work for me, as the .get function cannot be used standalone because its an inherited function of a structure, requiring an object to search its children. But at the same time doesnt search through the children's children.
    Meaning that it has no effect on nested collections, only the top-level ones.
    Meaning that if the following collection structure:

    - Left L
        - First L
        - Middle L
            - Last L

    When running the script using 'if not armature.collections.get(collection)' then it will only check 'Left L' collection, not any of its children, or their children.

    So I gave up on trying to find an elegant- built in solution to work with, and simply created a new function that goes over all collections manually, which might be a bit slow. But it works.

    I will update the OP to include the fixed script. So no more dupe collections, yay!

    1 love
  • Wayne Dixon replied

    Oh I understand your problem now.
    Yeah, you have to recursively search through all the collections - but I see you've figured that out.

    Sorry I was a bit late in my understanding.  But I'm glad you got it sorted.

    2 loves