In this blog post, I will show you how to download an IFC file that you have generated using Python and IfcOpenShell WebAssembly in Pyodide. This is a question that a user on GitHub recently asked, and someone suggested a helpful answer on Stack Overflow that I will share with you. You can follow along using the code example here on Github.
IfcOpenShell WebAssembly is a library that allows you to create and manipulate IFC files in the browser using Python. Pyodide is a web-based Python environment that lets you run Python code and interact with the DOM. Together, they enable you to create IFC models without installing any software on your computer.
To download an IFC file that you have created with IfcOpenShell WebAssembly, you need to use a JavaScript function that creates a link element with the data as text and simulates a click on it. This function is called download, and it takes two arguments: the file name and the text content. Here is the code for the function, which I copied from the Stack Overflow article:
|
|
To use this function, you need to call it from within the scope of the onclick event handler of the button that generates the IFC wall. This button runs a Python script in the background that creates a basic wall model using IfcOpenShell WebAssembly. The model is then converted to a string using the model.to_string() method. This string is what we need to pass to the download function as the text argument. Here is how we can do that:
|
|
That’s it! Now, when you click on the button, you will see a download prompt for the test.ifc file that contains your wall model. You can open this file in any IFC viewer or editor to inspect it. I hope this blog post was useful for you. If you have any questions or feedback, please let us know on Twitter or Youtube.