//====================================================================== // // Check the parsed arguments and do/undo/redo the command as appropriate // void checkArgs(ref MArgDatabase argsDb) { MSelectionList objects = new MSelectionList(); argsDb.getObjects(objects); for (uint i = 0; i < objects.length; ++i) { MDagPath dagPath = new MDagPath(); objects.getDagPath((uint)i, dagPath); MFnDagNode dagNode = new MFnDagNode(dagPath.node); MObject obj = dagNode.child(0); if (obj.apiTypeStr == "kMesh") { fMesh = new MFnMesh(obj); fObj = obj; fObjTransform = dagPath.node; } } if( fMesh == null || fObj == null || fObjTransform == null ) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError); throw new ArgumentException(errMsg, "argsDb"); } }
//====================================================================== // // Check the parsed arguments and do/undo/redo the command as appropriate // void checkArgs(ref MArgDatabase argsDb) { MSelectionList objects = new MSelectionList(); argsDb.getObjects(objects); for (uint i = 0; i < objects.length; ++i) { MDagPath dagPath = new MDagPath(); objects.getDagPath((uint)i, dagPath); MFnDagNode dagNode = new MFnDagNode(dagPath.node); MObject obj = dagNode.child(0); if (obj.apiTypeStr == "kMesh") { fMesh = new MFnMesh(obj); fObj = obj; fObjTransform = dagPath.node; } } if (fMesh == null || fObj == null || fObjTransform == null) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError); throw new ArgumentException(errMsg, "argsDb"); } }
//====================================================================== // // Look through the arg database and verify that the arguments are // valid. Only checks the common flags so derived classes should call // this parent method first before checking their own flags. // public virtual void checkArgs(MArgDatabase argsDb) { String formatType = "raw"; fSerialize = AssociationsSerializer.formatByName(formatType); if (fSerialize == null) { String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kMetadataFormatNotFound); String msg = String.Format(fmt, formatType); displayError(msg); throw new System.ArgumentException(msg); } //---------------------------------------- // (selection list) // // Commands need at least one mesh object on which to operate so gather up // the list of meshes specified and/or selected. // // Empty out the list of meshes on which to operate so that it can be // populated from the selection or specified lists. fMeshes.clear(); MSelectionList objects = new MSelectionList(); argsDb.getObjects(objects); for (int i = 0; i < objects.length; ++i) { MDagPath dagPath = new MDagPath(); objects.getDagPath((uint)i, dagPath); MFnDagNode dagNode = new MFnDagNode(dagPath.node); MObject obj = dagNode.child(0); if (obj.apiTypeStr == "kMesh") { MFnMesh mesh = new MFnMesh(obj); if (mesh != null) { fMeshes.append(obj); } } else { String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kObjectTypeError); String msg = String.Format(fmt, dagPath.fullPathName + "[" + obj.apiTypeStr + "]"); displayError(msg); throw new System.InvalidOperationException(msg); } } if (fMeshes.length == 0) { String msg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError); displayError(msg); throw new System.InvalidOperationException(msg); } }
//====================================================================== // // Look through the arg database and verify that the arguments are // valid. Only checks the common flags so derived classes should call // this parent method first before checking their own flags. // public virtual void checkArgs(MArgDatabase argsDb) { String formatType = "raw"; fSerialize = AssociationsSerializer.formatByName( formatType ); if( fSerialize == null) { String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kMetadataFormatNotFound); String msg = String.Format(fmt, formatType); displayError(msg); throw new System.ArgumentException(msg); } //---------------------------------------- // (selection list) // // Commands need at least one mesh object on which to operate so gather up // the list of meshes specified and/or selected. // // Empty out the list of meshes on which to operate so that it can be // populated from the selection or specified lists. fMeshes.clear(); MSelectionList objects = new MSelectionList(); argsDb.getObjects(objects); for (int i = 0; i<objects.length; ++i) { MDagPath dagPath = new MDagPath(); objects.getDagPath((uint)i, dagPath); MFnDagNode dagNode = new MFnDagNode( dagPath.node ); MObject obj = dagNode.child(0); if (obj.apiTypeStr == "kMesh") { MFnMesh mesh = new MFnMesh(obj); if(mesh != null) fMeshes.append(obj); } else { String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kObjectTypeError); String msg = String.Format(fmt, dagPath.fullPathName + "[" + obj.apiTypeStr + "]"); displayError(msg); throw new System.InvalidOperationException(msg); } } if( fMeshes.length == 0 ) { String msg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError); displayError(msg); throw new System.InvalidOperationException(msg); } }
private void parseArgs(MArgList args) { const string kMessageFlag = "m"; MArgDatabase argData = new MArgDatabase(syntax, args); if (argData.isFlagSet(kMessageFlag)) { bool flag = false; try { flag = argData.flagArgumentBool(kMessageFlag, 0); } catch (Exception) { throw new ArgumentException("could not parse message flag", "args"); } if (flag) { addMessage = true; } else { delMessage = true; } } try { argData.getObjects(conditions); } catch (Exception) { displayError("could not parse condition names"); } // If there are no conditions specified, operate on all of them // if (conditions.length == 0) { // conditionNames is set in initializePlugin to all the // currently available condition names. // conditions = conditionNames; } }
//====================================================================== // // Check the parsed arguments and do/undo/redo the command as appropriate // void checkArgs(ref MArgDatabase argsDb) { //---------------------------------------- // (selection list) // // Commands need at least one node on which to operate so gather up // the list of nodes specified and/or selected. // // Empty out the list of nodes on which to operate so that it can be // populated from the selection or specified lists. fNodes.clear(); MSelectionList objects = new MSelectionList(); argsDb.getObjects(objects); for (uint i = 0; i < objects.length; ++i) { MDagPath dagPath = new MDagPath(); objects.getDagPath((uint)i, dagPath); MFnDagNode dagNode = new MFnDagNode(dagPath.node); MObject obj = dagNode.child(0); if (obj.apiTypeStr == "kMesh") { if (obj == MObject.kNullObj) { throw new ApplicationException("Error: objects.getDependNode() "); } fNodes.append(dagPath.node); } else { String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kObjectTypeError); String msg = String.Format(fmt, dagPath.fullPathName + "[" + obj.apiTypeStr + "]"); displayError(msg); throw new System.InvalidOperationException(msg); } } if (fNodes.length == 0) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError); throw new ArgumentException(errMsg, "argsDb"); } }
//====================================================================== // // Check the parsed arguments and do/undo/redo the command as appropriate // void checkArgs(ref MArgDatabase argsDb) { //---------------------------------------- // (selection list) // // Commands need at least one node on which to operate so gather up // the list of nodes specified and/or selected. // // Empty out the list of nodes on which to operate so that it can be // populated from the selection or specified lists. fNodes.clear(); MSelectionList objects = new MSelectionList(); argsDb.getObjects(objects); for (uint i = 0; i < objects.length; ++i) { MDagPath dagPath = new MDagPath(); objects.getDagPath((uint)i, dagPath); MFnDagNode dagNode = new MFnDagNode(dagPath.node); MObject obj = dagNode.child(0); if (obj.apiTypeStr == "kMesh") { if (obj == MObject.kNullObj) { throw new ApplicationException("Error: objects.getDependNode() "); } fNodes.append(dagPath.node); } else { String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kObjectTypeError); String msg = String.Format(fmt, dagPath.fullPathName + "[" + obj.apiTypeStr + "]"); displayError(msg); throw new System.InvalidOperationException(msg); } } if (fNodes.length == 0) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError); throw new ArgumentException(errMsg, "argsDb"); } }
//====================================================================== // // Check the parsed arguments and do/undo/redo the command as appropriate // void checkArgs(ref MArgDatabase argsDb) { //---------------------------------------- // -structure flag // fStructureFlag.parse(ref argsDb, flagStructure); if (fStructureFlag.isSet()) { if (!fStructureFlag.isArgValid()) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kInvalidString); throw new ArgumentException(errMsg, "argsDb"); } string structureName = fStructureFlag.arg(); try { fStructure = Structure.structureByName(structureName); } catch (System.Exception) { string msgFmt = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataStructureNotFound); throw new ArgumentException(String.Format(msgFmt, structureName), "argsDb"); } } else { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataNoStructureName); throw new ArgumentException(errMsg, "argsDb"); } //---------------------------------------- // -streamName flag // fStreamNameFlag.parse(ref argsDb, flagStreamName); if (fStreamNameFlag.isSet()) { if (!fStreamNameFlag.isArgValid()) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kInvalidString); throw new ArgumentException(errMsg, "argsDb"); } fStreamName = fStreamNameFlag.arg(); } else { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataNoStructureName); throw new ArgumentException(errMsg, "argsDb"); } //---------------------------------------- // -channelType flag // fChannelTypeFlag.parse(ref argsDb, flagChannelType); if (fChannelTypeFlag.isSet()) { if (!fChannelTypeFlag.isArgValid()) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kInvalidString); throw new ArgumentException(errMsg, "argsDb"); } fChannelType = fChannelTypeFlag.arg(); } else { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataNoStructureName); throw new ArgumentException(errMsg, "argsDb"); } //---------------------------------------- // (selection list) // // Commands need at least one node on which to operate so gather up // the list of nodes specified and/or selected. // // Empty out the list of nodes on which to operate so that it can be // populated from the selection or specified lists. fNodes.clear(); MSelectionList objects = new MSelectionList(); argsDb.getObjects(objects); for (uint i = 0; i < objects.length; ++i) { MDagPath dagPath = new MDagPath(); objects.getDagPath((uint)i, dagPath); MFnDagNode dagNode = new MFnDagNode(dagPath.node); MObject obj = dagNode.child(0); if (obj.apiTypeStr == "kMesh") { if (obj == MObject.kNullObj) { throw new ApplicationException("Error: objects.getDependNode() "); } fNodes.append(dagPath.node); } else { String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kObjectTypeError); String msg = String.Format(fmt, dagPath.fullPathName + "[" + obj.apiTypeStr + "]"); displayError(msg); throw new System.InvalidOperationException(msg); } } if (fNodes.length == 0) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError); throw new ArgumentException(errMsg, "argsDb"); } }
//====================================================================== // // Check the parsed arguments and do/undo/redo the command as appropriate // void checkArgs(ref MArgDatabase argsDb) { //---------------------------------------- // -structure flag // fStructureFlag.parse(ref argsDb, flagStructure); if (fStructureFlag.isSet()) { if (!fStructureFlag.isArgValid()) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kInvalidString); throw new ArgumentException(errMsg, "argsDb"); } string structureName = fStructureFlag.arg(); try { fStructure = Structure.structureByName(structureName); } catch (System.Exception) { string msgFmt = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataStructureNotFound); throw new ArgumentException(String.Format(msgFmt, structureName), "argsDb"); } } else { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataNoStructureName); throw new ArgumentException(errMsg, "argsDb"); } //---------------------------------------- // -streamName flag // fStreamNameFlag.parse(ref argsDb, flagStreamName); if (fStreamNameFlag.isSet()) { if (!fStreamNameFlag.isArgValid()) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kInvalidString); throw new ArgumentException(errMsg, "argsDb"); } fStreamName = fStreamNameFlag.arg(); } else { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataNoStructureName); throw new ArgumentException(errMsg, "argsDb"); } //---------------------------------------- // -channelType flag // fChannelTypeFlag.parse(ref argsDb, flagChannelType); if (fChannelTypeFlag.isSet()) { if (!fChannelTypeFlag.isArgValid()) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kInvalidString); throw new ArgumentException(errMsg, "argsDb"); } fChannelType = fChannelTypeFlag.arg(); } else { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataNoStructureName); throw new ArgumentException(errMsg, "argsDb"); } //---------------------------------------- // (selection list) // // Commands need at least one node on which to operate so gather up // the list of nodes specified and/or selected. // // Empty out the list of nodes on which to operate so that it can be // populated from the selection or specified lists. fNodes.clear(); MSelectionList objects = new MSelectionList(); argsDb.getObjects(objects); for (uint i = 0; i < objects.length; ++i) { MDagPath dagPath = new MDagPath(); objects.getDagPath((uint)i, dagPath); MFnDagNode dagNode = new MFnDagNode(dagPath.node); MObject obj = dagNode.child(0); if (obj.apiTypeStr == "kMesh") { if (obj == MObject.kNullObj) { throw new ApplicationException("Error: objects.getDependNode() "); } fNodes.append(dagPath.node); } else { String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kObjectTypeError); String msg = String.Format(fmt, dagPath.fullPathName + "[" + obj.apiTypeStr + "]"); displayError(msg); throw new System.InvalidOperationException(msg); } } if (fNodes.length == 0) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError); throw new ArgumentException(errMsg, "argsDb"); } }
private void parseArgs(MArgList args) { const string kMessageFlag = "m"; MArgDatabase argData = new MArgDatabase(syntax, args); if (argData.isFlagSet(kMessageFlag)) { bool flag = false; try { flag = argData.flagArgumentBool(kMessageFlag, 0); } catch (Exception) { throw new ArgumentException("could not parse message flag", "args"); } if (flag) { addMessage = true; } else { delMessage = true; } } try { argData.getObjects(conditions); } catch(Exception) { displayError("could not parse condition names"); } // If there are no conditions specified, operate on all of them // if (conditions.length == 0) { // conditionNames is set in initializePlugin to all the // currently available condition names. // conditions = conditionNames; } }
public override void doIt(MArgList args) { MSelectionList list = new MSelectionList(); MArgDatabase argData; argData = new MArgDatabase(syntax, args); argData.getObjects(list); // Get the flags // bool allDagUsed = argData.isFlagSet(kAllDagFlag); bool parentAddedUsed = argData.isFlagSet(kParentAddedFlag); bool parentRemovedUsed = argData.isFlagSet(kParentRemovedFlag); bool childAddedUsed = argData.isFlagSet(kChildAddedFlag); bool childRemovedUsed = argData.isFlagSet(kChildRemovedFlag); bool childReorderedUsed = argData.isFlagSet(kChildReorderedFlag); bool helpUsed = argData.isFlagSet(kHelpFlag); bool nothingSet = (!allDagUsed && !parentAddedUsed && !parentRemovedUsed && !childAddedUsed && !childRemovedUsed && !childReorderedUsed && !helpUsed); if (nothingSet) { throw new ArgumentException("-A flag must be used. dagMessage -help for available flags.", "args"); } if (argData.isFlagSet(kHelpFlag)) { MGlobal.displayInfo("dagMessage -help"); MGlobal.displayInfo("\tdagMessage adds a callback to the selected nodes,"); MGlobal.displayInfo("\tor if no nodes are selected, to all nodes. The callback"); MGlobal.displayInfo("\tprints a message when called. When the plug-in is unloaded"); MGlobal.displayInfo("\tthe callbacks are removed."); MGlobal.displayInfo(""); MGlobal.displayInfo("\t-h -help : This message is printed"); MGlobal.displayInfo("\t-ad -allDag : parent changes and child reorders"); MGlobal.displayInfo("\t-pa -parentAdded : A parent is added"); MGlobal.displayInfo("\t-pr -parentRemoved : A parent is removed"); MGlobal.displayInfo("\t-ca -childAdded : A child is added (only for individual nodes)"); MGlobal.displayInfo("\t-cr -childRemoved : A child is removed (only for individual nodes)"); MGlobal.displayInfo("\t-cro -childReordered : A child is reordered"); MGlobal.displayInfo(""); } uint nObjs = list.length; if (nObjs == 0) { // Add the callback for all changes of the specified type. // if (allDagUsed) { try { MDagMessage.AllDagChangesEvent += userDAGGenericCB; } catch (Exception) { throw new ApplicationException("Could not add a -allDag callback"); } } if (parentAddedUsed) { addGenericCallback(null, MDagMessage.DagMessage.kParentAdded, " parent added "); } if (parentRemovedUsed) { addGenericCallback(null, MDagMessage.DagMessage.kParentRemoved, " parent removed "); } if (childAddedUsed) { throw new ArgumentException("-childAdded can only be used when a node is selected", "args"); } if (childRemovedUsed) { throw new ArgumentException("-childRemoved can only be used when a node is selected", "args"); } if (childReorderedUsed) { addGenericCallback(null, MDagMessage.DagMessage.kChildReordered, " child reordered "); } } else { for (uint i = 0; i < nObjs; i++) { MDagPath dagPath = new MDagPath(); list.getDagPath(i, dagPath); if (!dagPath.isValid) { continue; } // Add the callback for all changes of the specified type. // if (allDagUsed) { // we don't use obsolete function // addAllDagChangesCallback // use addAllDagChangesDagPathCallback instead try { dagPath.AllDagChangesDagPath += userDAGGenericCB; string infoStr = string.Format("Added a callback for all Dag changes on {0}", dagPath.fullPathName); MGlobal.displayInfo(infoStr); } catch (Exception) { throw new ApplicationException("Could not add a -allDag callback"); } } if (parentAddedUsed) { addGenericCallback(dagPath, MDagMessage.DagMessage.kParentAdded, " parent added "); } if (parentRemovedUsed) { addGenericCallback(dagPath, MDagMessage.DagMessage.kParentRemoved, " parent removed "); } if (childAddedUsed) { addGenericCallback(dagPath, MDagMessage.DagMessage.kChildAdded, " child added "); } if (childRemovedUsed) { addGenericCallback(dagPath, MDagMessage.DagMessage.kChildRemoved, " child removed "); } if (childReorderedUsed) { addGenericCallback(dagPath, MDagMessage.DagMessage.kChildReordered, " child reordered "); } } } return; }
public override void doIt(MArgList args) { MSelectionList list = new MSelectionList(); MArgDatabase argData; argData = new MArgDatabase(syntax, args); argData.getObjects(list); // Get the flags // bool allDagUsed = argData.isFlagSet(kAllDagFlag); bool parentAddedUsed = argData.isFlagSet(kParentAddedFlag); bool parentRemovedUsed = argData.isFlagSet(kParentRemovedFlag); bool childAddedUsed = argData.isFlagSet(kChildAddedFlag); bool childRemovedUsed = argData.isFlagSet(kChildRemovedFlag); bool childReorderedUsed = argData.isFlagSet(kChildReorderedFlag); bool helpUsed = argData.isFlagSet(kHelpFlag); bool nothingSet = (!allDagUsed && !parentAddedUsed && !parentRemovedUsed && !childAddedUsed && !childRemovedUsed && !childReorderedUsed && !helpUsed); if (nothingSet) { throw new ArgumentException("-A flag must be used. dagMessage -help for available flags.", "args"); } if (argData.isFlagSet(kHelpFlag)) { MGlobal.displayInfo("dagMessage -help"); MGlobal.displayInfo("\tdagMessage adds a callback to the selected nodes,"); MGlobal.displayInfo("\tor if no nodes are selected, to all nodes. The callback"); MGlobal.displayInfo("\tprints a message when called. When the plug-in is unloaded"); MGlobal.displayInfo("\tthe callbacks are removed."); MGlobal.displayInfo(""); MGlobal.displayInfo("\t-h -help : This message is printed"); MGlobal.displayInfo("\t-ad -allDag : parent changes and child reorders"); MGlobal.displayInfo("\t-pa -parentAdded : A parent is added"); MGlobal.displayInfo("\t-pr -parentRemoved : A parent is removed"); MGlobal.displayInfo("\t-ca -childAdded : A child is added (only for individual nodes)"); MGlobal.displayInfo("\t-cr -childRemoved : A child is removed (only for individual nodes)"); MGlobal.displayInfo("\t-cro -childReordered : A child is reordered"); MGlobal.displayInfo(""); } uint nObjs = list.length; if (nObjs == 0) { // Add the callback for all changes of the specified type. // if (allDagUsed) { try { MDagMessage.AllDagChangesEvent += userDAGGenericCB; } catch (Exception) { throw new ApplicationException("Could not add a -allDag callback"); } } if (parentAddedUsed) { addGenericCallback(null, MDagMessage.DagMessage.kParentAdded, " parent added "); } if (parentRemovedUsed) { addGenericCallback(null, MDagMessage.DagMessage.kParentRemoved, " parent removed "); } if (childAddedUsed) { throw new ArgumentException("-childAdded can only be used when a node is selected", "args"); } if (childRemovedUsed) { throw new ArgumentException("-childRemoved can only be used when a node is selected", "args"); } if (childReorderedUsed) { addGenericCallback(null, MDagMessage.DagMessage.kChildReordered, " child reordered "); } } else { for (uint i = 0; i < nObjs; i++) { MDagPath dagPath = new MDagPath(); list.getDagPath(i, dagPath); if (!dagPath.isValid) { continue; } // Add the callback for all changes of the specified type. // if (allDagUsed) { // we don't use obsolete function // addAllDagChangesCallback // use addAllDagChangesDagPathCallback instead try { dagPath.AllDagChangesDagPath += userDAGGenericCB; string infoStr = string.Format("Added a callback for all Dag changes on {0}", dagPath.fullPathName); MGlobal.displayInfo(infoStr); } catch (Exception) { throw new ApplicationException("Could not add a -allDag callback"); } } if (parentAddedUsed) { addGenericCallback(dagPath, MDagMessage.DagMessage.kParentAdded, " parent added "); } if (parentRemovedUsed) { addGenericCallback(dagPath, MDagMessage.DagMessage.kParentRemoved, " parent removed "); } if (childAddedUsed) { addGenericCallback(dagPath, MDagMessage.DagMessage.kChildAdded, " child added "); } if (childRemovedUsed) { addGenericCallback(dagPath, MDagMessage.DagMessage.kChildRemoved, " child removed "); } if (childReorderedUsed) { addGenericCallback(dagPath, MDagMessage.DagMessage.kChildReordered, " child reordered "); } } } return; }