Skip to content

Instantly share code, notes, and snippets.

@electricazimuth
Created August 23, 2023 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electricazimuth/9fb6aff5585d503742415594bf5ebcde to your computer and use it in GitHub Desktop.
Save electricazimuth/9fb6aff5585d503742415594bf5ebcde to your computer and use it in GitHub Desktop.
Fmod export timeline markers to json file
/*
-------------------------------------------
Exporting Markers
-------------------------------------------
This is a simple export of markers to a json file
I'm filtering only NamedMarker with names
Set showlogs to true to get output to the console window in Fmod
console can be opened with ctl+0 in fmod studio
*/
studio.menu.addMenuItem({ name: "Named Markers To File",
// if no event is selectd, the script can not be executed
isEnabled: function() { var event = studio.window.browserCurrent(); return event && event.isOfExactType("Event"); },
keySequence: "Alt+E",
showlogs: false,
log: function(str){
if(this.showlogs){
console.log(str);
}
},
execute: function() {
//get the current selected event
var event = studio.window.browserCurrent();
var output = {};
//get all events and not only the selectd one
//var events = studio.project.model.event.findInstances();
this.log("############ Markers #################");
for (x = 0; x < event.markerTracks.length; x++){
for (y = 0; y < event.markerTracks[x].markers.length; y++){
if( event.markerTracks[x].markers[y].entity == "NamedMarker"){
var pos = event.markerTracks[x].markers[y].position;
var name = event.markerTracks[x].markers[y].name;
if( name != "undefined"){
this.log("Marker:" + name + " " + pos);
output[name] = pos;
}else{
this.log("Undefined Marker:" + name + " " + pos);
}
}else{
this.log("Not exporting type: {" + event.markerTracks[x].markers[y].entity + "} marker named: " + event.markerTracks[x].markers[y].name );
}
}
}
this.log("############ Output #################");
this.log( JSON.stringify(output) );
// Save the file
var projectFile = studio.project.filePath;
var projectPath = projectFile.substr(0, projectFile.lastIndexOf("/") + 1);
var filename = projectPath + event.name + ".marker.json";
this.log("Saving to: " + filename );
var jsonfile = studio.system.getFile(filename);
jsonfile.open(studio.system.openMode.WriteOnly);
jsonfile.writeText( JSON.stringify(output) );
jsonfile.close();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment