![Rank 排名](http://www.ocatasi.com/forums/html/@6131E615FDDD75733C0A002A8E56C4C9/rank_icons/6_large.png)
排名
贡献者
11-29-2022上午02:38
感谢的人。我还没有深入研究这个问题,因为我可能已经找到了其他方法来解决我当时遇到的问题,但一旦我有空闲时间,我可能会研究这个问题,因为它在未来可能会有用。祝你有愉快的一天!
显示更多
11-10-202003:57我
10-31-2020分下午
2喜欢
你可以在Maya文档的“命令”部分找到你要找的东西。基本上,为了做到这一点,你需要编辑操纵符的状态,你可以通过调用以下命令来做到这一点:// move manipRotateContext;// for rotate manipScaleContext;你可以使用-e (edit)和-cah (currentactics handle)标志来运行这些命令,并指定轴为0 (X), 1 (Y), 2 (Z)或3(对齐到视图),最后指定你想要影响的操作符。如下:manipMoveContext -e -cah 0移动;然后,您可以在热键编辑器的Runtime Command部分下为每个操作器创建一个自定义快捷方式,但这意味着每个操作器有3个热键(每个轴一个),这在实践中使用起来相当烦人。我已经写了几行代码,应该做你真正想要的:/*这设置当前操纵器只在X轴上工作------------------------------ */{//查询当前操纵器字符串$curManip = ' currentCtx -q ';if ($curManip == "moveSuperContext") {manipMoveContext -e -cah 0 Move;} else if ($curManip == "RotateSuperContext") {manipRotateContext -e -cah 0旋转; } else if ($curManip == "scaleSuperContext") { manipScaleContext -e -cah 0 Scale; } } /* This sets the current manipulator to work only in the Y axis ------------------------------ */ { // Query the current manipulator string $curManip = `currentCtx -q`; if ($curManip == "moveSuperContext") { manipMoveContext -e -cah 1 Move; } else if ($curManip == "RotateSuperContext") { manipRotateContext -e -cah 1 Rotate; } else if ($curManip == "scaleSuperContext") { manipScaleContext -e -cah 1 Scale; } } /* This sets the current manipulator to work only in the Z axis ------------------------------ */ { // Query the current manipulator string $curManip = `currentCtx -q`; if ($curManip == "moveSuperContext") { manipMoveContext -e -cah 2 Move; } else if ($curManip == "RotateSuperContext") { manipRotateContext -e -cah 2 Rotate; } else if ($curManip == "scaleSuperContext") { manipScaleContext -e -cah 2 Scale; } } Assign each one to a shortcut and they should work as expected, regardless of the manipulator (so you only need 3 shortcuts). As a final tip (and one which I'm not sure is documented anywhere), to reset the manipulator state just double tap it's assigned shortcut (2x W, 2x E, 2x R). Hope that was helpful. Have a nice day!
显示更多
10-31-202004:05点
哦!好吧,现在我明白了!那时候我的方向是对的(有点)。基本上,任何在uiproc之外声明为本地的东西都不能被UI本身访问,除非它通过参数传递给UI过程,或者声明为全局,这使得它可以被UI过程访问。得到它!是的,我经常使用打印语句来调试问题!这就是为什么我们发现过程确实在执行,但其中的各种“for循环”实际上并没有运行。这终于说得通了!再次感谢大家!你帮了我很大的忙。
显示更多
10-31-202003:46点
是的,因为UI存在于脚本本身的过程中,而不是作为一个单独的脚本。这只是其中的一个步骤。
显示更多
10-31-202003:30点
谢谢你抽出时间来帮忙。你阐述局部和全局区别的方法非常有效。我已经对这两者之间的区别有了基本的了解,但脚本同样可以很好地处理局部变量。各个过程的公共变量在每个过程的作用域之外声明(在脚本的开头),因此每个过程都可以使用这些变量,尽管不是全局声明的。相反,正如您所指出的,在每个过程范围内声明的变量在这些范围之外是不可访问的(当然,除非我使用return语句之类的东西)。只有当我试图通过UI调用主进程时,问题才会出现。所以,脚本本身工作得很好..UI工作很好,它自己..把两者放在一起,就什么都不管用了。除非前几个变量是全局声明的。 Maybe I'm being dense, but I'm having a though time understanding how the script can work on it's own with local variables, but not if I call the same exact procedure through a button (unless that change is made). This is kind of hard for me to wrap my head around. Again, thank you so much for replying. Hope I have explained myself (English is not my first language).
显示更多
10-31-202043分下午
1像
大家好,在过去的几个月里,我一直在mel中摆弄脚本,没有任何编程方面的知识。我是一个初学者,可以说我的方法非常“亲力亲为”,我的意思是说我可能没有在这个主题上阅读那么多,因此,我猜,犯了一些对其他人来说很明显的错误。话虽如此,我现在已经设法创建了一个小工具集,这些工具被证明是有用的,不仅对我自己,对我的同事也是如此。我现在正在试验自定义ui,我希望能使这些工具更友好,但我有问题这样做,不知道是否有人能给我在这方面的任何建议。我的问题是,我的脚本似乎自己工作得很好,但每当我试图通过自定义UI调用过程时,脚本不工作或Maya崩溃,这在使用Maya的本机提示对话时不会发生,这是我经常做的。一位经验更丰富的同事建议对我所有过程的通用变量进行全局初始化,而不是局部初始化。这种方法奏效了,但他承认自己也不太确定其中的原因。只是作为一个例子,我通常以这种方式编写代码:{var / *常见 ------------------------------------------------------------- */ 字符串$控制器=(“name_controller”);字符串$select [] = {};$select = ' ls -select '; string $assets[] = {}; /* Procedures ------------------------------------------------------------- */ // Does this proc doThisThing () { // Code.. } // Does that proc doOtherThing () { // Code.. } // Custom UI proc customUI () { // Code.. } // Main proc: Checks conditions and execute all procedures proc doTheThing () { if (size($assets)>0) { doThisThing; } else { doOtherThing; } } customUI; } This is over simplified pseudo-code, I know. But basically what I did was just redefining common variables as global and adding a clear command at the end to free up the memory, which appears to have solved the problem. Can anyone explain to me as to why this would make the UI work correctly along my script (haven't changed anything else)? Also I'm used to initialize common variables as local because I've read elsewhere that is generally best in order to avoid incurring in a name of an already existing global variable within Maya. Going by intuition my idea is that somehow the procedure that I'm trying to call from within the UI isn't completely accessible within the scope of the UI itself (or something along these lines), but somehow declaring those variables as global makes the proc available for the UI as well (??? really confused about it). Any help or suggestion on proper programming practices would be greatly appreciated! Thanks in advance for taking the time to read this and have a nice day!
显示更多
10-31-202042我
1像
嗨,如果你看一下Maya的文档(在命令部分),你会找到你正在寻找的东西。为了改变操纵器的活动轴,您需要调用以下命令:Move - manipMoveContext旋转式- manipRotateContext因此,您首先需要做的是“编辑”操作符的状态,您可以使用-e (edit)标记来做到这一点。然后,您需要使用-cah (currentactical handle)指定您想要更改当前轴。然后,您可以通过输入0 (x) 1 (y) 2 (z) 3(与视图对齐)来指定轴,并通过指定您希望影响的操作器上下文来结束该行。如下:manipMoveContext -e -cah 0移动;这将Move操作符设置为只在X轴上操作。通过遵循相同的示例,您可以在“热键编辑器”的“运行时命令编辑器”选项卡中为每个轴创建自定义快捷方式。 Alternatively, a simpler way would be to call the procedure "dR_setActiveTransformAxis", which is part of the modeling toolkit toolset. Like so: dR_setActiveTransformAxis 0; (for the X axis) dR_setActiveTransformAxis 1; (for the Y axis) dR_setActiveTransformAxis 2; (for the Z axis) The procedure works on all manipulators, so this makes it possible to create a single shortcut for each axis independently from the manipulator. I use this at work every day and it's pretty handy! A final tip (which I'm not sure is documented), after you have operated in a specific axis if you want to reset the manipulator just double tap the it's shortcut and that will do it (2x W, 2x E, 2x R). Hope this was helpful. Have a nice day!
显示更多