diff --git a/tools/sandbox/rhino3dm_error/input/one_sphere.3dm b/tools/sandbox/rhino3dm_error/input/one_sphere.3dm new file mode 100644 index 0000000..34df303 Binary files /dev/null and b/tools/sandbox/rhino3dm_error/input/one_sphere.3dm differ diff --git a/tools/sandbox/rhino3dm_error/rhino3dm_error.js b/tools/sandbox/rhino3dm_error/rhino3dm_error.js index 2caacfe..32cc01a 100644 --- a/tools/sandbox/rhino3dm_error/rhino3dm_error.js +++ b/tools/sandbox/rhino3dm_error/rhino3dm_error.js @@ -2,11 +2,17 @@ let rhino3dm = require ('../../../libs/rhino3dm.min.js') let fs = require ('fs'); let path = require ('path'); -function GetThreeMeshesFrom3dm (rhino, rhinoFileName) +function Open3dmFile (rhino, rhinoFileName) { let inputBuffer = fs.readFileSync (rhinoFileName, null).buffer; let inputArray = new Uint8Array (inputBuffer); let inputDoc = rhino.File3dm.fromByteArray (inputArray); + return inputDoc; +} + +function GetThreeMeshesFrom3dm (rhino, rhinoFileName) +{ + let inputDoc = Open3dmFile (rhino, rhinoFileName); let objects = inputDoc.objects (); let threeMeshes = []; for (let i = 0; i < objects.count; i++) { @@ -33,9 +39,18 @@ function WriteThreeMeshesTo3dm (rhino, threeMeshes, rhinoFileName) function ReadWriteRhinoFile (rhinoIn, rhinoOut, inputRhinoFile, outputRhinoFile) { - let threeMeshes = GetThreeMeshesFrom3dm (rhinoIn, inputRhinoFile); - console.log ('Meshes in ' + inputRhinoFile + ': ' + threeMeshes.length); + let threeMeshes = []; + if (inputRhinoFile !== null) { + threeMeshes = GetThreeMeshesFrom3dm (rhinoIn, inputRhinoFile); + } + console.log ('Meshes in ' + outputRhinoFile + ': ' + threeMeshes.length); WriteThreeMeshesTo3dm (rhinoOut, threeMeshes, outputRhinoFile); + let reopened = Open3dmFile (rhinoIn, outputRhinoFile); + if (reopened !== null) { + console.log ('SUCCESS'); + } else { + console.log ('ERROR'); + } } if (!fs.existsSync ('output')){ @@ -47,5 +62,7 @@ rhino3dm ().then (async function (rhinoIn) { ReadWriteRhinoFile (rhinoIn, rhinoOut, 'input/one_cube.3dm', 'output/one_cube.3dm'); ReadWriteRhinoFile (rhinoIn, rhinoOut, 'input/two_cubes.3dm', 'output/two_cubes.3dm'); ReadWriteRhinoFile (rhinoIn, rhinoOut, 'input/three_cubes.3dm', 'output/three_cubes.3dm'); + ReadWriteRhinoFile (rhinoIn, rhinoOut, 'input/one_sphere.3dm', 'output/one_sphere.3dm'); + ReadWriteRhinoFile (rhinoIn, rhinoOut, null, 'output/empty.3dm'); }); });