あんまり使う人いないかな?w
なにかのキーに割り当てて、移動・回転・スケールの軸方向をさっと切り替えたいなぁと思って簡単なスクリプト書きました。
マーキングメニューで切り替えられるのも知っていますが、自分はなんとなくやりづらかったのでw
(例えば、移動の軸方向を変えたい場合、wWキーを押しながらマウスの右ボタン長押しすると軸のマーキングメニューがでます。)
スクリプト的にはすごく簡単なものですが自分が「ん?」って思った所を書いておきますと、
・回転のツールコンテキスト(RotateSuperContext)の頭文字だけなぜか大文字…
移動 → moveSuperContext スケール → scaleSuperContext
・ヘルプのドキュメントを見ると
cmds.manipMoveContext( 'manipMoveContext1', q=True, mode=True )
と、オブジェクト名に「'manipScaleContext1'」と書いてあるので
manipCtx = cmds.manipMoveContext() #ここでmanipScaleContext1 、manipScaleContext2などが作られる
cmds.manipMoveContext( manipCtx , q=True, mode=True )
ってやってみるとエラーなわけですよ! そして、「すべてのコマンドのエコー」をONにしてヒストリーを見てみると…
manipMoveContext -e -mode 2 Move;
ヒストリで見れるのはMELですが「Move」とありますね… ん?まさか…
はい、そのまさかでオブジェクト名は"Move"でした! うぉぉぉおおおいいいい、ヘルプドキュメント!!!
cmds.manipMoveContext( "Move", q=True, mode=True )
書きたかったのはそれだけです。
スクリプトの挙動としては、移動ツール・回転ツール・スケールツールのときに
オブジェクト→ワールド→コンポーネント→オブジェクト… と風に3つの軸方向が順番にぐるぐる変わります。
他に法線やジンバルなど入れたい方はご自由に改造してみてください(もしやりたいけど分からない方はお気軽に聞いて下さい)
使用されるときはホットキーエディタなどに下記の文を書いて下さい。
import kChangeToolAxis
reload (kChangeToolAxis)
# -*- coding: utf-8 -*- import maya.cmds as mc def kChangeToolAxis(): toolCtx = mc.currentCtx() if toolCtx == "moveSuperContext": axisDir = mc.manipMoveContext("Move" , q=True , mode=True) if axisDir == 0: mc.manipMoveContext("Move" , e=True , mode=2) elif axisDir == 2: mc.manipMoveContext("Move" , e=True , mode=9) elif axisDir == 9: mc.manipMoveContext("Move" , e=True , mode=0) else: mc.manipMoveContext("Move" , e=True , mode=0) elif toolCtx == "RotateSuperContext": axisDir = mc.manipRotateContext("Rotate" , q=True , mode=True) if axisDir == 0: mc.manipRotateContext("Rotate" , e=True , mode=1) elif axisDir == 1: mc.manipRotateContext("Rotate" , e=True , mode=9) elif axisDir == 9: mc.manipRotateContext("Rotate" , e=True , mode=0) else: mc.manipRotateContext("Rotate" , e=True , mode=0) elif toolCtx == "scaleSuperContext": axisDir = mc.manipScaleContext("Scale" , q=True , mode=True) if axisDir == 0: mc.manipScaleContext("Scale" , e=True , mode=2) elif axisDir == 2: mc.manipScaleContext("Scale" , e=True , mode=9) elif axisDir == 9: mc.manipScaleContext("Scale" , e=True , mode=0) else: mc.manipScaleContext("Scale" , e=True , mode=0) kChangeToolAxis()
コメントをお書きください