abScriptMenu

January 22nd, 2009

This script allows you to create a menu item in the Maya UI that contains all of your scripts, organized however you want.

Initial Setup

Once you've copied the script to your scripts folder, open up your userSetup.mel file and add the following line:

source abScriptMenu.mel;abSMbuildMenu();

This will automatically add the menu item to Maya main menu bar on startup.  It won't show up until you add some scripts to it and build a menu, though.  

Add Some Scripts

You can add scripts to your menu in two ways.  The first is to click the "Add Script Folder" button and select a directory that contains .mel or .py scripts.  The directory will be scanned and any scripts that are found will appear in the "Scripts" textScrollList.  Note that scripts ending in "template" are ignored.

You can also add scipts individually by clicking the "Add A Single Script" button.  Fill in the name for the menu item (eg: "my script"; how you want it to appear in the menu), the name of the script file (eg: "myScript.mel"; don't include the path), and the procedure in the script that you want to call (eg: "myScript"; most times this will be the name of the script minus the extension).

Note that your script menu won't be updated automatically when you add new scripts to one of the specified script paths, even when you restart Maya.  You have to first open the abScriptMenu UI (accessible from the menu), click "Rescan Folders", and then click the "Save And Build Menu" button.

And Build A Menu

Once you've got some scripts in the scripts list you can build your menu.  Click the "Save And Build Menu" button and you should see a new menu named "Scripts" on your Maya menu bar.  Open it and you'll see all of the scripts that you've loaded into the UI.

Changes that you make to items in the scriptMenu UI won't show up or be saved until you click the "Save and Build" button.  If you've made a bunch of changes without saving and you want to revert to your current menu configuration you can click the "Load Menu" button and the last saved state will be loaded into the UI.

Groups

It's nice to have scripts in a menu, but eventually you accumulate enough of them that you need some organization, and that's where groups come in.  Groups are basically submenus in your script menu that contain any scripts that you associate with them.

You create groups with the "New Group" button and remove them with either the "Remove Group" button or by selecting one and hitting the delete key.

You can assign scripts to groups in two ways.  The first is by selecting a group in the group list.  Once selected, all of its member scripts will be highlighted in the script list.  As long as there is a selection in the group list, any selection changes you make in the script list will either assign or remove those scripts from that selected group.  Note that you can hold down the control, shift or alt keys to modify the selection style.

You can also add scripts to a group using the popup menu in the script list.  First make sure nothing is selected in the group list (otherwise any selection that you make in the script list will assign those scripts to the selected group).  Then select one or more scripts in the script list, right-click and choose a group from the menu.

Note that the "Ignored" group is a special group which can't be deleted.  Any scripts assigned to it won't appear on the menu.

Script Properties

Beneath the script list are four textFields that are enabled when you have a single script selected.  The display name is the unique name for the script as it will show up in the menu.  The script textField indicates the name of the script file associated with this entry, and the group is the group that the script a member of, if any.

The "Proc To Call" field specifies which procedure in the script will be called.  Usually this is the name of the script minus the extension, but not always.  Sometimes you might need to run the entire script file, and not just a procedure withing it.  In that case, you can include the source statement in the field, like so:

source myScript.mel;myScript();

Proc To Call Options

Typically you'll just enter the function you wish to run and any desired arguments, like so:

myFunction(12, "unicorn", true, {"googly", "tater", "frank"})

Sometimes, though, you might want to run the function with different arguments.  You can do so using the following (markdown-esque) syntax:

myFunction(12, "unicorn", true, {"googly", "tater", "frank"})[Number of Objects, New Object Name, Rainbow Powered, Children]

Which will create a custom UI when you Control+Alt+Click its menu item in the main UI "Scripts" menu.  The strings in the brackets specify the names of each respective variable field.  Note that your individual argument labels cannot contain commas or quotes.

If you want the menu item to open your custom UI every time it's clicked, prefix your command with an "*", like this:

*myFunction(12, "unicorn", true, {"googly", "tater", "frank"})[Number of Objects, New Object Name, Rainbow Powered, Children]

Sometimes you may need to execute a non-standard bit of code to get a script running.  You can do this by prefixing your proc with an "!", like this:

!reload(myPyFunction)~myPyFunction

Note that the "~" is used to specify new lines, so this bit of python will run as:

reload(myPyFunction)
myPyFunction

The custom UI features will only work with mel scripts, but the "!" and "~" operators work with both mel and python.

Modifier Keys

Clicking on menu items in the main script menu with the different modifier keys performs different functions.

Control+Click:  Will source your script before running.  Note that scripts will be sourced automatically if the procedure doesn't currently exist in Maya's mighty memory.

Alt+Click:  Will open Mel scripts in your default editor.  Python files open in notepad (I know, it sucks, but they would be run if they were just loaded).  This feature is Windows only at the moment, but if you send me the system commands for your OS I'll include them.

Control+Alt+Click:  Creates a UI for each individual argument of a Mel procedure call.  If the procedure doesn't have any arguments it will be run and the UI will be skipped.  You can specify the names of the arguments by adding them in brackets immediately after the closing parenthesis of the procedure.  Separate them with commas and don't include quotes.  Here's an example of how the "Proc To Call" syntax might look:

myProc(12, "unicorn", true, {"googly", "tater", "frank"})[Number of Objects, New Object Name, Rainbow Powered, Children]

And here is the resulting UI.  Note that if you don't specify the variable names, they'll be labeled by variable type.  Also, this currently only works with Mel scripts.  I'll add Python at some point.

Oh, And Uh...

Double clicking a script folder path in the script list will open that folder.

Double clicking a script in the script list will run it and alt+clicking it will open it in your text editor.

Scripts added with the "Add Single Script" button can be deleted from the script list by selecting them and hitting the delete key.  You have to hit it really hard, though.

Scripts added with the "Add Script Folder" button can only be removed from the script list by removing their directory from the import list with the "Remove Folder" button.

That's it.  I hope you find it useful, and, as always, feedback is super fine.


Updates

Version 1.3
January 31st, 2009 Fixed python script launching; fixed spaces in names selection issue; single strings are now stripped of quotes in custom UI.
Version 1.4
February 3rd, 2009 Fixed issue where python scripts would show up twice in script list.
Version 1.4.1
March 10th, 2009 "Load Menu" button will now respect user added scripts.  Added script group optionMenu to Add Script UI.

This is a maintenance update.  The next version (with lots of changes and new features) is sitting half completed on my hard drive.  I hope to soon get some time to finish it.

Update/Bug Fix
September 24th, 2009 Still not the new version, but improved nonetheless.  Now if you add an "*" in front of the procedure in the "Proc To Call" field (in the config UI) the selected script will always open with the prebuilt UI.  Also added "Script Quick Search" to the main scriptMenu.  Use it to search for scripts with a text string.  You can click a script in the result list to launch it, or, if there's only one script result, hit enter (from the search text field) and it will launch.
Update/Bug Fix
May 25th, 2011 Fixed fatal crash (on 2011 and up) in "Script Quick Search" when user hits enter with one result in list.
Version 2.0
May 8th, 2013
  • Overhauled and improved UI.
  • Added the ability to arrange and sort menu items.
  • Added the ability to add dividers to your menus.
  • Probably added other stuff that I'm forgetting.
Version 2.1
April 2nd, 2014
  • Python scripts are now attempted to be executed with only the name of the script if the first try yields an attributeError.

  • You can now add an "!" (no quotes) as the first character in the proc field, and the script will run the code in the proc field as is.  You can break your proc code into lines using "~" (a tilde -- no quotes) as a new line indicator.

  • The options are getting kind of complicated, so I added a help button next to the "Proc To Call" textfield.

Version 2.2
November 13th, 2014
  • Script quicksearch works again.

"abScriptMenu" was posted on January 22nd, 2009 under Mel Scripts.  It was created using Maya.

This entry was last updated on November 13th, 2014.

Subscribe to the Comments Feed or Updates Feed for this entry.

Share |

comments

Ruben Algarra
February 13th, 2009 said:

Hi!! Thank you for sharing this scripts!!! For year I used ClipFX (with some modifications) but I think abScriptMenu is going to be the "New One" I only have 2 little suggestions: -Reorder (groups and scripts, to organize them not only alphabetically) -Separators (to organize them even more) Thanx again.

February 13th, 2009 said:

Hey Ruben,

Thanks, those are both good ideas.  I'll see what I can do.

Jfeng
February 17th, 2009 said:

Really a versatile script,thx!

ft
February 24th, 2009 said:

wow, this is nifty...

I'm a big fan of your scripts. If I can suggest something that would be checkboxes to swap modifiers (ctrl/alt) - but more so everyone knows there are shortcuts to source/open the script and list all available folders in MAYA_SCRIPT_PATH to choose from. Thank you

February 26th, 2009 said:

That's a good idea, ft.  I'll add an option to configure the modifiers in the next version.

March 2nd, 2009 said:

Another very handy script. Thankyou.

What if we have a mel that contains different procs that we need to run? eg I have a parentShape script that contains a parentShapePreservePos() and a parentShapeMoveToPos(). The two procs work like a front end for the main code and save me having to use cmd-line aguments. Can I have more than one instance of a script in abScriptMenu, so that I can differenciate the Proc To Call?

thanks again.

March 2nd, 2009 said:

djx,

Yes, you can have multiple procs in the script list for a given mel file, they just have to have unique display names.

In your case you'll get the first entry automatically when the script scans your script directories.  You'll want to change the default proc to whichever procedure you want to call (e.g. parentShapePreservePos()), and update the display name to reflect that.  Once that's done, you can add the second proc (parentShapeMoveToPos()) using the "Add Single Script" button.

March 3rd, 2009 said:

Excellent. Thankyou.

marco
April 15th, 2009 said:

its should be located in the main menu bar? is that right? main menu bar is where i have window, display, select ...?

April 15th, 2009 said:

Yes, it should appear near the right side of your main menu bar.  If it doesn't, try running the following in your command line:

source abScriptMenu.mel;abSMbuildMenu();

which should add a new menu item to your main menu bar (called "Scripts").  Let me know if that doesn't work.

marco
April 16th, 2009 said:

it does not work. there is no new menu called scripts. os vista 64 max 64 icq:223429090

marco
April 16th, 2009 said:

ops i wrote max. i mean maya

April 23rd, 2009 said:

Hey Marco,

I don't know why it's not working for you.  I actually just set up a vista 64 machine with Maya 2008 and the script works without a hitch.

Make sure the script is in your script path, and that you run the source statement (that I gave two posts above this one) in the command line or script editor as mel (not python).

If you're doing all of that and it still doesn't work, I don't know...

May 7th, 2009 said:

This is brilliant. It helped me overcome Maya's disability to understand my problem in mirroring weights. Thanks a ton.

sean
July 1st, 2009 said:

hey thanks for the script.  where do i creat userSetup.mel?? I dont see one and i know how to make the file but just totally forgot where i should put.

thanks

July 2nd, 2009 said:

Hey Sean,

My userSetup.mel is in my mayaVersion\scripts directory.  I think it can go anywhere in your scriptPath, though.

sean
July 7th, 2009 said:

hey crumbly, i always have problems with this userSetup.mel for years...maybe i am really that good with mel scripts.  What i did was that i created userSetup.mel and wrote "source abScriptMenu.mel;abSMbuildMenu();" in it.  still not working...

is there a way to make this menu script to work when i put mel scripts in each folders? not just dump them all to the "scripts" folder? (ex.  maya\2009-x64\scripts\cometScript)

the only script that i put in 2009\scripts\ is your abScriptMenu, and rest of other scripts....i put them in separate folders which are also in the same scripts folder..

thanks..this is a really good script to get organized :)

July 9th, 2009 said:

Hmmm, I'm not sure what the problem is with your userSetup.mel.  Have you installed bonusTools?  It writes to the userSetup.mel too.  Maybe that's why I have one (not sure).

The script will work with mel scripts in folders in your scripts directory.  The problem is that you'll have to specify each one in the scripts text window, so it's sort of a pain.  I generally throw all my scripts into a couple of different folders -- when I wrote the script I didn't account for scanning sub directories.

September 21st, 2009 said:

waaaaahhhh nice script you got here very usable, thanks

PS would it be possible to add an icon button(would asign an icon to the shelf and or an add to shelf button.

September 24th, 2009 said:

Hey Bertmac,

Maybe I'm not understanding, but if you hold control+alt+shift and click on a script in the menu it should be assigned to your shelf.  Is it not working that way for you?

ez
May 4th, 2013 said:

Do you have an update for Maya 2013 - 2014 ?

Thanks

May 8th, 2013 said:

Hey ez,

I've included a new version of this script (which works in 2014) in the abAutoRig Premium download for the past several upgrades.  I was holding on to it because I wasn't sure how I wanted to release it, but I think it's best to just make it free.  I'll post it here after I finish writing this.

BTW, the new version has a bunch of nice features, including an improved UI, the ability to specify the order in which the scripts are listed, and the option to insert divider lines.


just say it






    

Related Posts