protected void getSetAttrCmds(MObject node, MStringArray cmds) { // // Get rid of any garbage already in the array. // cmds.clear(); // // Run through the node's attributes. // MFnDependencyNode nodeFn = new MFnDependencyNode(node); uint numAttrs = nodeFn.attributeCount; uint i; for (i = 0; i < numAttrs; i++) { // // Use the attribute ordering which Maya uses when doing I/O. // MObject attr = nodeFn.reorderedAttribute(i); MFnAttribute attrFn = new MFnAttribute(attr); bool isChild; attrFn.parent(out isChild); // // We don't want attributes which are children of other attributes // because they will be processed when we process the parent. // // And we only want storable attributes which accept inputs. // if (!isChild && attrFn.isStorable && attrFn.isWritable) { // // Get a plug for the attribute. // MPlug plug = new MPlug(node, attr); // // Get setAttr commands for this attribute, and any of its // children, which have had their values changed by the scene. // MStringArray newCmds = new MStringArray(); plug.getSetAttrCmds(newCmds, MPlug.MValueSelector.kChanged, false); uint numCommands = newCmds.length; int c; for (c = 0; c < numCommands; c++) { if (newCmds[c] != "") cmds.append(newCmds[c]); } } } }
protected void getAddAttrCmds(MObject node, MStringArray cmds) { // // Run through the node's attributes. // MFnDependencyNode nodeFn = new MFnDependencyNode(node); uint numAttrs = nodeFn.attributeCount; uint i; for (i = 0; i < numAttrs; i++) { // // Use the attribute ordering which Maya uses when doing I/O. // MObject attr = nodeFn.reorderedAttribute(i); // // If this attribute has been added since the node was created, // then we may want to write out an addAttr statement for it. // if (nodeFn.isNewAttribute(attr)) { MFnAttribute attrFn = new MFnAttribute(attr); // // If the attribute has a parent then ignore it because it will // be processed when we process the parent. // bool bFound; attrFn.parent(out bFound); if ( !bFound ) { // // If the attribute is a compound, then we can do its entire // tree at once. // try { MFnCompoundAttribute cAttrFn = new MFnCompoundAttribute(attr); MStringArray newCmds = new MStringArray(); cAttrFn.getAddAttrCmds(newCmds); uint numCommands = newCmds.length; int c; for (c = 0; c < numCommands; c++) { if (newCmds[c] != "") cmds.append(newCmds[c]); } } catch (Exception) { string newCmd = attrFn.getAddAttrCmd(); if (newCmd != "") cmds.append(newCmd); } } } } }