I have set up the Shapediver API in an external website so that I can track the values of the grasshopper parameters as the user changes them. To do this, I have attached “ShapeDiverDataOutput” to each parameter in grasshopper, given each a unique name, and then have the values fill into an array each time the window is clicked. Here is the simplified version:
In theory, the info.data[0].data should always reference the same parameter, correct? But it does not. I have 10 parameters that read correctly at first, but once a parameter is moved, the reference identity for that parameter changes. For example, at first, the info.data[0].data does reference the Truss Depth parameter, but if that parameter value is changed, suddenly the trussDepth array starts showing values from the Length parameter. What is happening?
Alternatively, since each of my ShapeDiverDataOutputs have a unique name, how do I just refer to that label instead of data[i] numbers? I have tried the following and it has not worked.
You are right that the indices returned in the data array can change, since you are using separate data outputs. I would recommend instead to use a single data input with a json object that contains all the information you need. You can use the JSON components of the ShapeDiver plugin and build an object like this for example:
{
TrussDepth: 10,
Length: 20
}
Then you can comfortably access all the data from this object.
Alternatively, if you want to keep your Grasshopper definition as it is, you could just find the right element in your data array by looping through it and checking its name. That is less optimal but will work. See your code adapted below:
var info = api.scene.getData();
for (let i=0; i<info.data.length; i++) {
if (info.data[i].name == "TrussDepth") trussDepth.push(info.data[i].data);
if (info.data[i].name == "Length") length.push(info.data[i].data);
}
Thank you for your help on this, Mathieu. I am not as familiar with JSON and would like to keep the definition as it is. I have applied your suggested adapted code (thank you!), but now the shapdiver API won’t load. To be clear, the values you are referencing in quotes “TrussDepth” and “Length” are the names I have given the ShapeDiverDataOutput components, correct? I believe I understand the logic of what is happening, but not sure why it would cause the API to stop loading?
I cannot really help without seeing the final code you wrote or getting a link to the page where you embedded the model so I can debug. What do you mean by “the API is not loading”?