├── .gitignore ├── README.md ├── index.js ├── package.json └── test ├── duplex.ifc ├── erroneous.ifc ├── ifcConvertSpec.js └── mocha.opts /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ifc converter for Node.js 2 | 3 | A simple promised based wrapper for the IfcConvert program for node. 4 | 5 | # Requirements 6 | 7 | - IfcConvert, Installation instructions and binaries can be found at the [ifcOpenShell](http://ifcopenshell.org/ifcconvert.html) page. 8 | 9 | # Usage 10 | 11 | ```javascript 12 | var ifcConvert = require('ifc-convert'); 13 | 14 | ifcConvert('source.ifc', 'dest.dae') 15 | .then(function() { 16 | //Now you have a Collada file;) 17 | }); 18 | 19 | ifcConvert('source.ifc', 'dest.obj') 20 | .then(function() { 21 | //Now you have a Wavefront OBJ file with an .mtl file 22 | }); 23 | 24 | ifcConvert('source.ifc', 'dest.stp') 25 | .then(function() { 26 | //Now you have a STEP file 27 | }); 28 | 29 | ifcConvert('source.ifc', 'dest.igs') 30 | .then(function() { 31 | //Now you have a IGES file 32 | }); 33 | 34 | ``` 35 | 36 | # Options 37 | 38 | If you do not have IfcConvert in your path you can give it in options. 39 | 40 | ```javascript 41 | ifcConvert('source.ifc', 'dest.dae', {path: 'path/to/bin'}) 42 | .then(function() { 43 | //Done 44 | }); 45 | ``` 46 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var path = require("path"), 4 | execFile = require("child_process").execFile, 5 | fs = require('fs'); 6 | 7 | module.exports = function ifcConvert(source, dest, options) { 8 | 9 | return new Promise(function(resolve, reject) { 10 | 11 | var ifcConvertPath; 12 | 13 | if (options && options.path) { 14 | ifcConvertPath = options.path + '/IfcConvert'; 15 | } else { 16 | ifcConvertPath = 'IfcConvert'; 17 | } 18 | 19 | if (!fs.existsSync(source)) { 20 | reject('Unable to open the source file.'); 21 | return; 22 | } 23 | 24 | var args = [source, dest]; 25 | 26 | //If user supplies any args concat them to the args array 27 | if (options && options.args) { 28 | args = args.concat(options.args); 29 | } 30 | 31 | execFile(ifcConvertPath, args, { 32 | maxBuffer: options.maxBuffer || 1024 * 2000 33 | }, function(err, stdout, stderr) { 34 | 35 | if (err) { 36 | reject(err); 37 | } else if (stderr.length > 0) { 38 | reject(new Error(stderr.toString())); 39 | } else { 40 | resolve(); 41 | } 42 | }); 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ifc-convert", 3 | "version": "1.3.1", 4 | "description": "Simple wrapper for ifcConvert", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/klokoy/ifcConvert" 9 | }, 10 | "scripts": { 11 | "test": "mocha" 12 | }, 13 | "keywords": [ 14 | "ifc", 15 | "converter", 16 | "collada" 17 | ], 18 | "author": "Kim Lokøy", 19 | "license": "MIT", 20 | "devDependencies": { 21 | "chai": "^1.9.1", 22 | "mocha": "^1.18.2", 23 | "async": "^0.6.2" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/erroneous.ifc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klokoy/ifc-convert/0fc51439b8217bc7e528bb889706e6d90760a3f4/test/erroneous.ifc -------------------------------------------------------------------------------- /test/ifcConvertSpec.js: -------------------------------------------------------------------------------- 1 | var ifcConvert = require('../index.js'), 2 | assert = require('chai').assert, 3 | path = require('path'), 4 | fs = require('fs'), 5 | async = require('async'); 6 | 7 | describe('ifcConvert', function() { 8 | it('should convert to supported formats', function(done) { 9 | 10 | //stp seems to take a loong time, so I skip them 11 | 12 | var source = relative('duplex.ifc'); 13 | var formats = ['dae', 'obj', 'igs']; //'stp' 14 | 15 | var testFormat = function(format, callback) { 16 | var dest = relative('duplex.' + format); 17 | 18 | ifcConvert(source, dest) 19 | .then(function() { 20 | assert(fs.existsSync(dest)); 21 | callback(null); 22 | }) 23 | .catch(function() { 24 | //Should not be here 25 | assert(false); 26 | }) 27 | 28 | }; 29 | 30 | async.each(formats, testFormat, done); 31 | 32 | }); 33 | 34 | it('should err if source does not exits', function(done) { 35 | ifcConvert('doesnotexists.ifc', 'doesnotexits.dae') 36 | .catch(function(reason) { 37 | assert.equal(reason, 'Unable to open the source file.'); 38 | done(); 39 | }); 40 | }); 41 | 42 | it('should pass errors through', function(done) { 43 | var source = relative('erroneous.ifc'); 44 | 45 | ifcConvert(source, 'erroneous.dae') 46 | .catch(function(reason) { 47 | assert(reason); 48 | done(); 49 | }); 50 | }); 51 | 52 | it('should allow setting path to ifcConvert', function(done) { 53 | var source = relative('duplex.ifc'); 54 | var options = { 55 | path: '/usr/local/bin' 56 | }; 57 | 58 | ifcConvert(source, 'duplex.dae', options) 59 | .then(function() { 60 | done(); 61 | }); 62 | }); 63 | }); 64 | 65 | after(function() { 66 | fs.unlink(relative("duplex.dae")); 67 | fs.unlink(relative("duplex.obj")); 68 | fs.unlink(relative("duplex.mtl")); //mtl file is part of the Wavefront OBJ format 69 | fs.unlink(relative("duplex.igs")); 70 | }); 71 | 72 | function relative(relPath) { 73 | return path.resolve(__dirname, relPath); 74 | } 75 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --reporter spec 2 | --timeout 40000ms 3 | --slow 100000ms 4 | --------------------------------------------------------------------------------