Overview
ShapeDiver models have the ability to export data and files corresponding to the user-defined parameter values. This capability has to be set in the Grasshopper parametric model by its creator.
Export data in Grasshopper
The model designer will have to use export components from the ShapeDiver plugin and set them up for API access.
In our example, the model includes an export component named ExportAsset_1
. You will be able to directly retrieve the data using the requestAsync
function of the exports
interface:
api.exports.requestAsync({name: "ExampleDirectExport"}).catch(function(err) { return Promise.reject(err); }).then(function(response) { console.log("EXPORT DONE!", response); });
Alternatively, you can dynamically retrieve the list of all export assets and trigger the ones you choose. Call api.exports.get()
to get the complete list.
API getters
Calling get without arguments retrieves all assets in the specified interface. See also here how to pass filters to the get functions.
In the above case, if the export was successful, the response data will contain a time-limited download url for the corresponding file. There are several types of export assets which are described below.
Types of export
There are two types of file exports that can be defined in models uploaded to ShapeDiver: direct export and email export. Using api.exports.get()
, look for the type property: direct export have the download
type, while email exports have the email
type.
Both types of export can be requested with identical calls to requestAsync()
, but they contain a different response.
Direct export
When the model contains a direct export, the response object contains a content array which gives the file format, size and download link of the exported file:
api.exports.requestAsync({name: "ExportAsset_1"}).catch(function(err) { return Promise.reject(err); }).then(function(response) { console.log("EXPORT DONE!"); console.log("File format: " response.data.content[0].format); console.log("File size: " response.data.content[0].size); console.log("Download link: " response.data.content[0].href); });
Email export
The email export never exposes the file to the browser and instead sends it directly to the email address defined in the model. The request response only confirms whether the email was successfully sent:
api.exports.requestAsync({name: "ExportAsset_1"}).catch(function(err) { return Promise.reject(err); }).then(function(response) { console.log("EXPORT DONE!"); console.log("Result message: " response.data.result.msg); });
If the export was successful, the viewer will receive the message "Email has been successfully sent."
Silent mode
When embedding in iframe mode or by including the dependencies to load the ShapeDiver control panel, the default behaviour when requesting exports is to trigger the display of a modal dialog. In order to prevent this dialog and instead request the export in the background, set the silent
property to true
in the request object:
api.exports.requestAsync({name: "ExportAsset_1", silent: true});
Example model
Find below a simple example model with both types of exports and how to list and export them using the API:
The export download links are bound to the session and they expire at the end of the session due to security reasons.
Comments
0 comments
Article is closed for comments.