Hi @Bojan_T, to take a screenshot there is a function called api.scene.getScreenshotAsync()
. This will give you as response a base 64 image which you can send as a file to a ShapeDiverImageInput
component which will give you a bitmap in GH that you can process via Squid. Step by step your code could look like this:
-
You need a function that converts base 64 images into files:
function dataURLtoFile(dataurl, filename) {
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, {type:mime});
}
-
Get the screenshot via the api function
api.scene.getScreenshotAsync()
. -
Add a function that gets executed just after the screenshot is ready:
api.scene.getScreenshotAsync().then(function(res){});
. -
Inside this function the data response will contain the base 64 image which can be converted into file with the function in the first step:
api.scene.getScreenshotAsync().then(function(res){var file = dataURLtoFile(res.data,"a.png");});
. -
Now this file can be sent as a parameter update to the
ShapeDiverImageInput
component which in this example is calledTextureFile
:
api.scene.getScreenshotAsync().then(function(res){ var file = dataURLtoFile(res.data,"example.png"); api.parameters.updateAsync({name:"TextureFile",value:file});});
.
I have already tested this function and you can find the example here: https://app.shapediver.com/m/screenshot-test
Hope this helps.