FMOD Studio Script to retrieve automation data

I’m trying to generate a .js script to retrieve the information of all the automations inside a FMOD Studio project. This is the script I’ve been working on, but I can’t seem to find the right data. I achieved to retrieve a list of all the events in the project, but then, I can’t find any more information. All the variables “automator”, “automationCurve”, and so on are empty, even if there are automations in my project.

Do someone know how could I retrieve the information of the automation curves/points, or at least, where is it stored or why are all those variables empty?

Thank you!

Script code:

studio.menu.addMenuItem({
    name: "Export Automation JSON",
    execute: function () {
        exportAutomationJSON();
    }
});

function exportAutomationJSON() {
    var events = studio.project.model.Event.findInstances();
    if (!events || events.length === 0) {
        alert("No s'han trobat events al projecte");
        return;
    }

    var data = {};

    events.forEach(function (event) {

        var eventData = {
            name: event.name,
            path: event.getPath(),
            automations: []
        };

        function extractAutomationFrom(obj, label) {
            if (!obj || !obj.modulators) return;

            obj.modulators.forEach(function (modulator) {
                if (modulator.automation && modulator.automation.points.length > 0) {
                    var points = modulator.automation.points.map(function (pt) {
                        return {
                            time: pt.time,
                            value: pt.value
                        };
                    });

                    eventData.automations.push({
                        context: label,
                        modulatorType: modulator.type,
                        points: points
                    });
                }
            });
        }

        function traverseTrack(track, pathLabel) {
            extractAutomationFrom(track.volume, pathLabel + " Volume");
            extractAutomationFrom(track.pitch, pathLabel + " Pitch");

            if (track.modules) {
                track.modules.forEach(function (module, i) {
                    // Nom de l'efecte
                    var modLabel = pathLabel + " > Effect[" + i + "] (" + module.name + ")";
                    extractAutomationFrom(module.volume, modLabel + " Volume");
                    extractAutomationFrom(module.pitch, modLabel + " Pitch");

                    // Altres propietats que podrien tenir moduladors
                    if (module.properties) {
                        Object.keys(module.properties).forEach(function (propName) {
                            var prop = module.properties[propName];
                            extractAutomationFrom(prop, modLabel + " Property: " + propName);
                        });
                    }
                });
            }

            if (track.children) {
                track.children.forEach(function (childTrack, i) {
                    traverseTrack(childTrack, pathLabel + " > SubTrack[" + i + "]");
                });
            }
        }

        try {
            if (event.masterTrack) {
                traverseTrack(event.masterTrack, "MasterTrack");
            }
        } catch (e) { alert(e); }

        if (eventData.automations.length > 0) {
            data[event.getPath()] = eventData;
        }
    });

    var json = JSON.stringify(data, null, 4);

    var outputPath = studio.project.filePath;
    if (!outputPath) {
        alert("No es pot determinar la ruta del projecte. Guarda el projecte abans d'executar.");
        return;
    }

    outputPath = outputPath.replace(/\\/g, "/");
    outputPath = outputPath.substr(0, outputPath.lastIndexOf("/") + 1) + "automation_export.json";

    var textFile = studio.system.getFile(outputPath);
    if (!textFile.open(studio.system.openMode.WriteOnly)) {
        alert("No s'ha pogut obrir el fitxer per escriure.");
        return;
    }

    textFile.writeText(json);
    textFile.close();

    alert("Exportació d'automatitzacions completada a:\n" + outputPath);
}

Hi,

All property modulations for events belong to master/group tracks. Any automation applied to properties or modules on that track can be found in track.automationTracks[i]. You can find the following information for a given var automationTrack = track.automationTracks[i]:

  • The name of the property being automated is stored in automationTrack.automator.nameOfPropertyBeingAutomated
  • The object (i.e. module, effect, etc.) being automated is stored in automationTrack.automator.objectBeingAutomated
  • The points of the automation curve are stored as an array automationPoints belonging to the given automation curve - i.e. `automationTrack.automator.automationCurves[j]

For reference, the function .dump() can be used on all ManagedObjects in the Studio Scripting API, and will provide a list of all members for that object, which is helpful when writing scripts.

Okey, I found about the variable “track”, but how do I access to all the tracks?
I know events can be gathered like:

var events = studio.project.model.Event.findInstances();

The problem is that the class Event does not have a track variable inside to then access track.automationTracks[i].

I hope you could answer my new question!

Thank you for your response, it was super useful!