string GetMayaWindowName()
        {
            MGlobal.executePythonCommand("import maya.cmds as cmds");
            string totalMenuName = MGlobal.executePythonCommandStringResult("cmds.menu(parent=mel.eval('$temp1=$gMainWindow'), label='InazumaTool',tearOff = True)");

            return(totalMenuName);
        }
        bool IExtensionPlugin.UninitializePlugin()
        {
            //MFnPluginData plugin = new MFnPluginData();
            subMenuDic.Clear();
            commandDic.Clear();
            cds.Clear();


            string menus = MGlobal.executePythonCommandStringResult("cmds.window(mel.eval('$temp1=$gMainWindow'), q=True, menuArray=True)");

            //BasicFunc.Print(menus);
            menus.TrimStart('[');
            menus.TrimEnd(']');
            string[] menuNames = menus.Split(',');
            for (int i = 0; i < menuNames.Length; i++)
            {
                //BasicFunc.Print(menuNames[i]);
                string labelName = MGlobal.executePythonCommandStringResult("cmds.menu(" + menuNames[i] + ",q=True,label=True)");
                if (labelName == "InazumaTool")
                {
                    MGlobal.executePythonCommand("cmds.deleteUI(" + menuNames[i] + ",m=True)");
                }
            }
            Debug.Log("-远征去了-");
            return(true);
        }
Beispiel #3
0
        public static MDagPath Duplicate(MDagPath targetDag)
        {
            string resultName = MGlobal.executePythonCommandStringResult(string.Format("cmds.duplicate(\"{0}\",rr = 1)", targetDag.fullPathName), true);

            Debug.Log("duplicate result:" + resultName);
            resultName = SubUShell(resultName);
            return(GetDagPathByName(resultName));
        }
        string AddSubMenu(string parentMenuName, string labelStr, bool tearOff)
        {
            MGlobal.executePythonCommand("import maya.cmds as cmds");
            string cmdStr = (tearOff ? "cmds.menuItem(tearOff = True, parent='" : "cmds.menuItem(parent='") + parentMenuName + "',subMenu = True, label='" + labelStr + "')";
            //Debug.Log("cmdStr:" + cmdStr);
            string subMenuName = MGlobal.executePythonCommandStringResult(cmdStr);

            return(subMenuName);
        }
        public static void MakeJointsHairChain(MSelectionList jointDagPaths)
        {
            //begin convert curve to dynamic
            MDagPath curveDagPath = CreateJointsCurve(jointDagPaths);
            string   cmdStr       = "cmds.makeCurveDynamic(0,0,0,1,0)";
            string   resultStr    = MGlobal.executePythonCommandStringResult(cmdStr);

            //string resultStr = MGlobal.executeCommandStringResult("makeCurvesDynamic 2 {\"0\",\"0\",\"0\",\"1\",\"0\"}");
            MGlobal.displayInfo("message" + resultStr);
        }
        public static string[] AddIKHandle(MDagPath startJointDagPath, MDagPath endJointDagPath, IKSolverType solverType = IKSolverType.RotatePlane, string curveName = "")
        {
            //string typeStr = "";
            string resultStr = "";

            CmdStrConstructor csc = new CmdStrConstructor("ikHandle", CmdStrConstructor.CmdType.Python);

            csc.UpdateParm("sj", startJointDagPath.fullPathName);
            csc.UpdateParm("ee", endJointDagPath.fullPathName);

            string ikMainName = startJointDagPath.partialPathName + "_" + endJointDagPath.partialPathName;

            switch (solverType)
            {
            case IKSolverType.SingleChain:
            {
                csc.UpdateParm("sol", "ikSCsolver");
                csc.UpdateParm("n", "ik_" + ikMainName);
                string excuteStr = csc.ToString();
                resultStr = MGlobal.executePythonCommandStringResult(excuteStr);
                //typeStr = "ikSCsolver";
                //resultStr = MGlobal.executePythonCommandStringResult("cmds.ikHandle(sj='" + startJointDagPath.fullPathName + "',ee='" + endJointDagPath.fullPathName + "',sol='" + typeStr + "',n='ik_" + ikMainName + "')");
                break;
            }

            case IKSolverType.RotatePlane:
            {
                csc.UpdateParm("sol", "ikRPsolver");
                csc.UpdateParm("n", "ik_" + ikMainName);
                string excuteStr = csc.ToString();
                resultStr = MGlobal.executePythonCommandStringResult(excuteStr);
                //typeStr = "ikRPsolver";
                //resultStr = MGlobal.executePythonCommandStringResult("cmds.ikHandle(sj='" + startJointDagPath.fullPathName + "',ee='" + endJointDagPath.fullPathName + "',sol='" + typeStr + "',n='ik_" + ikMainName + "')");
                break;
            }

            case IKSolverType.Spline:
            {
                csc.UpdateParm("sol", "ikSplineSolver");
                csc.UpdateParm("n", "ik_" + ikMainName);
                csc.UpdateParm("ccv", curveName == null || curveName.Length == 0);
                csc.UpdateParm("c", curveName);
                csc.UpdateParm("pcv", false);
                string excuteStr = csc.ToString();
                resultStr = MGlobal.executePythonCommandStringResult(excuteStr);
                //resultStr = MGlobal.executePythonCommandStringResult("cmds.ikHandle(sj='" + startJointDagPath.fullPathName + "',ee='" + endJointDagPath.fullPathName + "',sol='" + typeStr + "',c='" + curveName + "',n='ik_" + ikMainName + "')",true);
                break;
            }
            }
            //[u'ik_joint1_joint4', u'effector1']
            string[] resultArr = BasicFunc.SplitPythonResultStr(resultStr);

            return(resultArr);
        }
Beispiel #7
0
        //error here
        public static MDagPath CreateCircle(string ctlName)
        {
            string resultStr = MGlobal.executePythonCommandStringResult("cmds.circle(n='" + ctlName + "')");

            //string resultStr = MGlobal.executeCommandStringResult("circle -n " + ctlName);
            string[] resultArr = SplitPythonResultStr(resultStr);
            for (int i = 0; i < resultArr.Length; i++)
            {
                Debug.Log(resultArr[i]);
            }
            return(GetDagPathByName(resultArr[0]));
        }
Beispiel #8
0
        public static MDagPath CreateLocator(MVector worldPos, string locatorName)
        {
            string cmdStr = "cmds.spaceLocator(n='" + locatorName + "')";

            locatorName = SubUShell(MGlobal.executePythonCommandStringResult(cmdStr));
            MDagPath     locDagPath   = BasicFunc.GetDagPathByName(locatorName);
            MFnTransform locatorTrans = new MFnTransform(locDagPath);

            //Debug.Log(locatorName+"dag:"+locDagPath.fullPathName);
            locatorTrans.setTranslation(worldPos, MSpace.Space.kWorld);
            return(locDagPath);
        }
Beispiel #9
0
        public static MDagPath CurveToHair(ref MDagPath hairSystemDagPath, MDagPath curveDagPath = null, ConstantValue.HairPointLockType pointLock = ConstantValue.HairPointLockType.Base)
        {
            if (curveDagPath == null)
            {
                curveDagPath = BasicFunc.GetSelectedDagPath(0);
            }
            bool           hairSystemReady = !hairSystemDagPath.node.isNull;
            MSelectionList targetList      = new MSelectionList();

            targetList.add(curveDagPath);
            if (hairSystemReady)
            {
                Debug.Log("hair system ready");
                targetList.add(hairSystemDagPath);
            }
            else
            {
                Debug.Log("hair system need to be created!");
            }
            BasicFunc.Select(targetList);


            string cmdStr    = "cmds.MakeCurvesDynamic(0,0,0,1,0)";
            string resultStr = MGlobal.executePythonCommandStringResult(cmdStr);

            MDagPath result = new MDagPath();

            //Debug.Log(curveDagPath.fullPathName);
            MFnTransform curveTrans = new MFnTransform(curveDagPath);

            if (curveTrans.parentCount > 0)
            {
                MDagPath follicleDagPath = MDagPath.getAPathTo(curveTrans.parent(0));
                MGlobal.executeCommand(string.Format("setAttr {0}.pointLock {1}", follicleDagPath.fullPathName, (int)pointLock));
                if (follicleDagPath.hasFn(MFn.Type.kFollicle))
                {
                    Debug.Log("follicle exist!");
                    ConvertHairSelection(HairSelectionType.OutputCurves, follicleDagPath);
                    result = BasicFunc.GetSelectedDagPath(0);
                    new MFnDependencyNode(result.node).setName("dy_" + curveDagPath.partialPathName);
                    if (!hairSystemReady)
                    {
                        ConvertHairSelection(HairSelectionType.HairSystem);
                        hairSystemDagPath = BasicFunc.GetSelectedDagPath(0);
                        hairSystemReady   = true;
                    }
                }
            }

            return(result);
        }
Beispiel #10
0
 public override void RunPythonCommand(string command)
 {
     var status = MGlobal.executePythonCommandStringResult(command);
 }
Beispiel #11
0
        /// <summary>
        /// return Dynamic Output Curve
        /// </summary>
        /// <param name="hairSystemDagPath">exist hairsystem or container of created hairsystem</param>
        /// <param name="curveList"></param>
        /// <param name="pointLock">0-none, 1-base, 2-end,3-both</param>
        /// <returns></returns>
        public static MDagPath[] CurvesToHairs(ref MDagPath hairSystemDagPath, MSelectionList curveList = null, ConstantValue.HairPointLockType pointLock = ConstantValue.HairPointLockType.Base)
        {
            if (curveList == null)
            {
                curveList = BasicFunc.GetSelectedList();
            }

            bool hairSystemReady = false;

            if (!hairSystemDagPath.node.isNull)
            {
                //Debug.Log("hairSystem node is not null:" + hairSystemDagPath.fullPathName);
                curveList.add(hairSystemDagPath);
                hairSystemReady = true;
            }
            else
            {
                //Debug.Log("hairsystem node is null");
            }
            MGlobal.setActiveSelectionList(curveList);
            string cmdStr    = "cmds.MakeCurvesDynamic(0,0,0,1,0)";
            string resultStr = MGlobal.executePythonCommandStringResult(cmdStr);

            if (hairSystemReady)
            {
                //Debug.Log("remove hairSystem Selection");
                curveList.remove(curveList.length - 1);
            }
            List <MDagPath> results = new List <MDagPath>();

            for (int i = 0; i < curveList.length; i++)
            {
                MDagPath curveDagPath = new MDagPath();
                curveList.getDagPath((uint)i, curveDagPath);

                //Debug.Log(curveDagPath.fullPathName);
                MFnTransform curveTrans = new MFnTransform(curveDagPath);
                if (curveTrans.parentCount > 0)
                {
                    MDagPath follicleDagPath = MDagPath.getAPathTo(curveTrans.parent(0));
                    MGlobal.executeCommand(string.Format("setAttr {0}.pointLock {1}", follicleDagPath.fullPathName, (int)pointLock));
                    if (follicleDagPath.hasFn(MFn.Type.kFollicle))
                    {
                        Debug.Log("follicle exist!");
                        ConvertHairSelection(HairSelectionType.OutputCurves, follicleDagPath);
                        MDagPath result = BasicFunc.GetSelectedDagPath(0);
                        new MFnDependencyNode(result.node).setName("dy_" + curveDagPath.partialPathName);
                        results.Add(result);
                        if (!hairSystemReady)
                        {
                            ConvertHairSelection(HairSelectionType.HairSystem);
                            hairSystemDagPath = BasicFunc.GetSelectedDagPath(0);
                            //Debug.Log("assign hairSystem:" + hairSystemDagPath.fullPathName);
                            hairSystemReady = true;
                        }
                    }
                }
            }


            //error
            return(results.ToArray());
        }