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);
}