Showing posts with label creating a new shelf. Show all posts
Showing posts with label creating a new shelf. Show all posts

Friday, November 11, 2011

The Shelf - Adding MEL Commands

Creating a shelf button for tasks and commands that you do regularly throughout your
work flow can be a huge time saver and incredibly easy to do with a few steps.

Adding a MEL Command to the Shelf

1. Decide which shelf you want to add your custom MEL command to.

    For our purposes, we'll use the Custom shelf we created in an earlier post about the Shelf.

    Click on the tab labeled "Custom" on the Shelf.
 

2. The MEL Command Statement(s)

    If you recently accessed the command, you can find it in the History Panel. 
    Otherwise, you can retype it. In our example, we'll use the following command statement:

    textCurves -t "Hello World!" ;

3. Highlight the Satement (see Figure 1) with your mouse.

Figure 1 -Highlight the Statement

4. Save the Script to the Shelf

    There are 2 options you can choose from here:
   
    Option 1: Click and Drag 
  • With the left mouse button, simply click and drag the statement directly to the Shelf.
  • A dialog box will appear, giving you the option to save the command to the Shelf either in MEL or in Python.
  • Select button that says MEL. 

        Option 2: Saving via the Script Editor Menu
    • In the Script Editor menu (NOT the main Maya menu. See Figure 2), go to:                                           File > Save Script to Shelf...
    Figure 2 - Save Script to Shelf
    • A dialog box will appear, giving you a chance to save the command with any name we'd like to give it. 
    • I decided to give it the name, "hello"
    • A dialog box will appear, giving you the option to save our command to the Shelf as either in MEL or  in Python.
    • Select button that says MEL.
    5. Pat yourself on the back

        You've just turned your script into a custom shelf button for future use! (see Figure 3)

    Figure 3 - Results of Options 1 and 2

         Now you'll never have to write the complete statement, textCurves -t "Hello World!"; again!

         A simple press of the button in the Shelf will execute the command!

    Deleting Items from the Shelf: 
    You may want to delete shelf buttons for a variety reasons. Here's how:

    • With your middle mouse button, click & drag the shelf button to the Trashcan icon, which is located at the far right of the Shelf (see Figure 4).

    Figure 4 - Trashcan Icon for the Shelf
     






    Conclusion:
    Remember, this is just a proof of concept; you probably won't ever be in desperate need
    to automate a "Hello World" text curve into your scene.

    However, this example opens up so many possiblities, especially when considering an extremely complex set of instructions (MEL commands) can be encapsulated into a simple button!

    For instance, what if you had a task that required you to the following steps:
    • center pivot of all objects
    • freeze transformations of all objects
    • delete history of all objects
    • save the file
    Going through all those steps to perform a task would be a real pain, especially if you do it often.

    Wouldn't it be nice if there was just one button to do all of these steps? Using what we just learned as a foundation, it won't be difficult to do.

    Of course, before we can create a complex MEL script, we have to know how to make a simple one! Like so many teachers have told me in the past:
    • Learn to stand before you walk.
    • Learn the ABCs before you write your novel.
    Next Blog Post:
    Creating a MEL Script!
       

    The Shelf and Creating a New Shelf

    Figure 1 - the Shelf
    When you probably first started Maya, you may have noticed that even though you can create a polygonal sphere from Maya's main menu, you could also just click on a button on the Shelf (see Figure 1) to create one, as well.

    But did you know that you can actually add custom buttons to the Shelf?

    Creating a shelf button for tasks and commands that you do regularly throughout your workflow can be a huge timesaver and incredibly easy to do.

    There are 2 parts to this process:
    1. Decide which shelf you want to add your MEL command - or create a new Shelf, altogether.
    2. Adding the MEL command to the Shelf

    The Shelf
    If you don't see the Shelf in Maya's interface, you can activate it in Maya's main menu (see Figure 2 ):

        Display > UI Elements > Shelf
    Figure 2 - Displaying the Shelf

    Creating a new Shelf
    1.  Along the Shelf, at the far left, there's an icon with a downward-pointing arrow (see Figure 3). 

    Figure 3 - Shelf Icon
     
    2.  With your left mouse button, click & hold over the downward-pointing arrow icon.

    3.  A dialog box will pop up, but will disappear if you release your mouse button's hold.

    4.  Click on the option, "New Shelf"

    5.  A dialog box will appear, prompting you to enter the name of the new shelf we are creating (see Figure 4).

    Figure 4 - Dialog box to name the new Shelf
     
    6.  For now, let's give it the name, "Custom", but you can give it any name you wish.

    7.  click "Ok".

    Creating a new shelf means we don't have to clutter the other default Maya shelves. Not to mention, its a great way to keep our shelf buttons organized once you become a MEL guru and start writing all kinds of different custom MEL commands and scripts.

    Next Blog Post: