# Script to place assets

**URL:** <https://qa.fmod.com/t/script-to-place-assets/21689>\
**Category:** FMOD Studio\
**Tags:** javascript, studio-scripting-api\
**Created:** [June 1, 2024, 3:26pm UTC](https://qa.fmod.com/t/script-to-place-assets/21689 "2024-06-01T15:26:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dada\_da](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@dada\_da](https://qa.fmod.com/u/dada_da)\
**Post date:** [June 1, 2024, 3:26pm UTC](https://qa.fmod.com/t/script-to-place-assets/21689/1 "2024-06-01T15:26:15Z")

</div>

Hi,  
For a project I am trying to place around 100 assets (already imported to project) on a discrete parameter sheet and match the filename with the value of the parameter. Very similar to the Unity Piano FMOD example.

The parameter goes from 0-100, the filenames contain a number at the end of the file, think: sound\_01.wav, sound\_02.wav etc. After the script is run the file sound\_01.wav should be place at parameter value 1, the sound\_02.wav at parameter value 2 etc.

Could someone from FMOD team help me with a script to make this happen?  
That would be amazing!

---

<div class="post-metadata">

**Author:** ![dada\_da](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@dada\_da](https://qa.fmod.com/u/dada_da)\
**Post date:** [June 3, 2024, 8:42am UTC](https://qa.fmod.com/t/script-to-place-assets/21689/2 "2024-06-03T08:42:55Z")

</div>

Does someone from he FMOD team have an idea for this? Thanks a lot!

---

<div class="post-metadata">

**Author:** ![li\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/li_fmod/32/6577_2.png) [@li\_fmod](https://qa.fmod.com/u/li_fmod)\
**Post date:** [June 7, 2024, 1:47am UTC](https://qa.fmod.com/t/script-to-place-assets/21689/3 "2024-06-07T01:47:24Z")

</div>

Hi,

I have created a script that will allow you to assign multiple sound files based on numerical digits within each file’s name and corresponding parameter value numbers.

> **Assign Multiple Assets Script**
>
> ```auto
> studio.menu.addMenuItem({
> name: "User Scripts ...\\ Assign Assets",
> 
> execute: function () {
> function assignAssets(widget) {
> selectedEvent = studio.project.lookup(widget.findWidget("m_EventPathText").text()) //Assign the event's file path for later
> parm = selectedEvent.parameters[parseInt(widget.findWidget("m_EventParmNum").text(), 10)] //Retrieve the event parameter that you want to assign the audio files to
> audioFilesArr = studio.window.browserSelection() //Retrieve the currently selected audio files
> 
> //Loop through the array
> audioFilesArr.forEach(function(file, index) {
> if (file.isOfType("AudioFile")) {
> result = audioFilesArr[index].assetPath.match(/\d+/) //Pick out the digit from the file string
> number = parseInt(result[0], 10) //Convert the result to an int value
> 
> newInstrument = selectedEvent.groupTracks[0].addSound(parm, 'SingleSound', number, 1) //Create a single instrument on parameter's sheet, matching the file name digit and parameter value
> newInstrument.audioFile = file //Assign the matching audio file to the single instrument
> }
> });
> }
> 
> //widget UI design
> studio.ui.showModalDialog({
> windowTitle: "Assign Multiple Assets To First Parameter Sheet",
> windowWidth: 180,
> windowHeight: 150,
> widgetType: studio.ui.widgetType.Layout,
> layout: studio.ui.layoutType.VBoxLayout,
> items: [
> { widgetType: studio.ui.widgetType.Label, widgetId: "m_EventPathLabel", text: "EventPath :" },
> {
> widgetType: studio.ui.widgetType.LineEdit,
> widgetId: "m_EventPathText",
> text: "",
> onTextEdited: function () { },
> },
> { widgetType: studio.ui.widgetType.Label, widgetId: "m_EventParmLabel", text: "Parameter Number :" },
> {
> widgetType: studio.ui.widgetType.LineEdit,
> widgetId: "m_EventParmNum",
> text: "",
> onTextEdited: function () { },
> },
> {
> widgetType: studio.ui.widgetType.PushButton,
> text: "Apply",
> onClicked: function () {
> assignAssets(this);
> this.closeDialog();
> }
> },
> ],
> });
> }
> });
> 
> ```

Please follow these steps to use the script, also note that I haven’t put much error handling within the code.

1. Add the script to the local APP directory so it is available in all FMOD versions: `C:\Users\YourUserName\AppData\Local\FMOD Studio\Scripts`

2. Then in FMOD Studio, create an event and add a discrete parameter sheet to it.

3. Right click on the event and copy the file path for later use by selecting `Copy Path`

4. Open the `Assets` browser and select all target sound files.  
 **![](https://lh7-us.googleusercontent.com/docsz/AD_4nXdaorzaAej4jBrRiavJZShvyVQK_em-LpabzBG6f7pPbIdS5NrXd-QcDsk7NiNBRm9mWNVHPM4xdJfc-x_gIKDoCztqnFnEsYPhn9QPgwWsXu5FehLOEpD4zzq7EZTkwJjjXOwlDaJfPv2gM6eZ5CtDZKY?key=a_JmNXLbeK7Hdj7uhpyZfg)**

5. Reload and run the script with the `Asset` browser opened and audio files selected.  
 **![](https://lh7-us.googleusercontent.com/docsz/AD_4nXdc2bqnCEBfgpG3TWWOVI6RL_ZoOBB5s78bV7Xkzd5CDqBtGq87-nAOiI_ptuGZuTUlZEwe6cKOJ6kVOxVajNQYNTkkmgG9XsJn_Si4TV_0GsWauTFZkKyJmCiidqWf1AEHEdXCa9SNZ-9MGGaLXhIHpBnG?key=a_JmNXLbeK7Hdj7uhpyZfg)**

6. Input the file path you just copied and the index of the parameter sheet, hit `Apply`  
 **![](https://lh7-us.googleusercontent.com/docsz/AD_4nXfZSwAOScpFfaZX0jmoTtGTRpoy1D0-iulDIi4rtLWIvGwXWBUrdZX1IqfOgYd6h85v748WJX766kE9ye6I2nrNX5FV0ZeKElVlxQJMLLVhVke4p1YOiUIXU-_UFxp6gqUCwYw6erU-QcGMu8WOq7VEeEM?key=a_JmNXLbeK7Hdj7uhpyZfg)**

For more information, you could also take a look at a similar post which I will link it here:

> [@Adding audio files automatically to a parameter sheet label](https://qa.fmod.com/t/adding-audio-files-automatically-to-a-parameter-sheet-label/21662):
>
> Hello everyone, I have been trying to figure out how to script the addition of an audio file to each label of a parameter sheet. So far, I have been manually dropping the audio file into the track for each label, but this process is quite tedious, as I have to do it for dozens of parameter sheets. I am using project.importAudioFile to import the audiofiles with their paths and I tried to use GroupTrack.addSound but I can’t figure out how to use it with a parameter sheet, I only foun…

Let me know if you have any questions, and please feel free to modify the script according to your needs.

---

<div class="post-metadata">

**Author:** ![dada\_da](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@dada\_da](https://qa.fmod.com/u/dada_da)\
**Post date:** [June 10, 2024, 2:55pm UTC](https://qa.fmod.com/t/script-to-place-assets/21689/4 "2024-06-10T14:55:59Z")

</div>

Thanks so much! I had to simplify my naming, but this works! Awesome!
