Search code examples
javascriptmayaadobe-illustratormel

Illustrator file that runs commands upon opening


This is a long shot, but is there a possible way to store a JavaScript (or any sort of executable code) within an Adobe Illustrator file?

The reason I'm asking this is because I'm currently trying to automate the process of importing render results from Autodesk Maya. The concept is that as soon Maya is done rendering all frames/layers, a MEL script could generate a file that Illustrator could open and run commands found in it, directing illustrator to the render results and start importing them.

The original idea was to give a system command via MEL script to launch Illustrator straight away after rendering completion and somehow start the process. But since this automation is for not-so-tech-savvy people, an application calling for the launch of another one would be rather frustrating and maybe confusing.

Having Maya generate a file that can complete the task when the user opens it is a much preferred solution. Give more control to the user and does not overload a system that is already busy with more application calls.

Think of it like a .mel file, where upon opening, it launches the needed application (Maya) and when the application is ready, carries out the commands included (MEL). Is there a way to do that with Adobe applications, Illustrator in particular, where a file automatically is recognized as an Illustrator file (eg. .ai), launches application and then runs code contained in it (eg. JS)?

ANY help is welcomed, but I would like to avoid applescripts/VBS as they are platform specific and can be difficult to manage between Mac/Windows.

Thanks.


Solution

  • This is a relatively broad question as there can be many ways to achieve this. I'll try to give you one possible solution here, it clearly might not be the best.


    Your needs:

    • Create a "file" or something that imports all the Maya's rendered images in an illustrator scene.
    • Can be executed whenever you want (No post render process that opens illustrator)
    • Non-tech people like my mom have to be able to use it.
    • Cross-platform (Win/Osx)

    Solution:

    • Create a post-render script (mel or python) for Maya
    • Concerning this script (.mel or .py):
      • Is run once all frames have been rendered
      • Copies an existing JavaScript (.jsx) file in the folder where the frames have been rendered
      • Creates two executable files (.bat and .command, both for Windows and OSX)
    • Concerning the .jsx file:
      • Creates a new .ai file
      • Imports the rendered frames one by one and adds them in a new artboard
      • Saves the .ai file in the current folder
    • Concerning the .bat and .command executables:
      • Run Illustrator
      • Execute the .jsx script on startup

    To sum up, once the frames will have been rendered, all three files (.jsx, .bat, .command) will be created in the same folder as the frames. When your artists will want to create their Illustrator scene, they'll just have to double click on the .bat or .command file to automatically run Illustrator and import the rendered frames and save the file.

    The command to run a script on Illustrator (CS 5.1) on Windows is and this will be the content of the .bat file:

    "C:\Program Files (x86)\Adobe\Adobe Illustrator CS5.1\SupportFiles\Contents\Windows\Illustrator.exe" C:\Path\To\Script.jsx

    You can easily make an equivalent for the .command file.

    Script.jsx can be something like this:

    // Get the fullpath of the script
    var script_fullpath = $.fileName
    // Only get the folder path
    var script_folder   = Folder(script_fullpath).path
    // Get renderred frames
    var rendered_frames = Folder(script_folder).getFiles("*.exr");
    
    if(rendered_frames.length == 0){
        alert("No images to import");
    }else{
        // Loop through all the images
        // Create a new artbook
        // Import Fram
        // Then save the file here: script_folder + "/" + "illustratorFile"
    }