I am working on a script to generate modular rig segments such as IK/FK chains and other such controls to drive a result skeleton. After creating a rig segment, the user can then take those controls and add space-switching parents to them to make that part of the rig constrained to whatever parents the user wants. The script also has a derigging feature to remove the rig from the result joints cleanly; it can easily be reapplied, but currently the user has to set up all of the space-switching parents every time.
I have an idea for the derigging function to note which space-switching parents the rig segment has (if any) and stores that information in the result joints, so that when the script reapplies the rig, it can automatically reapply the space-switching parents as well.
Right now, I'm considering storing this information in the result joint's Notes attribute, but I would like to make sure that this isn't a bad idea before going through with it. Could I use a joint's Notes attribute to store rigging information for a rigging script, or should I store it in a custom attribute, if at all?
Replies
Example:
<div># Do your imports import json from maya import cmds # Globals to make your life easier RIG_ATTRIBUTE = "recursiveRigData" # Write the attribute to the node def write_rig_data(node, data): # Quick note, I don't have Maya on this machine, so everything should work, # but no promises. if not cmds.attributeQuery(RIG_ATTRIBUTE, node=node, exists=True): cmds.addAttr(node, longName=RIG_ATTRIBUTE, dataType="string") # Unlock the attribute, set the data, then lock it again. attr = "{}.{}".format(node, RIG_ATTRIBUTE) cmds.setAttr(attr, lock=False) cmds.setAttr(attr, json.dumps(data), type="string") cmds.setAttr(attr, lock=True) def read_rig_data(node): # I'm assuming that the data you pass into the attribute is always a # dictionary. I recommend this because you can store a lot of information in # the attribute this way. if not cmds.attributeQuery(RIG_ATTRIBUTE, node=node, exists=True): return {} attr = "{}.{}".format(node, RIG_ATTRIBUTE) return json.loads(cmds.getAttr(attr))<br></div>Also, thank you for letting me know that dictionaries are a thing! I've never really used Python before switching to it from MEL, so I know very little about it outside of what I've needed for this script. Having actual key-value pairs will definitely simplify a few of my functions, which currently try to do the same thing with nested lists.
data = {"constraint_relationships": {"node1": "parent", "node2": "orient", "node3": "scale"}} # JSON string in the attribute '{"constraint_relationships": {"node1": "parent", "node3": "scale", "node2": "orient"}}' Having the data this way gives you a lot of flexibility later. For example, you can say what length the joint is, or what side it is.