Skip to content

Instantly share code, notes, and snippets.

@feromes
Last active June 27, 2024 01:27
Show Gist options
  • Save feromes/b9e7935b9313e7eb7e197d267168ebdb to your computer and use it in GitHub Desktop.
Save feromes/b9e7935b9313e7eb7e197d267168ebdb to your computer and use it in GitHub Desktop.
This follow files intend to help you getting work the IFC Viewer on Windows 10. You really should consider using Linux, but when you are not convinced. Follow the steps

Instructions to getting IFC Viewer working on Jupyter NoteBook

  1. You have to install previously Anaconda and I supposed you're under Windows OS, otherwise you had already IFC Viewer working :)
  2. It's boring but will rid you from some trouble. You should create a new Environment on Anaconda
  • Open Anaconda
  • Go to Environments
  • Click on +Create
  • Choose an appropriate name, like ifc_viewer
  1. Still on Anaconda, we're gonna go deeper. Click on arrow right to the name of the environment you just created, and you should access a menu, and then choose Open Terminal
  2. You must be thrilled to see this beautiful black terminal. I always think I'm Neo in Matrix this time :) But you're here just to install 3 Python Libs that we need to make things working. And you're gonna type the following lines on terminal, hit enter and wait for the magic happens.

conda install -c conda-forge ifcopenshell

conda install -c dlr-sc pythonocc-core

conda install -c conda-forge pythreejs

  1. You should have an IFC file to see Jupyter NoteBook working, I recommend you download IFCOpenHouse
  2. Now, you have to be able to view IFC files on Jupyter Notebook, as the following file attached here in this Gist.
  3. In order to work properly you have to let the both file in the same directory.
  4. By default, when you start Jupyter Notebook on Anaconda, it uses your Home Folder. You should put all files in a folder there, including your IFC File or IFC OpenHouse.
  5. Just start Jupyter Notebook, go to the folder you save the files and open ifc_visualizer.ipynb Pay attention to the Jupyter Notebook cell 2 command file path. It has to point to the correct location and find a valid IFC file.

I hope this lines help you to get involved with programing.

from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer as Renderer
class ifc_viewer(Renderer):
def __init__(self):
Renderer.__init__(self)
self.n = 0
self.products = []
@staticmethod
def subshapes(shp):
import OCC.Core.TopoDS
it = OCC.Core.TopoDS.TopoDS_Iterator(shp)
while it.More():
yield it.Value()
it.Next()
def DisplayShape(self, product, shp, color):
for shp, sty in zip(self.subshapes(shp), color):
Renderer.DisplayShape(self, shp, shape_color=sty[0:3], render_edges=True)
self.products.append(product)
def onclick(self, item):
self.html.value = "Selected %r" % self.products[int(item.name)]
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import ifcopenshell\n",
"import ifcopenshell.geom"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# You must have an IFC valid file to Open\n",
"# I recommend you get a good one on IfcOpenHouse repository\n",
"# https://github.com/aothms/IfcOpenHouse\n",
"file = ifcopenshell.open(f\"./IfcOpenHouse/IfcOpenHouse_IFC4.ifc\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"settings = ifcopenshell.geom.settings()\n",
"settings.set(settings.USE_PYTHON_OPENCASCADE, True)\n",
"geometry = dict((file[item.data.id], (item.geometry, item.styles)) \n",
" for item in ifcopenshell.geom.iterator(settings, file))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2445c0f5636f47b98ab9f65a1e8cfa58",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(VBox(children=(HBox(children=(Checkbox(value=True, description='Axes', layout=Layout(height='au…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from ifc_viewer import ifc_viewer\n",
" \n",
"viewer = ifc_viewer()\n",
"\n",
"for product, (shape, styles) in geometry.items():\n",
" # if not product.is_a(\"IfcWall\"): continue\n",
" viewer.DisplayShape(product, shape, styles)\n",
" \n",
"viewer.Display()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment