//======================================================================
		//
		// 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");
			}
		}
Esempio n. 2
0
        public override void doIt(MArgList args)
        {
            MArgDatabase argData = new MArgDatabase(syntax, args);

            if (argData.isFlagSet(deregisterFlag))
            {
                string eventName = argData.flagArgumentString(deregisterFlag, 0);
                MUserEventMessage.deregisterUserEvent(eventName);
            }
            else if (argData.isFlagSet(registerFlag))
            {
                // Register the new event and add two fixed callbacks to it.
                string eventName = argData.flagArgumentString(registerFlag, 0);
                if (!MUserEventMessage.isUserEvent(eventName))
                {
                    MUserEventMessage.registerUserEvent(eventName);

                    userCB cb1 = new userCB();
                    cb1.clientData = "Sample Client Data (an MString object)";
                    MUserEventMessage.UserEvent[eventName] += cb1.userCallback1;
                    MUserEventMessage.UserEvent[eventName] += cb1.userCallback2;
                }
            }
            else if (argData.isFlagSet(postFlag))
            {
                string eventName = argData.flagArgumentString(postFlag, 0);
                MUserEventMessage.postUserEvent(eventName);
            }
            else if (argData.isFlagSet(testFlag))
            {
                runTests();
            }

            return;
        }
Esempio n. 3
0
        protected override bool parseArgs(MArgList argList)
        {
            MArgDatabase argData;

            argData = new MArgDatabase(_syntax, argList);

            // Settings only work at creation time. Would need an
            // attribute on the node in order to push this state
            // into the node at any time.
            ConstraintType typ;

            if (argData.isFlagSet(kConstrainToLargestWeightFlag))
            {
                typ = GeometrySurfaceConstraintCommand.ConstraintType.kLargestWeight;
            }
            else if (argData.isFlagSet(kConstrainToSmallestWeightFlag))
            {
                typ = GeometrySurfaceConstraintCommand.ConstraintType.kSmallestWeight;
            }
            else
            {
                typ = GeometrySurfaceConstraintCommand.ConstraintType.kLargestWeight;
            }
            weightType = typ;

            // Need parent to process
            return(false);
        }
Esempio n. 4
0
        public override void doIt(MArgList args)
        {
            MArgDatabase argData = new MArgDatabase(syntax, args);

            bool creating = true;

            if (argData.isFlagSet(kCreateFlag))
            {
                creating = true;
            }
            else if (argData.isFlagSet(kDeleteFlag))
            {
                creating = false;
            }
            else
            {
                throw new ArgumentException("Command Syntax is incorrect", "args");
            }

            if (creating)
            {
                lineManipObj = modifier.createNode("simpleLineManipCSharp", MObject.kNullObj);
            }
            else
            {
                if (lineManipObj != null)
                {
                    modifier.deleteNode(lineManipObj);
                }
                lineManipObj = null;
            }

            redoIt();
        }
Esempio n. 5
0
        public override void doIt(MArgList args)
        {
            string fileName;

            MArgDatabase argData = new MArgDatabase(syntax, args);

            if (argData.isFlagSet(kFileNameFlag))
            {
                fileName = argData.flagArgumentString(kFileNameFlag, 0);

                if (fileName != null)
                {
                    string currFile = MFileIO.fileCurrentlyLoading;

                    MStringArray pathDirectories = new MStringArray(currFile.Split('/'));

                    if (pathDirectories.length > 0)
                    {
                        string expandedFileName = "";

                        for (int i = 0; i < pathDirectories.length - 1; i++)
                        {
                            expandedFileName += pathDirectories[i];
                            expandedFileName += "/";
                        }

                        expandedFileName += fileName;

                        MGlobal.sourceFile(expandedFileName);
                    }
                }
            }

            return;
        }
Esempio n. 6
0
        override public void doIt(MArgList args)
        {
            MSyntax syntax = new MSyntax();

            syntax.addArg(MSyntax.MArgType.kDouble);
            syntax.addArg(MSyntax.MArgType.kDouble);
            syntax.addArg(MSyntax.MArgType.kDouble);

            MArgDatabase argData = new MArgDatabase(syntax, args);

            MVector vector = MVector.xAxis;

            if (args.length == 1)
            {
                vector.x = args.asDouble(0);
            }
            else if (args.length == 2)
            {
                vector.x = args.asDouble(0);
                vector.y = args.asDouble(1);
            }
            else if (args.length == 3)
            {
                uint i = 0;
                vector = args.asVector(ref i);
            }
            __delta = vector;
            __action(MoveToolAction.kDoIt);
            return;
        }
Esempio n. 7
0
        //======================================================================
        //
        // 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");
            }
        }
Esempio n. 8
0
	    public void parse(ref MArgDatabase argDb, String name)
	    {
		    fIsSet = argDb.isFlagSet(name);
            if (fIsSet == false)
                return;
            argDb.getFlagArgument(name, 0, out fArg);
		    fIsArgValid = fArg.Length > 0;
	    }
Esempio n. 9
0
        //======================================================================
        //
        // 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);
            }
        }
Esempio n. 10
0
 public void parse(ref MArgDatabase argDb, String name)
 {
     fIsSet = argDb.isFlagSet(name);
     if (fIsSet == false)
     {
         return;
     }
     argDb.getFlagArgument(name, 0, out fArg);
     fIsArgValid = fArg.Length > 0;
 }
Esempio n. 11
0
        //======================================================================
        //
        // 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);
            }
        }
Esempio n. 12
0
        bool flipGlobal = false;						// Flip globally or per shell


        public override void parseSyntax(MArgDatabase argData)
        {
            if (argData.isFlagSet(horizFlag))
                horizontal =argData.flagArgumentBool(horizFlag, 0);

            if (argData.isFlagSet(globalFlag))
                flipGlobal = argData.flagArgumentBool(globalFlag, 0);

            if (argData.isFlagSet(extendFlag))
                extendToShell = argData.flagArgumentBool(extendFlag, 0);

            return;
        }
Esempio n. 13
0
        public override void doIt(MArgList args)
        {
	        MArgDatabase argsDb = new MArgDatabase(syntax, args);

            checkArgs(argsDb);
		    clearResult();
		    switch (fMode)
		    {
                case CommandMode.kCreate: doCreate(); break;
                case CommandMode.kEdit: doEdit(); break;
                case CommandMode.kQuery: doQuery(); break;
		    }
        }
Esempio n. 14
0
        public override void checkArgs(MArgDatabase argsDb)
        {
            if (argsDb.isFlagSet(kFileNameFlag))
            {
                fileName = argsDb.flagArgumentString(kFileNameFlag, 0);

                if (fileName == null)
                {
                    throw new System.ApplicationException("ExportMetadataCmd: You must specify the output path ex: -fn c:/mypath/thefile.meta.");
                }
            }
            base.checkArgs(argsDb);
        }
Esempio n. 15
0
        public override void checkArgs(MArgDatabase argsDb)
        {
            if (argsDb.isFlagSet(kFileNameFlag))
            {
                fileName = argsDb.flagArgumentString(kFileNameFlag, 0);

                if (fileName == null)
                {
                    throw new System.ApplicationException("ExportMetadataCmd: You must specify the output path ex: -fn c:/mypath/thefile.meta.");
                }
            }
            base.checkArgs(argsDb);
        }
Esempio n. 16
0
        public override void doIt(MArgList args)
        {
            MArgDatabase argsDb = new MArgDatabase(syntax, args);

            checkArgs(argsDb);
            clearResult();
            switch (fMode)
            {
            case CommandMode.kCreate: doCreate(); break;

            case CommandMode.kEdit: doEdit(); break;

            case CommandMode.kQuery: doQuery(); break;
            }
        }
Esempio n. 17
0
        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;
            }
        }
Esempio n. 18
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");
            }
        }
Esempio n. 19
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");
			}
		}
Esempio n. 20
0
        bool flipGlobal = false;                                                // Flip globally or per shell


        public override void parseSyntax(MArgDatabase argData)
        {
            if (argData.isFlagSet(horizFlag))
            {
                horizontal = argData.flagArgumentBool(horizFlag, 0);
            }

            if (argData.isFlagSet(globalFlag))
            {
                flipGlobal = argData.flagArgumentBool(globalFlag, 0);
            }

            if (argData.isFlagSet(extendFlag))
            {
                extendToShell = argData.flagArgumentBool(extendFlag, 0);
            }

            return;
        }
Esempio n. 21
0
        private void parseArgs(MArgList args)
        {
            MArgDatabase argData = new MArgDatabase(syntax, args);

            if (argData.isFlagSet(kMessageFlag))
            {
                bool flag;
                try
                {
                    flag = argData.flagArgumentBool(kMessageFlag, 0);
                }
                catch (System.Exception)
                {
                    throw new ArgumentException("could not parse message flag", "args");
                }

                addMessage = flag;
                delMessage = !flag;
            }

            MStringArray evts;

            try
            {
                evts = argData.objects;

                if (evts.length == 0)
                {
                    events = eventNames.ToArray();
                }
                else
                {
                    evts.get(out events);
                }
            }
            catch (System.Exception)
            {
                displayError("could not parse condition names");
            }
        }
Esempio n. 22
0
		override public void doIt(MArgList args)
		{
			MSyntax syntax = new MSyntax();
			syntax.addArg(MSyntax.MArgType.kDouble);
			syntax.addArg(MSyntax.MArgType.kDouble);
			syntax.addArg(MSyntax.MArgType.kDouble);

			MArgDatabase argData = new MArgDatabase(syntax, args);

			MVector vector = MVector.xAxis ;
			if ( args.length == 1 ) {
				vector.x =args.asDouble (0) ;
			} else if ( args.length == 2 ) {
				vector.x =args.asDouble (0) ;
				vector.y =args.asDouble (1) ;
			} else if ( args.length == 3 ) {
				uint i =0 ;
				vector = args.asVector(ref i);
			}
			__delta = vector;
			__action (MoveToolAction.kDoIt) ;
			return;
		}
Esempio n. 23
0
        public override void doIt(MArgList argList)
        {
            MArgDatabase argData = new MArgDatabase(syntax, argList);

            // Retrieve pass Id. The pass flag must be set.
            string passId = argData.isFlagSet(PassFlag[0]) ? argData.flagArgumentString(PassFlag[0], 0) : "";

            if (passId.Length <= 0)
            {
                throw new System.ArgumentException("The pass flag is not set", "argList");
            }

            MRenderPassDef def = null;

            try {
                def = MRenderPassRegistry.getRenderPassDefinition(passId);
            } catch (System.Exception) {
                setResult(false);
                return;
            }

            // implementation information
            string renderer = argData.isFlagSet(RendererFlag[0]) ? argData.flagArgumentString(RendererFlag[0], 0) : "";

            if (renderer.Length > 0)
            {
                MPxRenderPassImpl impl = null;
                try {
                    impl = def.getImplementation(renderer);
                } catch (System.Exception) {
                    // impl info requested but does not exist, stop here
                    setResult(false);
                    return;
                }

                if (argData.isFlagSet(TypesFlag[0]))
                {
                    uint   types  = impl.typesSupported();
                    string result = getTypeStrings(types);
                    setResult(result);
                }
                else if (argData.isFlagSet(DefaultTypeFlag[0]))
                {
                    uint   type   = (uint)impl.getDefaultType();
                    string result = getTypeStrings(type);
                    setResult(result);
                }
                else if (argData.isFlagSet(NumChannelsFlag[0]))
                {
                    uint result = impl.getNumChannels();
                    setResult(result);
                }
                else if (argData.isFlagSet(SemanticFlag[0]))
                {
                    string result = getSemanticString(impl.frameBufferSemantic());
                    setResult(result);
                }
                else if (argData.isFlagSet(PerLightFlag[0]))
                {
                    bool result = impl.perLightPassContributionSupported();
                    setResult(result);
                }
                else if (argData.isFlagSet(CompatFlag[0]))
                {
                    string fCompat = argData.flagArgumentString(CompatFlag[0], 0);
                    bool   result  = impl.isCompatible(fCompat);
                    setResult(result);
                }
                else
                {
                    // just indicate the implementation exists
                    setResult(true);
                }
            }
            else
            {
                // pass information
                if (argData.isFlagSet(NameFlag[0]))
                {
                    setResult(def.getName());
                }
                else if (argData.isFlagSet(GroupFlag[0]))
                {
                    setResult(def.getGroup());
                }
                else if (argData.isFlagSet(DescriptionFlag[0]))
                {
                    setResult(def.getDescription());
                }
                else
                {
                    // just indicate the definition exists
                    setResult(true);
                }
            }

            return;
        }
Esempio n. 24
0
		public override void doIt(MArgList argList)
		{
			MArgDatabase argData = new MArgDatabase(syntax, argList);

			// Retrieve pass Id. The pass flag must be set.
			string passId = argData.isFlagSet(PassFlag[0]) ? argData.flagArgumentString(PassFlag[0], 0) : "";
			if (passId.Length <= 0)
				throw new System.ArgumentException("The pass flag is not set", "argList");

			MRenderPassDef def = null;
			try {
				def = MRenderPassRegistry.getRenderPassDefinition(passId);
			} catch (System.Exception) {
				setResult(false);
				return;
			}

			// implementation information
			string renderer = argData.isFlagSet(RendererFlag[0]) ? argData.flagArgumentString(RendererFlag[0], 0) : "";
			if (renderer.Length > 0) {
				MPxRenderPassImpl impl = null;
				try {
					impl = def.getImplementation(renderer);
				} catch (System.Exception) {
					// impl info requested but does not exist, stop here
					setResult(false);
                    return;
				}
				
				if (argData.isFlagSet(TypesFlag[0])) {
					uint types = impl.typesSupported();
					string result = getTypeStrings(types);
					setResult(result);
				} else if (argData.isFlagSet(DefaultTypeFlag[0])) {
					uint type = (uint)impl.getDefaultType();
					string result = getTypeStrings(type);
					setResult(result);
				} else if (argData.isFlagSet(NumChannelsFlag[0])) {
					uint result = impl.getNumChannels();
					setResult(result);
				} else if (argData.isFlagSet(SemanticFlag[0])) {
					string result = getSemanticString(impl.frameBufferSemantic());
					setResult(result);
				} else if (argData.isFlagSet(PerLightFlag[0])) {
					bool result = impl.perLightPassContributionSupported();
					setResult(result);
				} else if (argData.isFlagSet(CompatFlag[0])) {
					string fCompat = argData.flagArgumentString(CompatFlag[0], 0);
					bool result = impl.isCompatible(fCompat);
					setResult(result);
				} else {
					// just indicate the implementation exists
					setResult(true);
				}
			} else {
				// pass information
				if (argData.isFlagSet(NameFlag[0])) {
						setResult(def.getName());
				} else if (argData.isFlagSet(GroupFlag[0])) {
						setResult(def.getGroup());
				} else if (argData.isFlagSet(DescriptionFlag[0])) {
						setResult(def.getDescription());
				} else {
					// just indicate the definition exists
					setResult(true);
				}
			}

			return;
		}
Esempio n. 25
0
        public override void doIt(MArgList args /*, MPxCommandClass cmd*/)
        {
            // This method is called from script when this command is called.
            // It should set up any class data necessary for redo/undo,
            // parse any given arguments, and then call redoIt.
            MArgDatabase argData = new MArgDatabase(/*cmd.*/ syntax, args);

            __isIndex = argData.isFlagSet(kIndexFlag);

            // Get the plug specified on the command line.
            MSelectionList slist = argData.SelectionObjects;

            if (slist.length == 0)
            {
                throw new ArgumentException("Must specify an array plug in the form <nodeName>.<multiPlugName>.", "args");
            }
            __fPlug = slist.getPlug(0);
            if (__fPlug == null)
            {
                throw new ArgumentException("Must specify an array plug in the form <nodeName>.<multiPlugName>.", "args");
            }

            // Construct a data handle containing the data stored in the plug.
            MDataHandle dh = new MDataHandle();

            try {
                __fPlug.getValue(dh);
            } catch (Exception) {
                throw new ApplicationException("Could not get the plug value.");
            }

            MArrayDataHandle adh;
            uint             indx = 0;

            try {
                adh = new MArrayDataHandle(dh);
            } catch (Exception) {
                __fPlug.destructHandle(dh);
                throw new ApplicationException("Could not create the array data handle.");
            }

            // Iterate over the values in the multiPlug.  If the index flag has been used, just return
            // the logical indices of the child plugs.  Otherwise, return the plug values.
            string errorMsg = null;

            for (uint i = 0; i < adh.elementCount(); i++, adh.next())
            {
                try {
                    indx = adh.elementIndex();
                } catch (Exception) {
                    continue;
                }
                if (__isIndex)
                {
                    appendToResult((int)indx);
                }
                else
                {
                    MDataHandle h = adh.outputValue();
                    if (h.isNumeric)
                    {
                        switch (h.numericType)
                        {
                        case MFnNumericData.Type.kBoolean: appendToResult(h.asBool); break;

                        case MFnNumericData.Type.kShort: appendToResult(h.asShort); break;

                        case MFnNumericData.Type.kInt: appendToResult(h.asInt); break;

                        case MFnNumericData.Type.kFloat: appendToResult(h.asFloat); break;

                        case MFnNumericData.Type.kDouble: appendToResult(h.asDouble); break;

                        default:
                            errorMsg = string.Format("{0}This sample command only supports boolean, integer, and floating point values. Not {1}.\n",
                                                     errorMsg != null ? errorMsg : "", h.numericType.ToString());

                            break;
                        }
                    }
                }
            }
            __fPlug.destructHandle(dh);

            if (errorMsg != null)
            {
                throw new ApplicationException(errorMsg);
            }
            ;

            return;
        }
Esempio n. 26
0
		public override void doIt(MArgList args/*, MPxCommandClass cmd*/)
		{
			// This method is called from script when this command is called.
			// It should set up any class data necessary for redo/undo,
			// parse any given arguments, and then call redoIt.
			MArgDatabase argData = new MArgDatabase(/*cmd.*/syntax, args);

            __isIndex = argData.isFlagSet(kIndexFlag);

			// Get the plug specified on the command line.
			MSelectionList slist = argData.SelectionObjects;
			if ( slist.length == 0 ) {
				throw new ArgumentException("Must specify an array plug in the form <nodeName>.<multiPlugName>.", "args");
			}
			__fPlug = slist.getPlug (0) ;
			if ( __fPlug == null ) {
				throw new ArgumentException("Must specify an array plug in the form <nodeName>.<multiPlugName>.", "args");
			}

			// Construct a data handle containing the data stored in the plug.
			MDataHandle dh = new MDataHandle() ;

            try {
                __fPlug.getValue(dh);
            } catch (Exception) {
                throw new ApplicationException("Could not get the plug value.");
            }

			MArrayDataHandle adh ;
			uint indx =0 ;
			try {
				adh = new MArrayDataHandle(dh);
			} catch (Exception) {
				__fPlug.destructHandle(dh) ;
				throw new ApplicationException("Could not create the array data handle.");
			}

			// Iterate over the values in the multiPlug.  If the index flag has been used, just return
			// the logical indices of the child plugs.  Otherwise, return the plug values.
            string errorMsg = null;
            for (uint i = 0; i < adh.elementCount(); i++, adh.next())
            {
				try {
					indx = adh.elementIndex() ;
				} catch (Exception) {
					continue ;
				}
				if ( __isIndex ) {
					appendToResult ((int)indx) ;
				} else {
					MDataHandle h = adh.outputValue () ;
					if (h.isNumeric)
					{
						switch (h.numericType)
						{
							case MFnNumericData.Type.kBoolean: appendToResult (h.asBool) ; break;
							case MFnNumericData.Type.kShort: appendToResult (h.asShort) ; break;
							case MFnNumericData.Type.kInt: appendToResult (h.asInt) ; break;
							case MFnNumericData.Type.kFloat: appendToResult (h.asFloat) ; break;
							case MFnNumericData.Type.kDouble: appendToResult (h.asDouble) ; break;
							default:
                                errorMsg = string.Format("{0}This sample command only supports boolean, integer, and floating point values. Not {1}.\n",
                                    errorMsg != null ? errorMsg : "", h.numericType.ToString());

								break;
						}
					}
				}
			}
			__fPlug.destructHandle (dh) ;

            if (errorMsg != null)
                throw new ApplicationException(errorMsg); ;

			return;
		}
Esempio n. 27
0
		//======================================================================
		//
		// 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 );

			}
		}
Esempio n. 28
0
        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;
        }
Esempio n. 29
0
        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;
        }
Esempio n. 30
0
        //======================================================================
        //
        // 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");
            }
        }
Esempio n. 31
0
		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;
			}
		}
Esempio n. 32
0
        //======================================================================
        //
        // 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);
            }
        }
Esempio n. 33
0
        public override 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;
        }
Esempio n. 34
0
        private void parseArgs(MArgList args)
        {
            MArgDatabase argData = new MArgDatabase(syntax, args);

            if(argData.isFlagSet(kMessageFlag))
            {
                bool flag;
                try
                {
                    flag = argData.flagArgumentBool(kMessageFlag, 0);
                }
                catch (System.Exception)
                {
                    throw new ArgumentException("could not parse message flag", "args");
                }

                addMessage = flag;
                delMessage = !flag;
            }

            MStringArray evts;
            try
            {
                evts = argData.objects;

                if (evts.length == 0)
                    events = eventNames.ToArray();
                else
                    evts.get(out events);
            }
            catch (System.Exception)
            {
                displayError("could not parse condition names");
            }
        }
Esempio n. 35
0
		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;
		}
Esempio n. 36
0
		//======================================================================
		//
		// 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] );
                }
            }
		}
Esempio n. 37
0
        public override void doIt(MArgList args)
        {
            MArgDatabase argData = new MArgDatabase(syntax, args);

            bool creating = true;
            if ( argData.isFlagSet( kCreateFlag ) )
                creating = true;
            else if ( argData.isFlagSet( kDeleteFlag ) )
                creating = false;
            else
                throw new ArgumentException("Command Syntax is incorrect", "args");

            if (creating)
            {
                lineManipObj = modifier.createNode("simpleLineManipCSharp", MObject.kNullObj);
            }
            else
            {
                if (lineManipObj != null)
                {
                    modifier.deleteNode(lineManipObj);
                }
                lineManipObj = null;
            }

            redoIt();
        }
Esempio n. 38
0
        //======================================================================
        //
        // 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;

            for (int 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);

                Console.WriteLine("METADATA for node " + dagNode.fullPathName);
                Console.WriteLine("=====================================================================");

                foreach (Channel chn in node.metadata)
                {
                    Console.WriteLine("Channel: type = {0}, nbStreams = {1}", chn.nameProperty, chn.dataStreamCount);
                    foreach (Stream strm in chn)
                    {
                        Console.WriteLine("Stream: name = {0}, nbElements = {1}", strm.name, strm.elementCount());

                        Structure strct = strm.structure;

                        Console.WriteLine("Structure: name = {0}, nbMembers = {1}", strct.name, strct.memberCount);

                        string[] memberNames = new string[strct.memberCount];
                        int      memberID    = -1;
                        foreach (Member member in strct)
                        {
                            ++memberID;
                            Console.WriteLine("Structure member: name = {0}, type = {1}, array size = {2}", member.nameProperty, member.typeProperty.ToString(), member.lengthProperty);
                            memberNames[memberID] = member.nameProperty;
                        }

                        int k = -1;

                        foreach (Handle handle in strm)
                        {
                            ++k;
                            for (uint n = 0; n < strct.memberCount; ++n)
                            {
                                handle.setPositionByMemberIndex(n);

                                Array data = handle.asType;

                                if (data.Length < 1)
                                {
                                    throw new ApplicationException("Handle data seems corrupted");
                                }

                                string line = string.Format("Handle #{0}, member = {1}, data = {2}", k, memberNames[n], data.GetValue(0).ToString());

                                if (data.Length > 1)
                                {
                                    for (int d = 1; d < data.Length; ++d)
                                    {
                                        line = line + "," + data.GetValue(d).ToString();
                                    }
                                }

                                Console.WriteLine(line);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 39
0
        public override void doIt(MArgList args)
        {
            string fileName;

            MArgDatabase argData = new MArgDatabase(syntax, args);
          
            if (argData.isFlagSet(kFileNameFlag))
            {
	            fileName = argData.flagArgumentString(kFileNameFlag, 0);

	            if (fileName != null)
	            {
		            string currFile = MFileIO.fileCurrentlyLoading;

		            MStringArray pathDirectories = new MStringArray(currFile.Split('/'));

		            if (pathDirectories.length > 0)
		            {
			            string expandedFileName = "";

			            for (int i = 0; i < pathDirectories.length-1; i++)
			            {
				            expandedFileName += pathDirectories[i];
				            expandedFileName += "/";
			            }

			            expandedFileName += fileName;

			            MGlobal.sourceFile(expandedFileName);
		            }
	            }
            }	

            return;
        }
Esempio n. 40
0
		//======================================================================
		//
		// 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;
			for ( int 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);

                Console.WriteLine( "METADATA for node " + dagNode.fullPathName );
                Console.WriteLine( "=====================================================================" );

                foreach( Channel chn in node.metadata)
                {
                    Console.WriteLine("Channel: type = {0}, nbStreams = {1}", chn.nameProperty, chn.dataStreamCount);
                    foreach (Stream strm in chn)
                    {
                        Console.WriteLine("Stream: name = {0}, nbElements = {1}", strm.name, strm.elementCount() );

                        Structure strct = strm.structure;

                        Console.WriteLine("Structure: name = {0}, nbMembers = {1}", strct.name, strct.memberCount );

                        string[] memberNames = new string[strct.memberCount];
                        int memberID = -1;
                        foreach( Member member in strct )
                        {
                            ++memberID;
                            Console.WriteLine("Structure member: name = {0}, type = {1}, array size = {2}", member.nameProperty, member.typeProperty.ToString(), member.lengthProperty );
                            memberNames[memberID] = member.nameProperty;
                        }
                        
                        int k = -1;

                        foreach (Handle handle in strm)
                        {
                            ++k;
                            for (uint n = 0; n < strct.memberCount; ++n)
                            {
                                handle.setPositionByMemberIndex(n);

                                Array data = handle.asType;

                                if( data.Length < 1 )
                                    throw new ApplicationException( "Handle data seems corrupted" );

                                string line = string.Format( "Handle #{0}, member = {1}, data = {2}", k, memberNames[n], data.GetValue(0).ToString() );

                                if( data.Length > 1 )
                                {
                                    for( int d = 1; d < data.Length; ++d )
                                    {
                                        line = line + "," + data.GetValue(d).ToString();
                                    }
                                }

                                Console.WriteLine( line );
                            }
                        }
                    }
                }
			}
		}
        protected override bool parseArgs( MArgList argList)
        {
            MArgDatabase argData;
            argData = new MArgDatabase(_syntax, argList);

            // Settings only work at creation time. Would need an
            // attribute on the node in order to push this state
            // into the node at any time.
            ConstraintType typ;
            if (argData.isFlagSet(kConstrainToLargestWeightFlag))
                typ = GeometrySurfaceConstraintCommand.ConstraintType.kLargestWeight;
            else if (argData.isFlagSet(kConstrainToSmallestWeightFlag))
                typ = GeometrySurfaceConstraintCommand.ConstraintType.kSmallestWeight;
            else
                typ = GeometrySurfaceConstraintCommand.ConstraintType.kLargestWeight;
            weightType = typ;

            // Need parent to process
            return false;
        }
Esempio n. 42
0
        //======================================================================
        //
        // 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]);
                }
            }
        }
Esempio n. 43
0
		//======================================================================
		//
		// 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");
			}
		}
Esempio n. 44
0
		public override void doIt(MArgList args)
		{
			MArgDatabase argData = new MArgDatabase(syntax, args);

			if (argData.isFlagSet(deregisterFlag))
			{
				string eventName = argData.flagArgumentString(deregisterFlag, 0);
				MUserEventMessage.deregisterUserEvent(eventName);
			}
			else if (argData.isFlagSet(registerFlag))
			{
				// Register the new event and add two fixed callbacks to it.
				string eventName = argData.flagArgumentString(registerFlag, 0);
				if (!MUserEventMessage.isUserEvent(eventName))
				{
					MUserEventMessage.registerUserEvent(eventName);
                    
                    userCB cb1 = new userCB();
                    cb1.clientData = "Sample Client Data (an MString object)";
                    MUserEventMessage.UserEvent[eventName] += cb1.userCallback1;
                    MUserEventMessage.UserEvent[eventName] += cb1.userCallback2;
				}
			}
			else if (argData.isFlagSet(postFlag))
			{
				string eventName = argData.flagArgumentString(postFlag, 0);
				MUserEventMessage.postUserEvent(eventName);
			}
			else if (argData.isFlagSet(testFlag))
			{
				runTests();
			}

			return;
		}