Skip to content

Instantly share code, notes, and snippets.

@inderpreetsingh
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inderpreetsingh/cce7c0fa6fac36787aab to your computer and use it in GitHub Desktop.
Save inderpreetsingh/cce7c0fa6fac36787aab to your computer and use it in GitHub Desktop.
Meteor.methods({
convertFile:function(fileId)
{
var sys = Npm.require('sys'),
fs = Npm.require('fs'),
exec = Npm.require('child_process').exec;
var modelObj = ModelFiles.findOne(fileId);
var readStream = modelObj.createReadStream('modelFiles');
var filePath = readStream.path;
var objects;
var mgedPath = '/usr/brlcad/dev-7.25.0/bin/mged';
var g_objPath = '/usr/brlcad/dev-7.25.0/bin/g-obj';
var cmd = mgedPath + " -c " + filePath +" ls -a 2>&1";
var uploadDirPath = filePath.substring(0, filePath.lastIndexOf("/"));
/* First commmand filds the list of objects in a .g database */
child = exec(cmd, function (error, stdout, stderr) {
sys.print('stdout' + stdout);
objects = stdout.split(" "); //all objects get stored in an array
console.log(objects);
sys.print('stderr' + stderr);
if (error != null) {
console.log('exec error: ' + error);
} else {
for (i in objects) {
/* For each object in .g database , a g file is generated */
var objPath = uploadDirPath + "/" + objects[i] + ".obj";
cmd = g_objPath + " -n 10 -o " + objPath + " " + filePath + " " + objects[i];
child = exec(cmd, function (error, stdout, stderr) {
if (error) {
console.log("There's some error in converting file" + error);
} else {
console.log("File has been converted");
objFS = new FS.File(objPath);
}
});
}
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment