# Automating audio file import and assignment to event instruments via scripting API

**URL:** <https://qa.fmod.com/t/automating-audio-file-import-and-assignment-to-event-instruments-via-scripting-api/22751>\
**Category:** FMOD Studio\
**Tags:** javascript\
**Created:** [March 31, 2025, 11:20am UTC](https://qa.fmod.com/t/automating-audio-file-import-and-assignment-to-event-instruments-via-scripting-api/22751 "2025-03-31T11:20:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![norbertweiher](https://avatars.discourse-cdn.com/v4/letter/n/b38774/32.png) [@norbertweiher](https://qa.fmod.com/u/norbertweiher)\
**Post date:** [March 31, 2025, 11:20am UTC](https://qa.fmod.com/t/automating-audio-file-import-and-assignment-to-event-instruments-via-scripting-api/22751/1 "2025-03-31T11:20:59Z")

</div>

Hello team FMOD!  
The game I’m currently working on has a lot of characters that share a similar setup for their sound events. I’m writing a script to automate the import process. Here’s what I’m trying to achieve:

- Using currently selected audio assets in FMOD Studio (working).
- Grouping files with the same prefix (differing only in variation numbers) (working).
- Creating events with a track that contains a multi-instrument for each group (working).
- Adding volume and pitch modulators to the multi-instrument (working).
- Placing events in the correct folder structure - (not working yet).
- Setting the length of the created multi-instrument to the length of the contained assets (not working yet).
- Assigning the created event to a bank that corresponds to the character name (not working yet).

I got quite a lot working already, but I’m having trouble with the last three parts (properly assigning an event folder to the newly created event, adding it to a bank and setting the length of the created multi-instrument to the length of its content, like the corresponding context menu item).

I manage to put the event in the events master folder, using this code:

```auto
       var myEvent = studio.project.create("Event");
        myEvent.name = eventName;
        // Set the events folder to the root event folder.
        myEvent.folder = studio.project.workspace.masterEventFolder;

```

For the bank assignment and resizing the multi-instrument I haven’t managed to get anything working yet.

Could you point me in the right direction as to which functions to use for these tasks?

If it helps, I’m happy to share the script I’ve created so far!

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [April 1, 2025, 2:23am UTC](https://qa.fmod.com/t/automating-audio-file-import-and-assignment-to-event-instruments-via-scripting-api/22751/2 "2025-04-01T02:23:33Z")

</div>

Hi,

> [@norbertweiher](#):
>
> Placing events in the correct folder structure - (not working yet).

You can find all the `EventFolder`’s in your project with:

```js
var folders = studio.project.model.EventFolder.findInstances()
folders.forEach(function(folder) { console.log(folder.name) } )

```

You can then find the folder you are looking for with something like:

```js
folders.forEach(function(folder) {
if (folder.name == "The folder I want")
    myEvent.folder = folder;
})

```

> [@norbertweiher](#):
>
> Setting the length of the created multi-instrument to the length of the contained assets (not working yet).

I previously made a script for creating an event with an multi instrument on a button press:  
[Create3DMultiEventMacro.js.txt](https://qa.fmod.com/uploads/short-url/4J2GXDngzvh3Q6qCU96KgEAbGVc.txt) (1.9 KB). Specifically for setting the length you would use:

```auto
track.addSound(event.timeline, 'MultiSound', 0, /*Set length here*/)

```

> [@norbertweiher](#):
>
> Assigning the created event to a bank that corresponds to the character name (not working yet).

To assign an event to a bank you add it to the `relationships` ([FMOD Studio | Scripting API Reference - Project.ManagedObject](https://fmod.com/docs/2.02/studio/scripting-api-reference-project-managedobject.html))

```auto
var myEvent = studio.window.browserCurrent()
undefined
var bank = studio.window.browserCurrent()
undefined
myEvent.relationships.banks.add(bank)
true

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![norbertweiher](https://avatars.discourse-cdn.com/v4/letter/n/b38774/32.png) [@norbertweiher](https://qa.fmod.com/u/norbertweiher)\
**Post date:** [April 1, 2025, 1:51pm UTC](https://qa.fmod.com/t/automating-audio-file-import-and-assignment-to-event-instruments-via-scripting-api/22751/3 "2025-04-01T13:51:18Z")

</div>

Thanks so much Connor!

That was the missing piece, now it’s all working.

After browsing the forum a bit more I also managed to add FX presets to my master track chain and some modulators to the created multi instrument.

Happy days!

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [April 2, 2025, 4:52am UTC](https://qa.fmod.com/t/automating-audio-file-import-and-assignment-to-event-instruments-via-scripting-api/22751/4 "2025-04-02T04:52:11Z")

</div>

Great to hear it worked!

If you have any more questions please do not hesitate to ask!
