Apply parameters to ShapeDiver model during mount

I’d like to initialise the ShapeDiver Viewer and during mount apply a set of parameters.
A couple of issues: when applying them, this could result in a white screen.

code:
Object.keys(applyParameters).forEach(async key => {
await api.current.parameters
.updateAsync({name: key, value: applyParameters[key]})

…and then:
await api.current.plugins.refreshPluginAsync(“CommPlugin_1”)
// finally show the scene
await api.current.updateSettingAsync(“scene.show”, true)

I do get it to work, by applying the parameters afterwards, with a timeout.

code:
setTimeout(() => {
Object.keys(applyParameters).forEach(async key => {
await api.current.parameters
.updateAsync({name: key, value: applyParameters[key]})
.then((data) => console.log(data))
})}, 500)

But then, you first get the model rendered without the parameters applied, and that’s a shame.

Any suggestions?

Next point: I don’t seem to be able to apply multiple parameter values at once, as an array (it is stated in the documentation though: Requesting parameter updates – ShapeDiver - Documentation and Support).
code:
api.parameters.updateAsync([{name: “Length”, value: 100}, {name: “Width”, value: 50}]);

It is difficult to know what exactly the problem is without the full code. Maybe you could create a working codepen or similar? A few comments:

  • You should indeed switch to updating all parameters with a single call. I don’t know why your last line doesn’t work but it should. This is correct code:
    api.parameters.updateAsync([{name: “Length”, value: 100}, {name: “Width”, value: 50}]);
  • How are you loading the viewer? Which settings are used for initializing?

Here is a codepens that:

  1. Load a model but defers geometry loading
  2. Updates viewer settings and several parameters of the model in a single call
  3. Shows the scene when this is completed

Thanks very much! I’ve got it to work. The problem lied in not firing ‘api.updateSettingAsync(‘scene.show’, true);’ at the right time.

Updating multiple parameters also behaves as expected. I was probably sending an object with parameter names as keys 🤦.