Rigging Library scripting logic

I’ve been working on a basic structure for a rigging library within Blender(much like many studios utilize with their software). I’m not an amazing coder but I’m a rigger and I think this could be a handy plugin for character TD type people. I could use some help critiquing my basic logic behind the structure? I’m having some issues with things not being possible:)

Basically, I need a master control script which operates a panel to be allowed to call children scripts. Because the user determines which scripts are going to be used each time (each body part is its own script[ i.e–biped leg, quadraped leg, tail, etc…]), I don’t think I can dynamically do it as modules. My plan was to have the user input the filenames, store them in a list, and then use this command:

bpy.ops.script.python_file_run(filename = 'somefiles') 

on each one.

My problem is that each of the scripts comes in stages:

1- Generate empties which indicate joint positions
2- Connect Rig

I was going to try and see if I could pass in arguments (like argc and argv) into the method(to tell the script which stage of the process to run) but thats no good.

My next idea is to store a variable in my main control panel which indicates the stage and import the main class into each of the children scripts. I’d then run them using the above method and access main.stage to see what portion of the script to run.

example:


#in main.py:

class MainControl():
     stage = 0

#in second file
from main import MainControl()

if MainControl.stage == 0:

#etc...

Do any experienced coders see a better way of doing this that I’m missing? If I do it that way, will the “stage” variable actually update as I run the script? I’d rather spend less time at this point completely redoing my logic and more actually scripting these body parts:) If it was incoherent or you want more actual code examples I can post them. Either way, thanks for reading this enormous post.

Hmmm… I just ran a test where I initialized the variable in the main class to a value, changed it several times throughout the script, and printed it out from the importing script. The importing script only saw the initial value. I had hoped that because it was running within a panel that it would be current…I’ve got no ideas :slight_smile:

So python does actually let you dynamically import modules. Thats really cool:) I think thats probably the best I’m going to get so for now I’m going to go with that…

Yes, Python does have all the features you need to dynamically load and introspect modules.