materialisecloud
Advanced tools
Materialise Cloud API SDK for node.js
Weekly downloads
Readme
The SDK to run operations on Materialise Cloud API.
All operations in materialisecloud module have the same contracts (input and result) as per documentation.
For example, the operation Reduce Triangles has the following parameters:
accuracyMm (number)
maxAngle (number)
numberOfIterations (number)
inputId (string)
which is manifested in the function's signature:
function reduceTrianglesOperationApi(inputId, accuracyMm, maxAngle, numberOfIterations, callback)
The operation's results are in JSON format and have the following structure:
{
"operationId": "98f499ac-099c-4637-a2d5-f54fed455773",
"resultId": "ca74d93d-43b7-452b-bf44-1554081d6bac"
}
which is exactly the structure of the object returned in the result parameter of the operation's callback function. The callback is a standard node.js style callback function with first arugment 'error' if an error has occured, the second: the resulting object.
cloud.reduceTrianglesOperationApi('<<INPUTID>>', 1, 45, 5, function(error, result) {
console.log("OperationId: " + result.operationId);
console.log("ResultId: " + result.resultId);
}
Import the module. It has an entry point function create which requires your credentials and (optionally) the base url (without http and slashes) and port (if not supplied, defaults to production values). After calling create simply call the operation API functions:
var cloudFactory = require("materialisecloud");
var cloud = cloudFactory.create("<<YOUR EMAIL HERE>>", "<<PASSWORD>>", "<<CLIENTID>", "<<CLIENTSECRET>>", "api-cloudtoolkit-sandbox.materialise.net", "443");
cloud.uploadFileFromLocalStorageApi('\\path\\to\\file.stl', function(error,result){
if(error){
console.log('Error: ' + error);
}
else {
console.log('Result file id: ' + result.fileId);
cloud.importOperationApi(result.fileId, 'mm', function(error,result){
if(error){
console.log('Error: ' + error);
}
else {
console.log('Result id: ' + result.resultId);
}
});
}
});
You can also use a control flow library like async.js to get rid of nested callbacks. See examples for more information.
$ npm install materialisecloud
cloud.uploadFileFromLocalStorageApi('//path//to//saved//file.stl', function(error, result) {
console.log(result.fileId); //id of uploaded file
});
cloud.uploadFileFromLocalStorageApi(bufferWithFileContents, "test.stl", function(error, result) {
console.log(result.fileId); //id of uploaded file
});
in case of success path to downloaded file will be returned in callback's second argument
cloud.downloadFileToLocalStorageApi('<<FILEID>>', "//path//to//saved//file.stl", function(error, result) {
console.log(result); //logs "//path//to//saved//file.stl"
});
in case of success downloaded file buffer will be returned in callback's second argument
cloud.downloadFileToBufferApi('<<FILEID>>', function(error, result) {
fs.writeFile("\\path\\to\\file.stl", result, function(err) {
console.log('file saved');
});
});
cloud.analyzeOperationApi('<<INPUTID>>', function(error,result){
console.log(result); //outputs model analysis data in JSON format
});
cloud.convertToStlOperationApi('<<INPUTID>>', 'mm', function(error,result){
console.log(result.resultId); //outputs id of result
});
cloud.exportOperationApi('<<INPUTID>>', 'stl', function(error,result){
console.log(result.fileId); //id of resulting stl file
});
FAQs
Materialise Cloud API SDK for node.js
The npm package materialisecloud receives a total of 0 weekly downloads. As such, materialisecloud popularity was classified as not popular.
We found that materialisecloud demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.