Home Technical Talk

Help making a MEL script

polycounter lvl 11
Offline / Send Message
Brygelsmack polycounter lvl 11
I basically have zero scripting knowledge, but I want to make a simple MEL script that makes CryEngine exporting faster for me. Can anyone help me out with how I can achieve this? This should save a bunch of time since I export from Maya very often.

In the following order I want to:

1. Select one or multiple objects (obviously I do that myself)
2. Create a group called cryexportnode_[name of object]
3. Create a sub-group called group_[name of object]
4. Select the top of the hierarchy (cryexportnode group)

It would be cool if I click my shelf button I get a window in which I can specify the name of my object I'm exporting (essentially text that replaces "name of object" above.

This is the hierarchy I want to create:

Cebb1pW.jpg

Thanks for any help!

Replies

  • Saf
    Options
    Offline / Send Message
    Saf polycounter lvl 11
    I'm just starting to learn Python. The code is ugly, but seems to work.
    You can select one or more object, "_and_" between them will be added to the new group name.

    import maya.cmds as cmds
    def CryExportPy():
    	Sel1 = str(cmds.ls (selection=True, objectsOnly=True))
    	Sel2 = Sel1.replace("u","").replace("]","").replace("[","").replace("'","").replace(" ","").replace(",","_and_")
    	Sel_List = Sel1.replace("u'","").replace("'","").replace("[","").replace("]","").replace(" ","").split(',')
    	cmds.group( empty=True, name=('group_'+Sel2) )
    	for i in range(len(Sel_List)):
    		listNum = Sel_List.pop()
    		cmds.parent( listNum, ('group_'+Sel2), a=True )
    	cmds.group( ('group_'+Sel2), name=('cryexportnode_'+Sel2))
    	cmds.select ('cryexportnode_'+Sel2)
    CryExportPy()
    
  • e-freak
    Options
    Offline / Send Message
    There should be a Tools Button in the Crytek Shelf, that has a "create CryExport Node" action in it. That will do just that and also add the custom properties to the CryExportNode Group with the necessary meta data for export.
  • Deadly Nightshade
    Options
    Offline / Send Message
    Deadly Nightshade polycounter lvl 10
    Most people trying to get into scripting in Maya (or of any kind really) usually have a big problem knowing where to start. Yes, you have the official documentation here: http://download.autodesk.com/global/docs/maya2013/en_us/Commands/

    ...but just going with that is like getting an English-Mandarin dictionary and then being told to learn chinese.

    You should start by going into the script editor and up to "History" and check the top four checkboxes. This will make the script editor echo out all the commands (and errors) that you do in Maya. So if you for example select something and create a group, you will see this:
    // Result: scriptEditorPanel1Window|TearOffPane|scriptEditorPanel1|formLayout108|formLayout110|paneLayout2|cmdScrollFieldReporter1 // 
    contextToolsMM "MayaWindow|formLayout1|viewPanes|modelPanel4|modelPanel4|modelPanel4|modelPanel4CommandPop";
    CreatePolygonCube;
    performPolyPrimitive Cube 0;
    polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;
    // Result: pCube2 polyCube2 // 
    // Result: polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1 //
    
    ...followed by even more lines prompting // Result: 0 //

    So then what? What here is useful? The easiest way to find out is to first go to Edit and then Clear All PRIOR to doing the stuff you want to script (like in this case, creating a cube and then group it).
    So at the top you have things like Panel4CommandPop and performPolyPrimitive

    Now to find out what is a command and what is just a MEL-procedure call, you can use the MEL-command whatIs - like this:
    whatIs performPolyPrimitive
    // Result: Mel procedure found in: X:/Autodesk/Maya2014/scripts/others/performPolyPrimitive.mel //

    or...
    whatIs select;
    // Result: Command //

    Continue using whatIs and open up native mel-scripts like the one mentioned above, reading the documentation and you will catch up with the syntax (programming grammar) in no time.

    Python is cool too (In fact, I prefer it over MEL) but imo it's smarter to first at least study a bit of MEL because a great part of Maya runs on MEL-commands. Also, even if you go all-out Python, you still need to learn Maya commands in order to make anything useful.

    If you want to get into Python then this is an amazing place to start:
    www.codeacademy.com

    Maybe this reply is a bit overkill, and maybe you are not that interested in learning more scripting - but I thought I should point this out in case someone else is interested. Good luck!
  • Brygelsmack
    Options
    Offline / Send Message
    Brygelsmack polycounter lvl 11
    e-freak wrote: »
    There should be a Tools Button in the Crytek Shelf, that has a "create CryExport Node" action in it. That will do just that and also add the custom properties to the CryExportNode Group with the necessary meta data for export.
    Thanks! Had no idea about this, never really checked out the other Cry tools... My bad.

    Sorry for wasting your time Saf and Deadly Nightshade, appreciate the help though. (:
  • Bartalon
    Options
    Offline / Send Message
    Bartalon polycounter lvl 12
    Thanks! Had no idea about this, never really checked out the other Cry tools... My bad.

    Sorry for wasting your time Saf and Deadly Nightshade, appreciate the help though. (:

    Damn it, and I just wrote something out lol. Here it is anyway I guess
    proc exportToCryEngine() {
        string $prompt = `promptDialog
            -title "Cryengine Export"
            -message "Label your node:"
            -button "OK" -button "Cancel"
            -defaultButton "OK" -cancelButton "Cancel"
            -dismissString "Cancel"`;
    
        if ($prompt == "OK") {
            string $name = `promptDialog -q -tx`;
            if ($name == "") { error "Name cannot be blank"; }
            else {
                string $sel[] = `ls -sl`;            
                string $group1 = `group -n ( "group_" + $name )`;
                string $group2 = `group -n ( "cryexportNode_" + $name )`;
                select -hi;
                ExportSelection;
            }
        }
    }
    
    exportToCryEngine;
    evalDeferred "undo;";
    

    The last line of code will undo any grouping and return everything to where it started. Remove it if you want to keep all the automatic grouping.
  • Brygelsmack
    Options
    Offline / Send Message
    Brygelsmack polycounter lvl 11
    I will still try that out, it's pretty neat with a shelf button. Thanks!
Sign In or Register to comment.