engine_web-ifc
engine_web-ifc copied to clipboard
example code in examples/nodejs is not executing properly
https://github.com/tomvandig/web-ifc/blob/8fa6d0042362ffdd60be538ab0d1c207d49aee5d/examples/nodejs/index.js#L50
Hi,
When I clone your repo and try to run the examples/nodejs example on my machine locally, the code reads the example.ifc and logs the properties, but it fails when trying to write new attributes into the example.ifc with the following error message: TypeError: lineObject.ToTape is not a function at IfcAPI2.WriteLine
Could you please look at the examples/nodejs and see how it could be fixed? Is there something I could do on my end to prevent this error?
My local machine specs are: Processor Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz 2.59 GHz Installed RAM 16.0 GB (15.8 GB usable) System type 64-bit operating system, x64-based processor
Edition Windows 10 Home Version 21H2 OS build 19044.1706
VSC Version: 1.67.2 (user setup) Node.js: 16.13.0
Thanks a lot!
Gordan
P.S. this is the first time I'm "Creating an Issue on GitHub", so please let me know if I forgot to write something that you might need in order to better understand this bug/error I'm getting.
Yeah, I get the same on Mac M1, node16.15. But I can also no longer build as of latest HEAD (b2f069cc198c22b1e6d92b36ccf6e3456f7230d6). This may be a toolchain issue on my side.
TypeError: lineObject.ToTape is not a function
/Users/pablo/ifcjs/web-ifc/dist/web-ifc-api-node.js:6139
throw ex;
^
RuntimeError: abort(TypeError: lineObject.ToTape is not a function). Build with -s ASSERTIONS=1 for more info.
Ok, I can build again! I had a broken emsdk.
So building from head and running the node example, I can repro this error.
Error comes from this line in src: https://github.com/tomvandig/web-ifc/blob/b77199c/src/web-ifc-api.ts#L275
let rawLineData: RawLineData = {
ID: lineObject.expressID,
type: lineObject.type,
arguments: lineObject.ToTape() as any[]
}
Looks like exporting from the sample file yields integers at this point in the code so each of these values is invalid. I have a draft patch that works enough to complete the extract and yields a loadable IFC:
@pablo-mayrgundter this has caused errors when exporting IFC files: https://github.com/IFCjs/web-ifc/issues/225 . We are reverting this change. Don't hesitate to bring up more ideas and suggestions! :) Cheers
Bummer! Well yeah, the patch I submitted was just to bypass an error when there was no way to write a line. Reverting will break it again for the data files we were using, but may let yours pass? I'd suggest cleaning up the error handling instead. Do you have someone working on this?
No worries, @QuimMoya already fixed it for future versions! We will address this issue separately to prevent this from breaking before publishing the new version! If you have any proposal, let us know
I reviewed the original error at top of thread here and also my fix. Also looked at the SO issue you linked.
here's my fix (which is still in HEAD): https://github.com/IFCjs/web-ifc/commit/77def23423d4b7741082c32d9a70ccabdf2edeca
All my workaround did was to output a console warning and continue with serialization instead of creating a TypeError if there were undefined properties in the lineObject, as before.
Is it possible that the example you had in the Crash Course video was actually getting that error, but still writing enough to data to make progress before? With my change the error is more visible by a quick scan of the output logs.
Can I have a look at the Crash Course?
Hey, this is the example of the crash course. I tested this with the same file and multiple versions of web-ifc, and only the last version was unable to write the IFC file.
Hmm, WIT works for me. Do you fail to serialize at all?
First I clone the repo and run as-is, with [email protected] in package.json, run the local demo server and download the modified file (which exercises WriteLine). That gives me "modified.ifc" which is 698903 bytes. (Note, I see 0.0.34 in jsconsole version log).
I then modify the package.json to use [email protected], rebuild the excercise and also copy in the correct wasm from node_modules. I get a new "modified.ifc" at 698631 bytes. Diffing the two files I see only changes to encode utf-8 chars directly instead of escaped (as with 0.0.34). Note, here I see 0.0.36 in my console log, and also the warning that "Line object cannot be serialized: IfcBuildingStorey {expressID: 138...". However, that element is present in the output file.
Both versions do output the problematic line.. here's the two outputs diff/grepped for just the STOREY element:
pablo@top:~/c/ifcjs/ifcjs-crash-course> diff modified-0.0.34.ifc modified-0.0.36.ifc | grep STOREY
< #138=IFCBUILDINGSTOREY('0w984V0GL6yR4z75YWgVfX',#41,'Nivel 1',$,'Nivel:Nivel 1',#136,$,'Nivel 1 - Editado',.ELEMENT.,0);
> #138=IFCBUILDINGSTOREY('0w984V0GL6yR4z75YWgVfX',#41,'Nivel 1',$,'Nivel:Nivel 1',#136,$,'Nivel 1',.ELEMENT.,0);
I think the console.warn is signaling a different problem, though the message is confusing.
ahh.. Are you saying the edited value doesn't show up in the output file? Yes, I see that now. Ok, will see what's going wrong...
I think the bug is a typo in my original fix attempt. I'm checking for ToArray but should be checking for ToTape. Sorry!
Here's the PR:
https://github.com/IFCjs/web-ifc/pull/226
Another discovery, the web-ifc example was broken a long time ago by a change in web-ifc API in
https://github.com/IFCjs/web-ifc/commit/bfc2601657595b8f84cd0f2df5d3907836fb6758
The api was changed from:
WriteLine(modelID: number, expressID: number, type: number, parameters: any)
to
WriteLine(modelID: number, lineObject: any)
The example that's in web-ifc has no real utility anymore.
Hey @pablo-mayrgundter we also spotted the bug and fixed it 🙂 Thanks a lot for fixing this on your end! I'm merging the PR right now. Cheers!