void PrintAttributes(MFnDependencyNode dependencyNode, int logRank)
        {
            // prints
            RaiseVerbose("Attributes", logRank);
            for (uint i = 0; i < dependencyNode.attributeCount; i++)
            {
                MObject attribute = dependencyNode.attribute(i);

                if (attribute.hasFn(MFn.Type.kAttribute))
                {
                    MFnAttribute mFnAttribute = new MFnAttribute(attribute);
                    RaiseVerbose("name=" + mFnAttribute.name + "    apiType=" + attribute.apiType, logRank + 1);
                }
            }
        }
Example #2
0
        void Print(MFnDependencyNode dependencyNode, int logRank, string title)
        {
            // prints
            RaiseVerbose(title, logRank);
            RaiseVerbose("Attributes", logRank + 1);
            for (uint i = 0; i < dependencyNode.attributeCount; i++)
            {
                MObject attribute = dependencyNode.attribute(i);

                if (attribute.hasFn(MFn.Type.kAttribute))
                {
                    MFnAttribute mFnAttribute = new MFnAttribute(attribute);
                    RaiseVerbose("name=" + mFnAttribute.name, logRank + 2);
                }
            }
            RaiseVerbose("Connections", logRank + 1);
            MPlugArray connections = new MPlugArray();

            try {
                dependencyNode.getConnections(connections);
                RaiseVerbose("connections.Count=" + connections.Count, logRank + 2);
                foreach (MPlug connection in connections)
                {
                    MObject source = connection.source.node;
                    if (source != null && source.hasFn(MFn.Type.kDependencyNode))
                    {
                        MFnDependencyNode node = new MFnDependencyNode(source);
                        RaiseVerbose("name=" + connection.name + "    source=" + node.name, logRank + 2);
                    }
                    else
                    {
                        RaiseVerbose("name=" + connection.name, logRank + 2);
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
Example #3
0
		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]);
					}
				}
			}
		}
Example #4
0
		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);
						}
					}
				}
			}
		}
Example #5
0
		//
		// Write the 'connectAttr' commands for all of a node's incoming
		// connections.
		//
		protected void writeNodeConnections(FileStream f, MObject node)
		{
			MFnDependencyNode	nodeFn = new MFnDependencyNode(node);
			MPlugArray			plugs = new MPlugArray();

            try
            {
                nodeFn.getConnections(plugs);
            }
            catch (Exception)
            {
            }

			uint numBrokenConns = fBrokenConnSrcs.length;
			uint numPlugs = plugs.length;
			int i;
			string result = "";
			for (i = 0; i < numPlugs; i++)
			{
				//
				// We only care about connections where we are the destination.
				//
				MPlug		destPlug = plugs[i];
				MPlugArray	srcPlug = new MPlugArray();

				destPlug.connectedTo(srcPlug, true, false);

				if (srcPlug.length > 0)
				{
					MObject				srcNode = srcPlug[0].node;
					MFnDependencyNode	srcNodeFn = new MFnDependencyNode(srcNode);

					//
					// Don't write the connection if the source is not writable...
					//
					if (!srcNodeFn.canBeWritten) continue;

					//
					// or the connection was made in a referenced file...
					//
					if (destPlug.isFromReferencedFile) continue;

					//
					// or the plug is procedural...
					//
					if (destPlug.isProcedural) continue;

					//
					// or it is a connection between a default node and a shared
					// node (because those will get set up automatically).
					//
					if (srcNodeFn.isDefaultNode && nodeFn.isShared) continue;

					result += "connectAttr \"";

					//
					// Default nodes get a colon at the start of their names.
					//
					if (srcNodeFn.isDefaultNode) result += ":";

					result += (srcPlug[0].partialName(true)
					  + "\" \"");

					if (nodeFn.isDefaultNode) result += ":";

					result += (destPlug.partialName(true)
					  + "\"");

					//
					// If the src plug is also one from which a broken
					// connection originated, then add the "-rd/referenceDest" flag
					// to the command.  That will help Maya to better adjust if the
					// referenced file has changed the next time it is loaded.
					//
					if (srcNodeFn.isFromReferencedFile)
					{
						int j;

						for (j = 0; j < numBrokenConns; j++)
						{
							if (fBrokenConnSrcs[j] == srcPlug[0])
							{
								result += (" -rd \""
								  + fBrokenConnDests[j].partialName(true)
								  + "\"");

								break;
							}
						}
					}

					//
					// If the plug is locked, then add a "-l/lock" flag to the
					// command.
					//
					if (destPlug.isLocked) result += " -l on";

					//
					// If the destination attribute is a multi for which index
					// does not matter, then we must add the "-na/nextAvailable"
					// flag to the command.
					//
					MObject			attr = destPlug.attribute;
					MFnAttribute	attrFn = new MFnAttribute(attr);

					if (!attrFn.indexMatters) result += " -na";

					result += (";" + "\n");
				}
			}
			writeString(f, result);
		}
Example #6
0
		//
		// Write the 'disconnectAttr' statements for those connections which were
		// made in referenced files, but broken in the main scene.
		//
		protected void writeBrokenRefConnections(FileStream f)
		{
			uint numBrokenConnections = fBrokenConnSrcs.length;
			int i;
			string result = "";
			for (i = 0; i < numBrokenConnections; i++)
			{
				result += ("disconnectAttr \"" 
					+  fBrokenConnSrcs[i].partialName(true) 
					+ "\" \"" + fBrokenConnDests[i].partialName(true) 
					+ "\"");
				//
				// If the destination plug is a multi for which index does not
				// matter, then we must add a "-na/nextAvailable" flag to the
				// command.
				//
				MObject			attr = fBrokenConnDests[i].attribute;
				MFnAttribute	attrFn = new MFnAttribute(attr);

				if (!attrFn.indexMatters) result += " -na";

				result += (";" + "\n");
			}
			writeString(f, result);
		}