Lately I was doing a script involving the Paint effects tool. The command is not available in the documentation so I just used, as usual, the script editor in conjunction of ‘Echo all command’ to get the mysterious MEL command: PaintEffectsTool. Everything’s good, my script is going well but one thing annoys me… I want to pause my script while the user is painting and then do something with his input. The problem is, all the following commands of my script get executed immediately after calling the Paint Effect Tool. It never waits for the user input. I continued my investigation on how to do this… and finally stepped upon the scriptCtx command:
This command allows a user to create their own tools based on the selection tool. A number of selection lists can be collected, the behaviour of the selection and the selection masks are fully customizable, etc.
It kinda worked but not quite well, and I was not satisfied with the result. I then noticed in the command reference of Maya a lot of commands with the suffix Ctx and especially the currentCtx command:
This command returns the currently selected tool context.
No sooner said than done, I executed the Paint Effect Tools and then currentCtx and…
string $whichCtx = `currentCtx`;
// Result: dynWireCtx1 //
cmds.currentCtx()
# Result: dynWireCtx1 #
Bingo. No need to use the previous strange MEL command, everything is good and clean! If you tried to play with the scriptCtx command before, you understand immediately that ‘dynWireCtx1’ is the name of the instance of the tool, and that if you want to create your own instance, the initial command is dynWireCtx.
But it does absolutely nothing when I try to execute that command, what’s wrong? Well, when you execute a context command Ctx, you just create the tool. To actually execute it you have to use setToolTo(). For example:
dynWireCtx "customName";
setToolTo("customName");
cmds.dynWireCtx("customName")
cmds.setToolTo("customName")
If you try to change the parameters of the tool by calling the same command, you will notice that Maya return an error. In order to do it, just edit your existing one with the ‘edit’ flag. You can get all the flags name in the pyMel documentation. One hidden but really interesting parameter is the brushMass flag. In conjunction with the brushDrag flag it can give crazy results as you can see in the next video, but as always, it is much more noticeable by testing by yourself.
dynWireCtx "customName";
setToolTo("customName");
dynWireCtx -edit -brushMass 100 -brushDrag 0.1 "customName";
dynWireCtx -edit -brushMass 100 -brushDrag 0.01 "customName";
dynWireCtx -edit -brushMass 10 -brushDrag 0.1 "customName";
cmds.dynWireCtx("customName")
cmds.setToolTo("customName")
cmds.dynWireCtx("customName" , edit=True, brushMass = 100, brushDrag = 0.1)
cmds.dynWireCtx("customName" , edit=True, brushMass = 100, brushDrag = 0.01)
cmds.dynWireCtx("customName" , edit=True, brushMass = 10, brushDrag = 0.1)