简体   繁体   中英

Maya-Python manipMoveContext

Right now I'm trying to make a script that changes the pivot orientation in Maya. (This feature is already in the Maya Modeling Toolbox but I want to make a custom and simplified version of it) However I'm getting issues with my function. This is the code:

cmds.optionMenu(label = 'Pivot', changeCommand = pivotOrient)

cmds.menuItem( label='Object', )
cmds.menuItem( label='World')
cmds.menuItem( label='Component' )
cmds.menuItem( label='Normal' )


def pivotOrient( p ):
    if p == 'Object':
        cmds.manipMoveContext(e= True, mode= 0)
    elif p == 'World':
        cmds.manipMoveContext(e= True, mode= 2)
    elif p == 'Component':
        cmds.manipMoveContext(e= True, mode= 10)
    else:
        cmds.manipMoveContext(e= True, mode= 3)

It says "# Error: RuntimeError: file line 40: No object name specified. #"

Can you help me with this problem? I'm sorry I'm still a newbie at Python and Maya scripting. Thanks in advance.

The manipMoveContext command requires the first argument to specify the context, when in edit or query mode (see: http://help.autodesk.com/cloudhelp/2016/ENU/Maya-Tech-Docs/CommandsPython/manipMoveContext.html#hExamples ).

In the simplest case scenario, you can use 'Move' as the first argument for your calls, as such: cmds.manipMoveContext('Move', e=True, mode=0)

But for less trivial scenarios (or even just to generalize your code and make it more robust) you need to understand how manipulators and contexts work and add some logic to your pivotOrient function.

Merely as a hint to what I mean, you can have a look at these:

Also, try playing with this:

curctx = cmds.currentCtx()
print curctx
if cmds.superCtx(curctx, ex=1):
    ctx = cmds.superCtx(curctx, q=1)
    typ = cmds.contextInfo(ctx, q=1, c=1)
    print ctx, typ

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM