# Script For Setting Platform Exclusion on All Instances of an Effect

**URL:** https://qa.fmod.com/t/script-for-setting-platform-exclusion-on-all-instances-of-an-effect/20945
**Category:** FMOD Studio
**Tags:** javascript
**Created:** [December 4, 2023, 5:14am UTC](https://qa.fmod.com/t/script-for-setting-platform-exclusion-on-all-instances-of-an-effect/20945 "2023-12-04T05:14:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JSMallard](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@JSMallard](https://qa.fmod.com/u/JSMallard)
#### Post date: [December 4, 2023, 5:14am UTC](https://qa.fmod.com/t/script-for-setting-platform-exclusion-on-all-instances-of-an-effect/20945/1 "2023-12-04T05:14:32Z")

</div>

Hey Everyone! I was reading through this post here and it seems like @jashan accomplished what I am trying to do.

> [@Is there a way to batch-disable effect for a platform on all events?](https://qa.fmod.com/t/is-there-a-way-to-batch-disable-effect-for-a-platform-on-all-events/18693/4):
>
> I ended up writing a little console app that iterates over all the event XML-files and adds PS5 to the exclusion list for the Oculus Spatializer plugin. A bit hacky but worked as intended.

Oculus Spatializer is not usable with PSVR and I have been switching to Resonance Audio for compatibility on multiple platforms. I want to make a script that can change platform exclusion on the Oculus Spatializer plugin that is on a ton of events.

I am not using preset effects and can’t batch edit the events due to their differences. Is there a way to access and set the platform exclusion proprety of Oculus Spatializer? Accessing that is where I got stuck. Any help is very appreciated!

---

<div class="post-metadata">

### Author: ![JSMallard](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@JSMallard](https://qa.fmod.com/u/JSMallard)
#### Post date: [December 5, 2023, 5:14pm UTC](https://qa.fmod.com/t/script-for-setting-platform-exclusion-on-all-instances-of-an-effect/20945/2 "2023-12-05T17:14:53Z")

</div>

I found a lead on this, but am not as sure about the specific modification of platform exclusion in a way that is safe.

> [@FMOD JS Scripting - Getting effect properties from plugin effect](https://qa.fmod.com/t/fmod-js-scripting-getting-effect-properties-from-plugin-effect/18456/2):
>
> To get the settings of the Oculus effect, you need to iterate through each of the plugin’s parameters. Try this bit of code: var selectedEvents = studio.window.browserSelection(); selectedEvents.forEach(function(event) { var effectChain = event.masterTrack.mixerGroup.effectChain; var effectChainEffects = effectChain.effects; effectChainEffects.forEach(function(eventEffect) { if(eventEffect.isOfType("PluginEffect")) { …

Using something like this, I can see what platform are excluded. It looks like this is not a pluginParameter though and changing it would mean changing several values? Ideally, I want to safely switch what platforms are excluded and not.

```auto
studio.menu.addMenuItem({
    name: "Disable Oculus Spatitalizers",
    execute: function() {
		var selectedEvents = studio.window.browserSelection();
		selectedEvents.forEach(function(event)
			{
				var effectChain = event.masterTrack.mixerGroup.effectChain;
				var effectChainEffects = effectChain.effects;
				effectChainEffects.forEach(function(eventEffect)
					{
						eventEffect.excludedPlatforms.forEach(function(excludedPlatforms) 
						{
							console.log(excludedPlatforms.dump());
						});
					});
			});
    },
});

```

---

<div class="post-metadata">

### Author: ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)
#### Post date: [December 6, 2023, 4:03am UTC](https://qa.fmod.com/t/script-for-setting-platform-exclusion-on-all-instances-of-an-effect/20945/3 "2023-12-06T04:03:04Z")

</div>

> [@JSMallard](#):
>
> Using something like this, I can see what platform are excluded. It looks like this is not a pluginParameter though and changing it would mean changing several values? Ideally, I want to safely switch what platforms are excluded and not.

To add a platform to an effect’s `excludedPlatforms` array, you need to add it via the effect’s relationships - for example:

```auto
// get current platform
var platform = studio.project.workspace.projectSettings.activePlatform;
// add it to the effect's excluded platforms
eventEffect.relationships.excludedPlatforms.add(platform);

```

I’ve modified your script to use the effect’s relationships to toggle whether the Oculus Spatializer effect is excluded from the currently selected plaform. Give it a try and let me know whether you run into any issues.

```javascript
studio.menu.addMenuItem({
    name: "Toggle Oculus Spatializers for Current Platform",
    execute: function() {
		var platform = studio.project.workspace.projectSettings.activePlatform; // get current platform
		var selectedEvents = studio.window.browserSelection();
		// iterate over browser selection
		selectedEvents.forEach(function(event)
		{
			// check whether event is selected
			if (event.isOfExactType("Event"))
			{
				var effectChain = event.masterTrack.mixerGroup.effectChain;
				var effectChainEffects = effectChain.effects;
				// iterate over effects in event's master track
				effectChainEffects.forEach(function(eventEffect)
				{
					// if current effect is a plugin effect
					if (eventEffect.isOfExactType("PluginEffect"))
					{
						// if plugin effect is oculus spatializer
						if (eventEffect.plugin.identifier === "Oculus Spatializer")
						{
							// check whether effect is already excluded so exclusion can be toggled
							var index = platformsArrayIncludes(eventEffect.excludedPlatforms, platform)
							if (index >= 0)
							{
								eventEffect.relationships.excludedPlatforms.remove(platform);
							}
							else
							{
								eventEffect.relationships.excludedPlatforms.add(platform);
							}
									
						}
					}
				});
			}
		});
    },
});

// helper function to check whether platform is already excluded
function platformsArrayIncludes(array, platformToCheck){
	var index = -1;
	array.forEach(function(platform){
		index++;
		if (platform.id === platformToCheck.id) return index;
	});
	return index;
}

```

---

<div class="post-metadata">

### Author: ![JSMallard](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@JSMallard](https://qa.fmod.com/u/JSMallard)
#### Post date: [January 9, 2024, 6:56pm UTC](https://qa.fmod.com/t/script-for-setting-platform-exclusion-on-all-instances-of-an-effect/20945/4 "2024-01-09T18:56:40Z")

</div>

I was finally able to test this out, and it works perfectly! Really amazed at how much scripting can do. Thank you very much!

For anyone wondering, I am using this to disable Oculus Spatializer on PSVR builds. When using PSVR, I run another version of the script to disable Resonance Audio on Oculus builds. For my purposes, this lets me test or change spatialization solutions on the fly.
