0
$\begingroup$

I have many .fbx files that I need convert to .ifc files by using the BlenderBIM addon.

I am trying to do this as part of a regular workflow which is initiated from a .bat file. (the bat file will do other things before and afterwards but that part is not included)

"C:\Program Files\Blender Foundation\Blender 2.90\blender.exe" --background "C:\Users\Joshua\Documents\_BatchProcessing\ProcessTemplate.blend" --python "C:\Users\Joshua\Documents\_BatchProcessing\FBXimportScript.py"

Which calls the python script

import bpy
import os
import glob

directory_im = 'C:/Users/Joshua/Documents/_BatchProcessing/max/fbx/test/'
files = glob.glob(directory_im + "*.fbx")
for f in files:
    head, tail = os.path.split(f)
    bpy.ops.import_scene.fbx(filepath=f)
    bpy.ops.object.select_all(action='SELECT')
    bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM')
    bpy.ops.object.select_all(action='SELECT')
    bpy.ops.export_ifc.bim(
    filepath=directory_im + tail.replace('.fbx', '') + '.ifc')

I have 2 FBX files to test which different geometry in each which can be seen by the different file size. the above python script exports 2 files with correct names however the same geometry is being exported to each file. enter image description here

If someone could point me in the right direction it would be very much appreciated!!!

$\endgroup$
8
  • $\begingroup$ Not sure I understand, but each export will have all the previous FBXs included in the scene. Did you want to clear the scene at the beginning of the loop? $\endgroup$
    – scurest
    Sep 8, 2020 at 8:23
  • $\begingroup$ what happens is that the same geometry is in all the exported .ifc files. i thought if i added bpy.ops.scene.new(type='EMPTY') after the file export in the same For loop it would clear the scene and move onto the next fbx file this didn't work. $\endgroup$
    – JBH
    Sep 8, 2020 at 9:08
  • $\begingroup$ Try bpy.ops.object.select_all(action='SELECT') ; bpy.ops.object.delete(use_global=False) to clear the scene. But it might be better to do the loop in the .bat file and pass just one file to be converted to the .py script at a time. $\endgroup$
    – scurest
    Sep 8, 2020 at 9:14
  • $\begingroup$ I’ll give that a go. however i’m curious to know how to do the loop in the bat file, how might that work? $\endgroup$
    – JBH
    Sep 8, 2020 at 10:02
  • 1
    $\begingroup$ CMD Loop was the answer! $\endgroup$
    – JBH
    Sep 8, 2020 at 23:26

1 Answer 1

1
$\begingroup$

A heads up for those reading this in 2021 that the BlenderBIM Add-on has since been completely rewritten and this script no longer applies. IFC is not a geometry format like FBX and so it isn't simply a matter of converting from one format to another. IFC instead requires a lot of semantic data, including a hierarchy of spaces, semantic classification of objects (e.g. not just a cube, but a "wall"), and more. As a result, you may be interested in looking at some of the operators available in the bpy.ops.bim.* namespace, or if you're looking for a geometry converter, I would instead recommend using more fundamental code seen in the ifcopenshell.api.* namespace.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .