问题
I'm wondering what exactly the cmds.scriptCtx command does, cuz I've tried to copy and paste it directly from the Autodesk help page to my script editor and nothing happened. Here's the script from Autodesk help:
import maya.cmds as cmds
cmds.scriptCtx( title='Attach Curve', totalSelectionSets=1, fcs="select -r $Selection1; performAttachCrv 0 \"\"", cumulativeLists=True, expandSelectionList=True, setNoSelectionPrompt='Select two curves close to the attachment points', setSelectionPrompt='Select a second curve close to the attachment point', setDoneSelectionPrompt='Never used because setAutoComplete is set', setAutoToggleSelection=True, setSelectionCount=2, setAutoComplete=True, curveParameterPoint=True )
I tried select one curve, and two curves, or not selecting anything at all and nothing ever happened. Did I miss something?
I'm using Maya 2018 for this script.
Thanks guys.
回答1:
I was always wondering what this command was too, but I've never seen another person use it so always ended up ignoring it.
Don't feel bad for not getting it, the documentation does a god awful job explaining how the example works. I had to dig around to find out that it completely omits that you need to use cmds.setToolTo()
.
Create 2 curves, run this, then pick a curve one at a time:
import maya.cmds as cmds
picker = cmds.scriptCtx(
title='Attach Curve', totalSelectionSets=1, fcs="select -r $Selection1; performAttachCrv 0 \"\"",
cumulativeLists=True, expandSelectionList=True, setNoSelectionPrompt='Select two curves close to the attachment points',
setSelectionPrompt='Select a second curve close to the attachment point', setDoneSelectionPrompt='Never used because setAutoComplete is set',
setAutoToggleSelection=True, setSelectionCount=2, setAutoComplete=True, curveParameterPoint=True
)
cmds.setToolTo(picker)
So basically, it's an object picker. When you run it, the cursor changes and it displays instructions for the user. In this example, it says pick 2 curves. When you pick one, the instructions update to say pick another curve. When another curve is picked, a script runs to attach both curves. The user can also hit esc at anytime to cancel it. All the masks parameters are there so that you can limit what type of objects the user can pick.
Coming from 3dsMax this is actually pretty awesome but the implementation feels poor. It's not obvious at all to the user that this picker is happening. The instructions aren't colored in anyway and it's easily missed in the bottom corner of Maya's interface. You also can't pick an object from the outliner, which is ridiculously bad design. And as far as I understand it only supports MEL.
It's kind of cool to know, but I still don't think I'll be using it.
来源:https://stackoverflow.com/questions/58373222/what-exactly-the-cmds-scriptctx-in-maya-python-does