Difference between revisions of "BlenderBIM Add-on/BlenderBIM Add-on code examples"

From Wiki.OSArch
(export code sample)
 
Line 1: Line 1:
Export ifc from console :
+
To import an IFC:
 +
 
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
bpy.ops.bim.export_ifc()
+
bpy.ops.import_ifc.bim(filepath='/home/dion/testb.ifc')
 +
</syntaxhighlight>
 +
 
 +
To export an IFC:
 +
 
 +
<syntaxhighlight lang="python">
 +
bpy.ops.export_ifc.bim(filepath='/home/dion/testb.ifc')
 +
</syntaxhighlight>
 +
 
 +
You can also bypass the operator to import or export yourself. This gives you granularity to instantiate the IFC import classes, export classes, quantity calculator class, logging class, settings, and so on. This is useful if you are writing your own script and would like to customise how the import or export works. You are also able to overload the definition of these classes to provide even more control.
 +
 
 +
To import an IFC:
 +
 
 +
<syntaxhighlight lang="python">
 +
import bpy
 +
import logging
 +
import blenderbim.bim.import_ifc
 +
ifc_import_settings = blenderbim.bim.import_ifc.IfcImportSettings.factory(bpy.context, '/home/dion/testa.ifc', logging.getLogger('ImportIFC'))
 +
ifc_importer = blenderbim.bim.import_ifc.IfcImporter(ifc_import_settings)
 +
ifc_importer.execute()
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="python">
 +
import bpy
 +
import logging
 +
import blenderbim.bim.export_ifc
 +
import blenderbim.bim.qto
 +
settings = blenderbim.bim.export_ifc.IfcExportSettings.factory(bpy.context, '/home/dion/testa.ifc', logging.getLogger('ExportIFC'))
 +
qto_calculator = blenderbim.bim.qto.QtoCalculator()
 +
ifc_parser = blenderbim.bim.export_ifc.IfcParser(settings, qto_calculator)
 +
ifc_exporter = blenderbim.bim.export_ifc.IfcExporter(settings, ifc_parser)
 +
ifc_exporter.export(bpy.context.selected_objects)
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 19:01, 3 August 2020

To import an IFC:

bpy.ops.import_ifc.bim(filepath='/home/dion/testb.ifc')

To export an IFC:

bpy.ops.export_ifc.bim(filepath='/home/dion/testb.ifc')

You can also bypass the operator to import or export yourself. This gives you granularity to instantiate the IFC import classes, export classes, quantity calculator class, logging class, settings, and so on. This is useful if you are writing your own script and would like to customise how the import or export works. You are also able to overload the definition of these classes to provide even more control.

To import an IFC:

import bpy
import logging
import blenderbim.bim.import_ifc
ifc_import_settings = blenderbim.bim.import_ifc.IfcImportSettings.factory(bpy.context, '/home/dion/testa.ifc', logging.getLogger('ImportIFC'))
ifc_importer = blenderbim.bim.import_ifc.IfcImporter(ifc_import_settings)
ifc_importer.execute()
import bpy
import logging
import blenderbim.bim.export_ifc
import blenderbim.bim.qto
settings = blenderbim.bim.export_ifc.IfcExportSettings.factory(bpy.context, '/home/dion/testa.ifc', logging.getLogger('ExportIFC'))
qto_calculator = blenderbim.bim.qto.QtoCalculator()
ifc_parser = blenderbim.bim.export_ifc.IfcParser(settings, qto_calculator)
ifc_exporter = blenderbim.bim.export_ifc.IfcExporter(settings, ifc_parser)
ifc_exporter.export(bpy.context.selected_objects)