BlenderBIM Add-on/Using the Python console with BlenderBIM Add-on

From Wiki.OSArch
Noun program 2979275 64x64.png This page is part of a series about Starting to code. All articles in the series can be found in the Category:Start_coding

The BlenderBIM Add-on comes with my useful Python libraries to interrogate BIM data, in addition to the math and geometry libraries that Blender comes with. A short list of these additional libraries is provided:

  • ifcopenshell - used for querying, writing, and manipulating IFC data and files
  • bcfplugin - used for querying, writing, and manipulating BCF data and files
  • fcl - used for writing custom logic for clash detection
  • OCC - used or directly accessing the OpenCascade geometry kernel for low-level geometric analysis
  • svgwrite - used for writing SVG for construction documentation
  • ifcdiff - used for comparing IFC files for changes
  • ifccsv - used for exporting and importing BIM data with CSV
  • ifcclash - a frontend of FCL, allowing you to trigger clash sets for collision detection
How to switch to Blender Python console mode
Running IfcOpenShell commands in the Blender console

You can launch an interactive Python shell letting you query BIM data in real-time. To do so:

  1. Install the BlenderBIM Add-on and ensure it is enabled
  2. Switch to the Blender Python console mode.
  3. There is no step 3.

You can now type in import ifcopenshell and it'll work! Have fun!

How to switch to Blender's built in text editor

Alternatively, you can write a full script from a text file and run it. Instead of switching to the Python console mode, just switch to the Blender text editor mode, and press the Run Script button in the top right once you've written or loaded a script. You can also press Alt P as a short cut, but your mouse cursor must be over your code when you press the hotkey.

The Blender text editor has basic line numbers, syntax highlighting, and line wrapping abilities. On Mac and Linux, the output will be to the console. On Windows, the console may not be visible. To make it visible, go click on Window > Toggle System Console.

If you'd like to access the currently loaded or imported IFC file, there is no need to re-open the file with IfcOpenShell. Instead, you can access it as so:

import blenderbim.bim.ifc
ifc = blenderbim.bim.ifc.IfcStore().get_file()

Please remove this "BlenderBIM_Addon_Documentation" template.