Use event listeners to subscribe to a parameter change

I want to be able to run specific code when a user changes a parameter of a model, I will do this using the ShapeDiver API. I believe I can get this working using event listeners, but I cant get it working following the ShapeDiver API documentation. I hope someone can help.


You can use the VALUE_UPDATE event from the parameters interface:

api.parameters.addEventListener(api.parameters.EVENTTYPE.VALUE_UPDATE, function(res) {
  // do something

Thanks for your reply. I believe thats the code used in the documentation, trying that gives me the following error:

Ive also tried window.api which doesnt work as well and gives the same error.

This is my code:

I should note that the ‘message’ event listener works fine.

Do you also correctly get the list of model parameters before you call SetupEventListeners()? It seems to me that this could be a timing issue. Depending on your environment, you might also need to add window. before calling the API?

Yeah I do, this is the console when refreshing the page

I just realized that you are probably using iframe embedding, which is not compatible with the event listeners. You will need to switch to direct embedding, as shown in this template for example:

Thanks for your reply. The reason for using iframes over direct embedding was because I was getting the following errors using direct embedding:

I also seem to be unable to render any kind of parameter controls when using direct embedding. Could this be due to these errors I’m having or something else?


Those errors happen in some cases but should not cause any issues. The controls are not part of the core viewer, if you want to include them instead of your own controls, you need to include a slightly more complicated template:

Thank you for your help! I have got embedding working now.

I was wondering if you could help with another query I have.

A model I’m working with has had two data outputs setup, yet when I attempt to log all exports on said model, an empty array is returned. See code and returned data below.
The following code:

Returns this:

I also have some models with around 6 different exports setup yet when I make an API call to fetch all exports I only have 4 returned.

I hope you can help.

If you are using data outputs, as you mentioned above, the correct function to use is


If you are actually talking about file exports, then I can test your model if you send me a link to it.

That works great. Thanks!