Import/export inputs values to JSON

Hi,

We would like to export/import inputs values via JSON Files.
We have shapeDiver files with more than 50 inputs, so, We need to work with Json to save and load configurations.

  1. I found how to export inputs from the API (I’ll use something similar to read JSON and edit inputs) :
function SDVcreateConfigurationData(){
  return new Promise((resolve, reject) => {
    var result = {};
    try{
      parameters = Object.values(SDV.sessions.mySessionImage.parameters);
      parameters.forEach(function(element, index) {
        result[element.id] = {'name':element.name, 'value':element.value, 'choices': element.choices};
      });
      //console.log(result);
      resolve(JSON.stringify(result));
    }catch (e) {
      console.error("Shapediver : cannot save configuration file", e);
      resolve(result);
    }
  });
}
  1. In ShapeDiver, there is the 3 dots menu to Import/export parameters values

image

  1. From GrassHopper, we found the menu to load inputs from JSON

So, the question is :
How to export inputs values to Json, from GrassHopper file?

(Sometimes our project are too heavy for ShapeDiver, so they need to be calculated localy, in GrassHopper. Then we need to export inputs definitions)

Thanks !
Olivia

Hi @olivia3

You can use Jswan

Well, thanks for your suggestion

But I’m looking for a solution to export all inputs in a single Json file, without having to setup inputs one by one.
I want a global export
To be sure not to forget 1 input

As you have noticed, the ShapeDiver platform includes a way to export a set of parameter values in a JSON file. The JSON file format we are using contains three properties for each input:

  • The name of the input: it corresponds in general to the name in Grasshopper
  • The value of the input
  • The ID of the input: this is a specific ID which is computed when you upload your definition to ShapeDiver

This JSON file can then be used to import parameter values in a ShapeDiver model: in that case, the input IDs are used to load the values of the JSON files to inputs of the online model.

This same JSON file can also be used to import parameter values in a Grasshopper definition, using the top-level menu option you are mentioning in your post (Parameters (Beta) > Load From JSON). However, note that in Grasshopper, input IDs do not exist, therefore the parameter name is used. If several parameters have the same name, this can result in conflicts. The load routine will trigger warnings in this case (there will be warnings in general if some parameters do not match between the JSON file and the definition).

I wanted to clarify these existing features before answering your questions about how to export input values to JSON from Grasshopper. As you can see, exporting the same JSON file format from Grasshopper that we use for the above-mentioned features will not be possible, because input IDs do not exist in the definition. Therefore, you will not be able to export JSON files that can then be used to load parameters in ShapeDiver at the moment.

In your case, it depends on why you want to export JSON input values from Grasshopper. Is it because you want to load them in a ShapeDiver model afterward? In the future, we could support loading from JSON files without IDs and trying to map parameter names; we will review this possible feature and let you know.

If your goal is a different one, I guess there are multiple possible answers to your question. You could write scripts in Grasshopper to import/export parameter values based on your own JSON file format. And you could also use the ShapeDiver API in your web application to import/export the same format on your own.

I hope these considerations provide some help. Please give me more details regarding your goals if you feel like I did not properly answer your question.

Thanks for this detailed answer

Yes, the perfect solution would be to be able to import/export inputs from grassHopper and ShapeDiver in every “direction”

But I undestrand why it’s not possible fot the moment.

So I think we’ll find another solution !
Thanks