Adverti horiz upsell
Color syntaxing the Script Editor Reporter
Color syntaxing the Script Editor Reporter
mlouala, updated 2017-04-16 11:20:08 UTC 5,726 views  Rating:
(1 rating)
Page 3 of 5

Linking intrinsically to Maya


Starting at launch

The execution of customized scripts when Maya starts can be easily achieved with the file userSetup.py in the folder Maya/scripts in your Documents, if the file doesn't exist, create it.

We will copy our awesome script in a new file named syntax.py in this folder, then we need to edit our userSetup.py file to add the following line ;

import syntax

 

Tips ; The use of the Maya's cmds function evalDeferred is often recommended if you want to differ the execution of scripts until Maya is 'available'.

Our example is a simple import statement so we don't need to do that =) !

Alrigh, then if you open your scriptEditor, and type

syntax.wrap()

our Command History QTextEdit will take some some colours !


A bit of hacking =) !

Now we have our function which colorize the Command History of Maya, we need to link it to Maya so each time the scriptEditor opens, the QSyntaxHighlighter will be parented to the corresponding QTextEdit ! Because everytime the window is closed, the Command History QTextEdit widget is deleted, so is our QSyntaxHighlighter !

If we turn on the option "Echo All Commands" in the scriptEditor we'll see that the command scriptEditor; is called when opening the window. After a search in Window → Settings/Preferences → Hotkey Editor under the Window section we find that the executed script for this function is ;

if (`scriptedPanel -q -exists scriptEditorPanel1`) { scriptedPanel -e -to scriptEditorPanel1; showWindow scriptEditorPanel1Window; selectCurrentExecuterControl; }else { CommandWindow; }

Unfortunately these 'inside' functions in Maya aren't editable, and even if they were, this will only change the script for the keyboard shortcut, not the other ways to open the window, like the little button  for instance, will continue to execute the function quoted above.

So we're going to have a look on the internal Maya files, with the secret hope to find this function in some .mel script, using a software like Notepad ++ we will be able to search inside all Maya's files and find the one which contains our command.

A little - and efficient - search indicates that the file defaultRunTimeCommands.mel in the folder scripts/startup inside the Maya folder contains what we are looking for.
The file is really huge, and the line we want differs between Maya versions, for Maya 2013 that line is the 4096th, for Maya 2014 that's the 4228th, simply search scriptEditor; in the file should bring you to correct line =) !

We just need to add a simple MEL command at the end of the Maya command, from ;

-command ("if (`scriptedPanel -q -exists scriptEditorPanel1`) { scriptedPanel -e -to scriptEditorPanel1; showWindow scriptEditorPanel1Window; selectCurrentExecuterControl; }else { CommandWindow; }")

to

-command ("if (`scriptedPanel -q -exists scriptEditorPanel1`) { scriptedPanel -e -to scriptEditorPanel1; showWindow scriptEditorPanel1Window; selectCurrentExecuterControl; python(\"StdOut = syntax.wrap()\"); }else { CommandWindow; }")

So our color syntax will be called everytime scriptEditor; is executed, whatever how the command is called =) !