public override void writer(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode)
        {
            string fullName = file.fullName;
            StreamWriter sWriter = new StreamWriter(fullName);
            sWriter.Write("# Simple text file of custom node information" + Environment.NewLine);

            MItDependencyNodes iterator = new MItDependencyNodes();
            while (!iterator.isDone)
            {
                MObject obj = iterator.thisNode;
                try
                {
                    MFnDependencyNode dnFn = new MFnDependencyNode(obj);
                    MPxNode userNode = dnFn.userNode;
                    if (userNode != null)
                        sWriter.Write("# custom node: " + dnFn.name + Environment.NewLine);
                }
                catch (System.Exception)
                {
                }

                iterator.next();
            }
            sWriter.Close();

            return;
        }
        public override void reader(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode)
        {
            string fullName = file.fullName;
            StreamReader sReader = new StreamReader(fullName);
            while (!sReader.EndOfStream)
            {
                string lineStr = sReader.ReadLine();
                processLine(lineStr);
            }
            sReader.Close();

            return;
        }
Exemple #3
0
		//
		// Maya calls this method to have the translator write out a file.
		//
		public override void writer(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode)
		{
			//
			// For simplicity, we only do full saves/exports.
			//
			if ((mode != MPxFileTranslator.FileAccessMode.kSaveAccessMode) && (mode != MPxFileTranslator.FileAccessMode.kExportAccessMode))
                throw new System.NotImplementedException( "We only support support SaveAccessMode and ExportAccessMode");

			//
			// Let's see if we can open the output file.
			//
			FileStream output = null;
			try
			{
                output = new FileStream(file.fullName, FileMode.Create, FileAccess.Write);
			}
			catch (ArgumentException ex)
			{
				MGlobal.displayInfo("File access invalid!");
				if(output != null)
					output.Close();
				throw ex;
			}
			//
			// Get some node flags to keep track of those nodes for which we
			// have already done various stages of processing.
			//
			fCreateFlag = MFnDependencyNode.allocateFlag(fPluginName);

			fAttrFlag = MFnDependencyNode.allocateFlag(fPluginName);

			fConnectionFlag = MFnDependencyNode.allocateFlag(fPluginName);

			//
			// Run through all of the nodes in the scene and clear their flags.
			//
			MItDependencyNodes nodesIter = new MItDependencyNodes();

			for (; !nodesIter.isDone; nodesIter.next())
			{
				MObject node = nodesIter.item;
				MFnDependencyNode nodeFn = new MFnDependencyNode(node);

				nodeFn.setFlag(fCreateFlag, false);
				nodeFn.setFlag(fAttrFlag, false);
				nodeFn.setFlag(fConnectionFlag, false);
			}

			//
			// Write out the various sections of the file.
			//
			writeHeader(output, file.name);
			writeFileInfo(output);
			writeReferences(output);
			writeRequirements(output);
			writeUnits(output);
			writeDagNodes(output);
			writeNonDagNodes(output);
			writeDefaultNodes(output);
			writeReferenceNodes(output);
			writeConnections(output);
			writeFooter(output, file.name);

			output.Close();

			MFnDependencyNode.deallocateFlag(fPluginName, fCreateFlag);

			return;
		}
Exemple #4
0
		public override void reader(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode)
		{
            throw new System.NotImplementedException("We only support support writer not reader");
        }
Exemple #5
0
		public override void reader(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode)
		{
			string fileName = file.fullName;
			// 	Parse the options. The options syntax is in the form of
			//	"flag=val;flag1=val;flag2=val"
			//

			if (optionsString.Length > 0)
			{
				//	Set up the flags for the paste command.
				//
				const string flagTime = "time";
				const string flagCopies = "copies";
				const string flagOption = "option";
				const string flagConnect = "connect";

				string copyValue = "";
				string flagValue = "";
				string connectValue = "";
				string timeValue = "";

				//	Start parsing.
				//
				string[] optionList = optionsString.Split(new Char[] { ';' });
				int nOptions = optionList.Length;
				for (int i = 0; i < nOptions; i++)
				{
					string[] theOption = optionList[i].Split(new Char[] { '=' });
					if (theOption.Length < 1)
						continue;

					if (theOption[0] == flagCopies && theOption.Length > 1)
					{
						copyValue = theOption[1]; ;
					}
					else if (theOption[0] == flagOption && theOption.Length > 1)
					{
						flagValue = theOption[1];
					}
					else if (theOption[0] == flagConnect && theOption.Length > 1)
					{
						if (Convert.ToInt32(theOption[1]) != 0)
							connectValue += theOption[1];
					}
					else if (theOption[0] == flagTime && theOption.Length > 1)
					{
						timeValue += theOption[1];
					}
				}

				if (copyValue.Length > 0)
				{
					pasteFlags += " -copies ";
					pasteFlags += copyValue;
					pasteFlags += " ";
				}
				if (flagValue.Length > 0)
				{
					pasteFlags += " -option \"";
					pasteFlags += flagValue;
					pasteFlags += "\" ";
				}
				if (connectValue.Length > 0)
				{
					pasteFlags += " -connect ";
					pasteFlags += connectValue;
					pasteFlags += " ";
				}
				if (timeValue.Length > 0)
				{
					bool useQuotes = false;
					try
					{
						Convert.ToDouble(timeValue);
					}
					catch (System.Exception)
					{
						useQuotes = true;
					}
					pasteFlags += " -time ";
					if (useQuotes) pasteFlags += "\"";
					pasteFlags += timeValue;
					if (useQuotes) pasteFlags += "\"";
					pasteFlags += " ";
				}
			}

			bool isImported = false;
			if (mode == MPxFileTranslator.FileAccessMode.kImportAccessMode)
				isImported = importAim(fileName, pasteFlags);
			else
				throw new ArgumentException("Invalid File Access mode.", "mode");

			if (!isImported)
			{
				throw new ApplicationException("Importing Anim Failed.");
			}

			return;
		}
Exemple #6
0
		public override void writer(MFileObject file, string options, MPxFileTranslator.FileAccessMode mode)
		{
			string fileName = file.fullName;
			StreamWriter animFile = new StreamWriter(fileName);

			//	Defaults.
			//
			string copyFlags = "copyKey -cb api -fea 1 ";
			int precision = kDefaultPrecision;
			bool nodeNames = true;
			bool verboseUnits = false;

			//	Parse the options. The options syntax is in the form of
			//	"flag=val;flag1=val;flag2=val"
			//
			if (options.Length > 0)
			{
				const string flagPrecision = "precision";
				const string flagNodeNames = "nodeNames";
				const string flagVerboseUnits = "verboseUnits";
				const string flagCopyKeyCmd = "copyKeyCmd";

				//	Start parsing.
				//
				string[] optionList = options.Split(new Char[] { ';' });

				int nOptions = optionList.Length;
				for (int i = 0; i < nOptions; i++)
				{
					string[] theOption = optionList[i].Split(new Char[] { '=' });
					if (theOption.Length < 1)
					{
						continue;
					}

					if (theOption[0] == flagPrecision && theOption.Length > 1)
					{
						precision = Convert.ToInt32(theOption[1]);
					}
					else if (theOption[0] == flagNodeNames && theOption.Length > 1)
					{
						if (Convert.ToInt32(theOption[1]) == 0)
							nodeNames = false;
						else
							nodeNames = true;
					}
					else if (theOption[0] == flagVerboseUnits && theOption.Length > 1)
					{
						if (Convert.ToInt32(theOption[1]) == 0)
							verboseUnits = false;
						else
							verboseUnits = true;
					}
					else if (theOption[0] == flagCopyKeyCmd && theOption.Length > 1)
					{

						//	Replace any '>' characters with '"'. This is needed
						//	since the file translator option boxes do not handle
						//	escaped quotation marks.
						//
						string optStr = theOption[1];
						string copyStr = "";
						for (int j = 0; j < optStr.Length; j++)
						{
							if (optStr[j] == '>')
								copyStr += '"';
							else
								copyStr += optStr[j];
						}

						copyFlags += copyStr;
					}
				}
			}

			//	Set the precision of the ofstream.
			//
			bool isExported = exportSelected(ref animFile, ref copyFlags, nodeNames, verboseUnits);
			animFile.Flush();
			animFile.Close();

			if (!isExported)
			{
				throw new ApplicationException("Exporting Anim Failed.");
			}

			return;
		}