Step 0. Locating the proc
If you already know the mel proc you want to call then skip this step.
Turn on "echo all commands" in the script editor (it's under history at the top of the window).
Perform the action manually through the UI.
Take a look at the script editor contents.
For assigning a new outline I get this:
editMenuUpdate MayaWindow|mainEditMenu;
buildCartoonMenu MayaWindow|mainCartoonMenu;
ToonCreatePfxOutlineMenu MayaWindow|mainCartoonMenu|toonCreatePfxOutlineItem;
AssignNewPfxToon;
assignNewPfxToon;
ls -selection -type "transform";
ls -selection -type "transform";
ls -selection -type "transform";
ls -selection -type "transform";
ls -selection -type "transform";
ls -selection -type "transform";
setFilterScript "initialShadingGroup";
// Result: 0 //
setFilterScript "initialParticleSE";
// Result: 0 //
setFilterScript "defaultLightSet";
// Result: 1 //
setFilterScript "defaultObjectSet";
// Result: 1 //
setFilterScript "cluster1Set";
// Result: 0 //
setFilterScript "initialShadingGroup";
// Result: 0 //
setFilterScript "initialParticleSE";
// Result: 0 //
editMenuUpdate MayaWindow|mainEditMenu;
autoUpdateAttrEd;
CBselectionChanged;
dR_updateCommandPanel;
hikControlRigSelectionChangedCallback;
$gHIKneedSyncOnSetKeyframe=1;
// Result: 1 //
updateAnimLayerEditor("AnimLayerTab");
statusLineUpdateInputField;
if (!`exists polyNormalSizeMenuUpdate`) {eval "source buildDisplayMenu";} polyNormalSizeMenuUpdate;
dR_updateCounter;
Look for a line or group of lines that look relevant to what you are doing, and you can narrow it down to
AssignNewPfxToon;
assignNewPfxToon;
Test out these commands to see what they do, or look in the mel files they come from. You can also use
mel.eval('whatIs ...')
to find out more info.
In this particular case it looks like AssignNewPfxToon just calls assignNewPfxToon.
Step 1. Locating the .mel
You can skip this if you already know what mel file contains the proc you want to use.
If you don't then use the UI menus to run it once, then run this code
import maya.mel as mel
mel.eval('whatIs assignNewPfxToon')
which will return
// Result: Mel procedure found in: C:/Program Files/Autodesk/Maya2022/scripts/paintEffects/assignNewPfxToon.mel //
So you can easily find the .mel file that you need to source
Step 2. Sourcing the .mel
If you are able to run your mel command from a fresh Maya then skip this step.
You'll notice that if you try to run certain MEL procs in a fresh Maya it will tell you it doesn't exist, but if you've run it once through the UI, then it will exist. This is because Maya only sources .mel functions as-needed.
import maya.mel as mel
mel.eval('source "theFileIWant.mel"')
If you want to detect if the file has already been sourced, you can use this code
import maya.mel as mel
if mel.eval('exists yourMelProc'):
print 'IT EXISTS'
else:
print 'IT DOES NOT EXIST')
Step 3. Run the proc
mel.eval('my my code')
Some of that is stuff you probably already know, I just wanted to be thorough since this is a pretty common problem people run into.