//====================================================================== // // 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); } }
public override void doCreate() { Associations associationsRead = null; MIStream inStream = MStreamUtils.CreateIFStream(fileName); string errors = ""; associationsRead = fSerialize.read(inStream, ref errors); if (associationsRead == null) { String fmt = MStringResource.getString(MetaDataRegisterMStringResources.kImportMetadataFileReadFailed); String msg; if (errors == null || errors.Length < 1) { errors = "No errors was given by the serializer when reading the metadata file."; } msg = String.Format(fmt, fileName, errors); displayError(msg); throw new System.ApplicationException(msg); } String resultFmt = MStringResource.getString(MetaDataRegisterMStringResources.kImportMetadataResult); for (int i = 0; i < fMeshes.length; ++i) { MFnMesh mesh = new MFnMesh(fMeshes[i]); // Should have filtered out non-meshes already but check anyway if (mesh == null) { continue; } displayInfo(mesh.fullPathName); //We dont have the correct interface on MDGModifier to assign metadata so no undo redo for now Associations associationsMesh = mesh.metadata; associationsMesh.assign(associationsRead); for (int c = 0; c < associationsRead.channelCount; ++c) { Autodesk.Maya.MetaData.Channel channel = associationsRead.channelAt((uint)c); String cName = channel.nameProperty; for (int s = 0; s < channel.dataStreamCount; ++s) { Autodesk.Maya.MetaData.Stream cStream = channel.dataStream((uint)s); if (cStream != null) { String sName = cStream.name; String msg = String.Format(resultFmt, mesh.fullPathName, cName, sName); appendToResult(msg); } } } } MStreamUtils.Close(inStream); inStream = null; }
public override void getFormatDescription(MOStream info) { string msgPre = MStringResource.getString(MetaDataRegisterMStringResources.kStructureXMLInfoPre); string msgPost = MStringResource.getString(MetaDataRegisterMStringResources.kStructureXMLInfoPost); MStreamUtils.writeChar(info, msgPre[0]); for (uint i = (uint)Member.eDataType.kFirstType; i < (uint)Member.eDataType.kLastType; ++i) { if (i != (uint)Member.eDataType.kFirstType) { MStreamUtils.writeCharBuffer(info, ", "); } } MStreamUtils.writeChar(info, msgPost[0]); }
//====================================================================== // // 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"); } }
public bool importAim(string fileName, string flags) { MAnimCurveClipboard.theAPIClipboard.clear(); // If the selection list is empty, there is nothing to import. // MSelectionList sList = new MSelectionList(); MGlobal.getActiveSelectionList(sList); if (sList.isEmpty) { string msg = MStringResource.getString(RegisterMStringResources.kNothingSelected); MGlobal.displayError(msg); return(false); } StreamReaderExt readExt = new StreamReaderExt(fileName); fReader.readClipboard(ref readExt, MAnimCurveClipboard.theAPIClipboard); if (MAnimCurveClipboard.theAPIClipboard.isEmpty) { return(false); } string command = "pasteKey -cb api "; command += pasteFlags; try { int result = -1; MGlobal.executeCommand(command, out result, false, true); } catch (System.Exception) { string msg = MStringResource.getString(RegisterMStringResources.kPasteFailed); MGlobal.displayError(msg); return(false); } readExt.Close(); return(true); }
public override void doCreate() { if (fMeshes.length != 1) { throw new System.ApplicationException("ExportMetadataCmd: do not support less or more then 1 mesh."); } MFnMesh mesh = new MFnMesh(fMeshes[0]); displayInfo(mesh.fullPathName); Associations associationsToWrite = mesh.metadata; if (associationsToWrite == null) { throw new System.ApplicationException("ExportMetadataCmd: no association to write."); } String errors = ""; // Dump either to a file or the return string, depending on which was // requested. // MOStream destination = MStreamUtils.CreateOFStream(fileName); if (fSerialize.write(associationsToWrite, destination, ref errors) == 0) { setResult(fileName); } else { String msg = MStringResource.getString(MetaDataRegisterMStringResources.kExportMetadataFailedFileWrite); displayError(msg); } MStreamUtils.Close(destination); destination = null; if (errors != null && errors.Length > 0) { displayError(errors); return; } return; }
private bool exportSelected(ref StreamWriter animFile, ref string copyFlags, bool nodeNames = false, bool verboseUnits = false) { // If the selection list is empty, then there are no anim curves // to export. // MSelectionList sList = new MSelectionList(); MGlobal.getActiveSelectionList(sList); if (sList.isEmpty) { string msg = MStringResource.getString(RegisterMStringResources.kNothingSelected); MGlobal.displayError(msg); return(false); } // Copy any anim curves to the API clipboard. // int result = 0; string command = copyFlags; try { MGlobal.executeCommand(command, out result, false, true); } catch (System.Exception) { string msg = MStringResource.getString(RegisterMStringResources.kAnimCurveNotFound); MGlobal.displayError(msg); return(false); } if (result == 0 || MAnimCurveClipboard.theAPIClipboard.isEmpty) { string msg = MStringResource.getString(RegisterMStringResources.kAnimCurveNotFound); MGlobal.displayError(msg); return(false); } fWriter.writeClipboard(ref animFile, MAnimCurveClipboard.theAPIClipboard, nodeNames, verboseUnits); return(true); }
static public void registerStringResources() { MStringResource.registerString(MetaDataRegisterMStringResources.kCreateMetadataCreateFailed); MStringResource.registerString(MetaDataRegisterMStringResources.kCreateMetadataHasStream); MStringResource.registerString(MetaDataRegisterMStringResources.kCreateMetadataNoChannelType); MStringResource.registerString(MetaDataRegisterMStringResources.kCreateMetadataNoStreamName); MStringResource.registerString(MetaDataRegisterMStringResources.kCreateMetadataNoStructureName); MStringResource.registerString(MetaDataRegisterMStringResources.kCreateMetadataStructureNotFound); MStringResource.registerString(MetaDataRegisterMStringResources.kEditQueryFlagErrorMsg); MStringResource.registerString(MetaDataRegisterMStringResources.kExportMetadataFailedFileWrite); MStringResource.registerString(MetaDataRegisterMStringResources.kExportMetadataFailedStringWrite); MStringResource.registerString(MetaDataRegisterMStringResources.kExportMetadataUndoMissing); MStringResource.registerString(MetaDataRegisterMStringResources.kFileIgnored); MStringResource.registerString(MetaDataRegisterMStringResources.kFileNotFound); MStringResource.registerString(MetaDataRegisterMStringResources.kFileOrStringNeeded); MStringResource.registerString(MetaDataRegisterMStringResources.kFlagMandatory); MStringResource.registerString(MetaDataRegisterMStringResources.kImportMetadataFileReadFailed); MStringResource.registerString(MetaDataRegisterMStringResources.kImportMetadataResult); MStringResource.registerString(MetaDataRegisterMStringResources.kImportMetadataSetMetadataFailed); MStringResource.registerString(MetaDataRegisterMStringResources.kImportMetadataStringReadFailed); MStringResource.registerString(MetaDataRegisterMStringResources.kImportMetadataUndoMissing); MStringResource.registerString(MetaDataRegisterMStringResources.kInvalidComponentType); MStringResource.registerString(MetaDataRegisterMStringResources.kInvalidFlag); MStringResource.registerString(MetaDataRegisterMStringResources.kInvalidStream); MStringResource.registerString(MetaDataRegisterMStringResources.kInvalidString); MStringResource.registerString(MetaDataRegisterMStringResources.kMetadataFormatNotFound); MStringResource.registerString(MetaDataRegisterMStringResources.kNometadataError); MStringResource.registerString(MetaDataRegisterMStringResources.kObjectNotFoundError); MStringResource.registerString(MetaDataRegisterMStringResources.kObjectTypeError); MStringResource.registerString(MetaDataRegisterMStringResources.kOnlyCreateModeMsg); MStringResource.registerString(MetaDataRegisterMStringResources.kStructureXMLInfoPost); MStringResource.registerString(MetaDataRegisterMStringResources.kStructureXMLInfoPre); MStringResource.registerString(MetaDataRegisterMStringResources.kStructureXMLMemberNameNotFound); MStringResource.registerString(MetaDataRegisterMStringResources.kStructureXMLMemberTypeNotFound); MStringResource.registerString(MetaDataRegisterMStringResources.kStructureXMLStructureNameNotFound); MStringResource.registerString(MetaDataRegisterMStringResources.kStructureDotNetTypeInfoPost); MStringResource.registerString(MetaDataRegisterMStringResources.kStructureDotNetTypeInfoPre); MStringResource.registerString(MetaDataRegisterMStringResources.kTypeUnspecified); }
//====================================================================== // // Do the metadata creation. The metadata will be randomly initialized // based on the channel type and the structure specified. For recognized // components the number of metadata elements will correspond to the count // of components in the selected mesh, otherwise a random number of metadata // elements between 1 and 100 will be created (at consecutive indices). // // The previously existing metadata is preserved for later undo. // override public void doIt(MArgList args) { MArgDatabase argsDb = new MArgDatabase(syntax, args); checkArgs(ref argsDb); clearResult(); MColorArray myColorArray = new MColorArray(); MFnDependencyNode node = new MFnDependencyNode(fObj); // Get the current metadata (empty if none yet) Associations newMetadata = new Associations(node.metadata); Channel newChannel = newMetadata.channel("vertex"); // Check to see if the requested stream name already exists Stream oldStream = newChannel.dataStream(fStreamName); if (oldStream != null) { string fmt = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataHasStream); string msg = String.Format(fmt, fStreamName); MGlobal.displayError(msg); return; } StreamForType <MyStructureClass> newStream = new StreamForType <MyStructureClass>(fStreamName); int indexCount = fMesh.numVertices; Random rndIndexCount = new Random(); // Fill specified stream ranges with random data int m; Random rnd = new Random(); for (m = 0; m < indexCount; ++m) { // Walk each structure member and fill with random data // tailored to the member data type. MyStructureClass myClass = new MyStructureClass(); // int myClass.a = rnd.Next(Int32.MinValue, Int32.MaxValue); // float myClass.b = (float)rnd.NextDouble(); // string string[] randomStrings = new string[] { "banana", "tomatoe", "apple", "pineapple", "apricot", "pepper", "olive", "grapefruit" }; int index = rnd.Next(randomStrings.Length); myClass.c = randomStrings[index]; // bool int randomInt = rnd.Next(0, 2); myClass.d = randomInt == 1 ? true : false; myClass.e = rnd.Next(Int32.MinValue, Int32.MaxValue); myClass.f = rnd.Next(Int32.MinValue, Int32.MaxValue); myClass.xyz[0] = (float)rnd.NextDouble(); myClass.xyz[1] = (float)rnd.NextDouble(); myClass.xyz[2] = (float)rnd.NextDouble(); newStream[m] = myClass; } newChannel.setDataStream(newStream); newMetadata.setChannel(newChannel); // Note: the following will not work if "obj" is a shape constructed by a source object // You need to delete the history of the shape before calling this... fDGModifier.setMetadata(fObj, newMetadata); fDGModifier.doIt(); Associations meshMetadata = fMesh.metadata; // This code is for debugging only { Channel chn = meshMetadata["vertex"]; Console.WriteLine("Channel : type = {0}, nbStreams = {1}", chn.nameProperty, chn.dataStreamCount); Stream chnStream = chn[fStreamName]; Structure strct = chnStream.structure; var strm = new StreamForType <MyStructureClass>(chnStream); Console.WriteLine("Stream : name = {0}, nbElements = {1}", chnStream.name, chnStream.Count); var tomatoes = strm.Where((KeyValuePair <Index, MyStructureClass> keyvalue) => keyvalue.Value.c == "tomatoe"); foreach (var keyvalue in tomatoes) // foreach (MyStructureClass myClass in strm.Values ) { Console.WriteLine("Vertex #{0}, a = {1}", keyvalue.Key.asString, keyvalue.Value.a.ToString()); Console.WriteLine("Vertex #{0}, b = {1}", keyvalue.Key.asString, keyvalue.Value.b.ToString()); Console.WriteLine("Vertex #{0}, c = {1}", keyvalue.Key.asString, keyvalue.Value.c.ToString()); Console.WriteLine("Vertex #{0}, d = {1}", keyvalue.Key.asString, keyvalue.Value.d.ToString()); Console.WriteLine("Vertex #{0}, e = {1}", keyvalue.Key.asString, keyvalue.Value.e.ToString()); Console.WriteLine("Vertex #{0}, f = {1}", keyvalue.Key.asString, keyvalue.Value.f.ToString()); Console.WriteLine("Vertex #{0}, xyz = {1},{2},{3}", keyvalue.Key.asString, keyvalue.Value.xyz[0].ToString(), keyvalue.Value.xyz[1].ToString(), keyvalue.Value.xyz[2].ToString()); Console.WriteLine("Vertex #{0}, abc = {1},{2}", keyvalue.Key.asString, keyvalue.Value.abc[0], keyvalue.Value.abc[1]); } } }
//====================================================================== // // 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"); } }
//====================================================================== // // Do the metadata creation. The metadata will be randomly initialized // based on the channel type and the structure specified. For recognized // components the number of metadata elements will correspond to the count // of components in the selected mesh, otherwise a random number of metadata // elements between 1 and 100 will be created (at consecutive indices). // // The previously existing metadata is preserved for later undo. // override public void doIt(MArgList args) { MArgDatabase argsDb = new MArgDatabase(syntax, args); checkArgs(ref argsDb); clearResult(); uint numNodes = fNodes.length; int i; for (i = 0; i < numNodes; ++i) { // fNodes[i] is the transform not the shape itself MFnDagNode dagNode = new MFnDagNode(fNodes[i]); MObject obj = dagNode.child(0); // obj is the shape, which is where we can add the meta data MFnDependencyNode node = new MFnDependencyNode(obj); // Get the current metadata (empty if none yet) Associations newMetadata = new Associations(node.metadata); Channel newChannel = newMetadata.channel(fChannelType); // Check to see if the requested stream name already exists Stream oldStream = newChannel.dataStream(fStreamName); if (oldStream != null) { string fmt = MStringResource.getString(MetaDataRegisterMStringResources.kCreateMetadataHasStream); string msg = String.Format(fmt, fStreamName); MGlobal.displayError(msg); continue; } Stream newStream = new Stream(fStructure, fStreamName); string strmName = newStream.name; int indexCount = 0; MFnMesh mesh = null; Random rndIndexCount = new Random(); // Treat the channel type initializations different for meshes if (obj.hasFn(MFn.Type.kMesh)) { mesh = new MFnMesh(obj); // Get mesh-specific channel type parameters if (fChannelType == "face") { indexCount = mesh.numPolygons; } else if (fChannelType == "edge") { indexCount = mesh.numEdges; } else if (fChannelType == "vertex") { indexCount = mesh.numVertices; } else if (fChannelType == "vertexFace") { indexCount = mesh.numFaceVertices; } else { // Set a random number between 1 to 100 indexCount = rndIndexCount.Next(1, 100); } } else { // Create generic channel type information indexCount = rndIndexCount.Next(1, 100); } // Fill specified stream ranges with random data int structureMemberCount = fStructure.memberCount; uint m, n, d; Random rnd = new Random(); for (m = 0; m < indexCount; ++m) { // Walk each structure member and fill with random data // tailored to the member data type. Handle handle = new Handle(fStructure); for (n = 0; n < structureMemberCount; ++n) { handle.setPositionByMemberIndex(n); switch (handle.dataType) { case Member.eDataType.kBoolean: { bool[] data = new bool[handle.dataLength]; for (d = 0; d < handle.dataLength; ++d) { int randomInt = rnd.Next(0, 2); bool randomBool = randomInt == 1 ? true : false; data[d] = randomBool; } handle.asBooleanArray = data; break; } case Member.eDataType.kDouble: { double[] data = new double[handle.dataLength]; for (d = 0; d < handle.dataLength; ++d) { // Set a random number between -2000000000.0.0 and 2000000000.0.0 data[d] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; } handle.asDoubleArray = data; break; } case Member.eDataType.kDoubleMatrix4x4: { double[] data = new double[handle.dataLength * 16]; for (d = 0; d < handle.dataLength; ++d) { data[d * 16 + 0] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 1] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 2] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 3] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 4] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 5] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 6] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 7] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 8] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 9] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 10] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 11] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 12] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 13] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 14] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; data[d * 16 + 15] = rnd.NextDouble() * 4000000000.0 - 2000000000.0; } handle.asDoubleMatrix4x4 = data; break; } case Member.eDataType.kFloat: { float[] data = new float[handle.dataLength]; for (d = 0; d < handle.dataLength; ++d) { // Set a random number between -2000000.0 and 2000000.0 data[d] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; } handle.asFloatArray = data; break; } case Member.eDataType.kFloatMatrix4x4: { float[] data = new float[handle.dataLength * 16]; for (d = 0; d < handle.dataLength; ++d) { // Set a random number between -2000000.0 and 2000000.0 data[d * 16 + 0] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 1] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 2] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 3] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 4] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 5] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 6] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 7] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 8] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 9] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 10] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 11] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 12] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 13] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 14] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; data[d * 16 + 15] = (float)rnd.NextDouble() * 4000000.0f - 2000000.0f; } handle.asFloatMatrix4x4 = data; break; } case Member.eDataType.kInt8: { sbyte[] data = new sbyte[handle.dataLength]; for (d = 0; d < handle.dataLength; ++d) { data[d] = (sbyte)rnd.Next(SByte.MinValue, SByte.MaxValue + 1); } handle.asInt8Array = data; break; } case Member.eDataType.kInt16: { short[] data = new short[handle.dataLength]; for (d = 0; d < handle.dataLength; ++d) { data[d] = (short)rnd.Next(Int16.MinValue, Int16.MaxValue + 1); } handle.asInt16Array = data; break; } case Member.eDataType.kInt32: { int[] data = new int[handle.dataLength]; for (d = 0; d < handle.dataLength; ++d) { // rnd.Next returns a number between [arg1,arg2[ // but unfortunately I can't pass Int32.MaxValue+1 here.... data[d] = rnd.Next(Int32.MinValue, Int32.MaxValue); } handle.asInt32Array = data; break; } case Member.eDataType.kInt64: { long[] data = new long[handle.dataLength]; for (d = 0; d < handle.dataLength; ++d) { // rnd.Next() gives a number between [0,Int32 data[d] = (long)rnd.Next(Int32.MinValue, Int32.MaxValue); if (data[d] >= 0) { data[d] *= Int64.MaxValue / Int32.MaxValue; } else { data[d] *= Int64.MinValue / Int32.MinValue; } } handle.asInt64Array = data; break; } case Member.eDataType.kUInt8: { byte[] data = new byte[handle.dataLength]; for (d = 0; d < handle.dataLength; ++d) { data[d] = (byte)rnd.Next(0, Byte.MaxValue + 1); } handle.asUInt8Array = data; break; } case Member.eDataType.kUInt16: { ushort[] data = new ushort[handle.dataLength]; for (d = 0; d < handle.dataLength; ++d) { data[d] = (ushort)rnd.Next(0, UInt16.MaxValue + 1); } handle.asUInt16Array = data; break; } case Member.eDataType.kUInt32: { uint[] data = new uint[handle.dataLength]; for (d = 0; d < handle.dataLength; ++d) { data[d] = (uint)rnd.Next(); } handle.asUInt32Array = data; break; } case Member.eDataType.kUInt64: { ulong[] data = new ulong[handle.dataLength]; for (d = 0; d < handle.dataLength; ++d) { data[d] = ((ulong)rnd.Next()) * UInt64.MaxValue / UInt32.MaxValue; } handle.asUInt64Array = data; break; } case Member.eDataType.kString: { string[] randomStrings = new string[] { "banana", "tomatoe", "apple", "pineapple", "apricot", "pepper", "olive", "grapefruit" }; string[] data = new string[handle.dataLength]; for (d = 0; d < handle.dataLength; ++d) { int index = rnd.Next(randomStrings.Length); data[d] = randomStrings[index]; } handle.asStringArray = data; break; } default: { Debug.Assert(false, "This should never happen"); break; } } } newStream.setElement(new Index(m), handle); } newChannel.setDataStream(newStream); newMetadata.setChannel(newChannel); // Note: the following will not work if "obj" is a shape constructed by a source object // You need to delete the history of the shape before calling this... fDGModifier.setMetadata(obj, newMetadata); fDGModifier.doIt(); // Set the result to the number of actual metadata values set as a // triple value: // (# nodes, # metadata elements, # members per element) // MIntArray theResult = new MIntArray(); theResult.append((int)fNodes.length); theResult.append((int)indexCount); theResult.append((int)structureMemberCount); setResult(theResult); } }
public override Structure read(MIStream cSrc, ref string errors) { int errCount = 0; Structure newStructure = null; errors = ""; uint size = MStreamUtils.getLength(cSrc); string myString = ""; // The last argument is true since we don't want to stop reading a stream when a WhiteSpace is encountered. MStreamUtils.readCharBuffer(cSrc, out myString, size, true); XmlReader reader = XmlReader.Create(new System.IO.StringReader(myString)); string elementName = ""; while (reader.Read()) { // Skip anything unrecognized, for maximum flexibility if (reader.NodeType != XmlNodeType.Element) { continue; } elementName = reader.Name; // Root must be a <structure> tag if (elementName == structureTag) { bool isStrucNameFound = reader.MoveToAttribute(structureNameAttribute); if (isStrucNameFound) { string structureName = reader.ReadContentAsString(); newStructure = new Structure(structureName); } else { string msgFmt = MStringResource.getString(MetaDataRegisterMStringResources.kStructureXMLStructureNameNotFound); IXmlLineInfo xmlInfo = (IXmlLineInfo)reader; int lineNumber = xmlInfo.LineNumber; string errorMsg = String.Format(msgFmt, lineNumber.ToString()); errors += errorMsg; errCount++; continue; } } if (newStructure == null) { continue; } // All children must all be <member> tags if (elementName == memberTag) { uint memberDim = 1; string memberName = ""; string memberType = ""; bool isMemberNameFound = reader.MoveToAttribute(memberNameAttribute); if (isMemberNameFound) { memberName = reader.ReadContentAsString(); } else { string msgFmt = MStringResource.getString(MetaDataRegisterMStringResources.kStructureXMLMemberNameNotFound); IXmlLineInfo xmlInfo = (IXmlLineInfo)reader; int lineNumber = xmlInfo.LineNumber; string errorMsg = String.Format(msgFmt, lineNumber.ToString()); errors += errorMsg; continue; } bool isMemberTypeFound = reader.MoveToAttribute(memberTypeAttribute); if (isMemberTypeFound) { memberType = reader.ReadContentAsString(); } else { string msgFmt = MStringResource.getString(MetaDataRegisterMStringResources.kStructureXMLMemberTypeNotFound); IXmlLineInfo xmlInfo = (IXmlLineInfo)reader; int lineNumber = xmlInfo.LineNumber; string errorMsg = String.Format(msgFmt, lineNumber.ToString()); errors += errorMsg; continue; } bool isMemberDimFound = reader.MoveToAttribute(memberDimAttribute); if (isMemberDimFound) { memberDim = (uint)reader.ReadContentAsInt(); } else { memberDim = 1; } newStructure.addMember(Member.typeFromName(memberType), memberDim, memberName); } } // If there were errors any structure created will be incorrect so pass // back nothing rather than bad data. if (errCount > 0) { newStructure = null; } return(newStructure); }
override public void doIt(MArgList args) { MArgDatabase argData; MPxCommandSyntaxFlagAttribute MyAttribute = (MPxCommandSyntaxFlagAttribute)Attribute.GetCustomAttribute(typeof(NodeInfoCmd), typeof(MPxCommandSyntaxFlagAttribute)); MSyntax syntax = new MSyntax(); if (MyAttribute != null) { syntax.addFlag(MyAttribute.ShortFlag, MyAttribute.LongFlag); } else { syntax.addFlag(kQuietFlag, kQuietFlagLong); } try { argData = new MArgDatabase(syntax, args); } catch (System.Exception ex) { MGlobal.displayInfo(ex.Message); } MSelectionList selectList = MGlobal.activeSelectionList; foreach (MObject node in selectList.DependNodes()) { MFnDependencyNode depFn = new MFnDependencyNode(); depFn.setObject(node); string nodename = depFn.name; nodename += ":"; printType(node, nodename); MPlugArray connectedPlugs = new MPlugArray(); try { depFn.getConnections(connectedPlugs); } catch (System.Exception ex) { MGlobal.displayInfo(ex.Message); } uint numberOfPlugs = connectedPlugs.length; string msgFmt = MStringResource.getString(NodeInfoCmd.rConnFound); MGlobal.displayInfo(String.Format(msgFmt, Convert.ToString(numberOfPlugs))); string pInfoMsg = MStringResource.getString(NodeInfoCmd.rPlugInfo); for (int i = 0; i < numberOfPlugs; i++) { MPlug plug = connectedPlugs[i]; string pInfo = plug.info; MGlobal.displayInfo(pInfoMsg + pInfo); MPlugArray array = new MPlugArray(); plug.connectedTo(array, true, false); string dInfoMsg = MStringResource.getString(rPlugDestOf); for (int j = 0; j < array.length; j++) { MObject mnode = array[j].node; printType(mnode, dInfoMsg); } } } return; }
static public void registerUIString() { MStringResource.registerString(NodeInfoCmd.rConnFound); MStringResource.registerString(NodeInfoCmd.rPlugInfo); MStringResource.registerString(NodeInfoCmd.rPlugDestOf); }