Maya MEL Scripting: Episode 03 (update)

Using the .ASS file format and some MEL script to build your own asset library, Maya/Arnold

Some explanation:
This is a simple example of how to use MEL and Arnold the smart way.

ASS is Arnold’s own file format. It can contain every kind of data: geometries, instances (also the result of a MASH network via the Instancer node), complex hierarchy of objects.
In some cases links to those data, like openVDB files etc.
It can also contain shaders and links to textures etc.

Simply put: it’s very versatile.

I wrote a simple MEL script to export the first selected object/group/locator as ASS and use the second selected object as a proxy.
I’m using the fileBrowser command to get a simple target folder for the ASS file.
Check the comments. It might help you.

// define the proc for the FileBrowser Command
global proc int ddTargetFolderASS(string $dirpath,string $type) 
{
    ///////////////////////////////////////////////////////////////////////
    // Freeze transform before export to avoid Double Transformation
    makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 -pn 1;
    
    // Get the list from Selection. 
    // The first selected object (or group or locator) will be the exported ASS the second one will be the proxy of that.
    string $ddAssSel[] = `ls -sl`;
    
    ///////////////////////////////////////////////////////////////////////
    // Create the variables for manageable paths
    // The folder path
    string $path = ($dirpath + "/");
    // The filename = the selected Group's name
    string $filename = $ddAssSel[0];
    // The extension in this case .ass
    string $extension = ".ass";
    // Put everything together
    string $fullpath = $path + $filename + $extension;
    
    ///////////////////////////////////////////////////////////////////////
    // Select the group for exporting
    select $ddAssSel[0]; 
    // Export the selection as .ass
    file -force -options "-shadowLinks 1;-mask 6399;-lightLinks 1;-boundingBox;-fullPath" -typ "ASS Export" -pr -es $fullpath;
           
    // Set the proxy shape attributes 
    string $shName[] = `listRelatives -s $ddAssSel[1]`; 
    setAttr ($shName[0] + ".aiTranslator") -type "string" "procedural";
    setAttr ($shName[0] + ".dso") -type "string" $fullpath;
    setAttr ($shName[0] + ".aiOverrideLightLinking") 0;
    setAttr ($shName[0] + ".aiOverrideShaders") 0;
    
    // Turn off visibility for the exported Group (or object)
    setAttr ($ddAssSel[0] + ".visibility") 0;
    
    ///////////////////////////////////////////////////////////////////////
    // Select the proxy for easier usage
    select $ddAssSel[1];
    // And export the proxy geo as .ma file, so you can import it in any scene
    file -force -options "v=0;" -typ "mayaAscii" -pr -es ($path + "proxy_" + $filename + ".ma");
    
    return true; 
}

// Run the target folder query and the commands
fileBrowser("ddTargetFolderASS", "Select the Target Folder", "", 4 );

The main parts are:

  1. Create the procedural
  2. Get the selections
  3. Build the path as variables
  4. Export the ASS
  5. Set the attributes on the Proxy Geo
  6. Export the Proxy Geo as .ma to the same folder
  7. Run the proc (folder query and commands)

Of course, you can use those proxy objects in any scatter. An obvious example is a tree with scattered leaves and stuff.
So this way you can scatter a scatter. 🙂

You can build more complex assets (asset clusters) with multiple objects and multiple scatters and export those as ASS. In this case, you have to remove the freeze transform part!

Cheers, D

Update

I changed how the shape node’s name is handled. Now it should work every time.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.