IfcOpenShell / IfcOpenShell

Open source IFC library and geometry engine
GNU Lesser General Public License v3.0
1.8k stars 715 forks source link

BlenderBIM AttributeError (without any using API related with ifc/bim) #1632

Closed koji-dan closed 3 years ago

koji-dan commented 3 years ago

Hi, i always appreciate for you great works !

What i want to try is just to import/export ifc file by python console of blender, and i installed BlenderBIM addon into blender. After installing BlenderBIM, i always meet AttributeError on python script as the followings. this message is always showing on starting python script, when not only before import/export call but also not using ifc import/export. this might be based on the version combination issue ??

Blender 2.93.0 (hash 84da05a8b806 built 2021-06-02 11:34:30) Read prefs: C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\config\userpref.blend Exception in module register(): C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\__init__.py Traceback (most recent call last): File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\modules\addon_utils.py", line 386, in enable mod.register() File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\__init__.py", line 131, in register module.register() File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\module\model\__init__.py", line 34, in register bpy.utils.register_tool(workspace.BimTool, after={"builtin.scale_cage"}, separator=True, group=True) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\modules\bpy\utils\__init__.py", line 888, in register_tool tool_converted = tool_from_class(tool_cls) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\modules\bpy\utils\__init__.py", line 885, in tool_from_class cls._km_action_simple(kc_default, kc, context_descr, tool_def.label, keymap_data) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\startup\bl_ui\space_toolsystem_common.py", line 471, in _km_action_simple km = kc.keymaps.get(km_idname) AttributeError: 'NoneType' object has no attribute 'keymaps' Traceback (most recent call last): File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\handler.py", line 223, in setDefaultProperties if len(bpy.context.scene.DocProperties.drawing_styles) == 0: AttributeError: 'Scene' object has no attribute 'DocProperties' windows X64 ver 2.93.2 and also ver 2.93.0 v0.0.210731
Moult commented 3 years ago

Ah you may have an old user preferences from an older version of the BlenderBIM Add-on.

The BlenderBIM Add-on executes a few things on start up to make drawing generating easier. This has changed a few times because the drawing system has changed a few times too. Since we're still in alpha, I haven't bothered to write code to migrate old settings, so as a result people with old user startup files kinda need to refresh them.

In short, try clearing your startup settings and it should be fixed.

koji-dan commented 3 years ago

Thank you so much for your response ! i tried to clear starup setting as the below, but result is not good for me.

  1. clean-install of blender 2.93.2
  2. go to Window10 AppData folder (C:\Users{user folder}\AppData\Roaming\Blender Foundation\Blender\2.93\config)
  3. I have never created my own user setting file, then there is only userpref.blend in this folder as blend file.
  4. when removing it, i do not find Attribute Error on starting python script , but also BlenderBIM addon is disappeared
  5. therefore, i can not use ifc import/export by BlenderBIM as my purpose.
Moult commented 3 years ago

Is the BlenderBIM Add-on enabled in your add-ons settings in Edit->Preferences?

koji-dan commented 3 years ago

in Edit->Preference window, when BlenderBIM is not enable(disappeared or gray-down display), i don't see AttributeError on python script, but i cannot use ifc import/export of BlenderBIM. when BlenderBIM is enable, i see AttributeError on python script, and i see also similar AttributeError below on use ifc import/export ...


Error: Python: Traceback (most recent call last): File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\operator.py", line 118, in execute settings = import_ifc.IfcImportSettings.factory(context, self.filepath, logger) File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\import_ifc.py", line 1465, in factory scene_diff = context.scene.DiffProperties AttributeError: 'Scene' object has no attribute 'DiffProperties'

location: C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\modules\bpy\ops.py:132

Python: Traceback (most recent call last): File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\operator.py", line 118, in execute settings = import_ifc.IfcImportSettings.factory(context, self.filepath, logger) File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\import_ifc.py", line 1465, in factory scene_diff = context.scene.DiffProperties AttributeError: 'Scene' object has no attribute 'DiffProperties'

location: C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\modules\bpy\ops.py:132 Error: Python: Traceback (most recent call last): File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\operator.py", line 118, in execute settings = import_ifc.IfcImportSettings.factory(context, self.filepath, logger) File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\import_ifc.py", line 1465, in factory scene_diff = context.scene.DiffProperties AttributeError: 'Scene' object has no attribute 'DiffProperties'

location: C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\modules\bpy\ops.py:132

Traceback (most recent call last): File "", line 1, in File "C:\Users\r00414643\Desktop\3DD.Work\Script\OpeConvBlender.py", line 119, in if (not DoImport( stSrc, stExt, stInFormat )): break File "C:\Users\r00414643\Desktop\3DD.Work\Script\OpeConvBlender.py", line 51, in DoImport bpy.ops.import_ifc.bim(filepath=stSrc) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\modules\bpy\ops.py", line 132, in call ret = _op_call(self.idname_py(), None, kw) RuntimeError: Error: Python: Traceback (most recent call last): File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\operator.py", line 118, in execute settings = import_ifc.IfcImportSettings.factory(context, self.filepath, logger) File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\import_ifc.py", line 1465, in factory scene_diff = context.scene.DiffProperties AttributeError: 'Scene' object has no attribute 'DiffProperties'

location: C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\modules\bpy\ops.py:132

Error: File format is not supported in file 'C:\Users\r00414643\Desktop\3DD.Work\data\ifc\sample_ifc.ifc'

Blender quit

Moult commented 3 years ago

I think the first thing to do is to ensure that you do not have any errors with the pure BlenderBIM Add-on and you can import/export from the graphical interface, i.e. File->Import->IFC. Then, we can focus on the errors with your script OpeConvBlender.py.

Can you first confirm that the BlenderBIM Add-on works by itself? If so, then we can debug your script, but you may need to post your script for me to see what is happening.

koji-dan commented 3 years ago

yes, i agree. from blender GUI, i tried to import/export successfully, but python script are not succeeded as the above error. my confirmation result are summarized again below. as you mentioned, i had better find solution against AttributeError when BlenderBIM is enable, before trying import/export IFC.


operation: import "sample_stl.stl" (File -> Import -> STL) and export "sample_stl2.stl"(File -> export -> STL).

[1.BlenderBIM addon is disable (Edit -> Preferences)] (1-1). operation on blender GUI => success (1-2). operation by python script => success [2.BlenderBIM addon is enable (Edit -> Preferences)] (2-1). operation on blender GUI => success (2-2). operation by python script => AttributeError (log is put in the bottom of this comment again)

the error of (2-2) is occured in the begining of script starting.


%> blender.exe --background --python OpeConvBlender.py

(OpeConvBlender.py) import bpy import os import sys import time

bpy.ops.import_ifc.bim(filepath="sample_bim.ifc")

bpy.ops.export_mesh.stl( filepath="sample_bim2.stl", filter_glob="*.stl" )

bpy.ops.import_mesh.stl( filepath="sample_stl.stl", filter_glob=".stl" ) bpy.ops.export_mesh.stl( filepath="sample_stl2.stl", filter_glob=".stl" )

(2-2) error log Blender 2.93.2 (hash 1eb06de2607a built 2021-08-03 23:48:49) Read prefs: C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\config\userpref.blend Exception in module register(): C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim__init.py Traceback (most recent call last): File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\modules\addon_utils.py", line 386, in enable mod.register() File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim__init.py", line 131, in register module.register() File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\module\model\init.py", line 34, in register bpy.utils.register_tool(workspace.BimTool, after={"builtin.scale_cage"}, separator=True, group=True) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\modules\bpy\utils\init__.py", line 888, in register_tool tool_converted = tool_from_class(tool_cls) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\modules\bpy\utils\init__.py", line 885, in tool_from_class cls._km_action_simple(kc_default, kc, context_descr, tool_def.label, keymap_data) File "C:\Program Files\Blender Foundation\Blender 2.93\2.93\scripts\startup\bl_ui\space_toolsystem_common.py", line 471, in _km_action_simple km = kc.keymaps.get(km_idname) AttributeError: 'NoneType' object has no attribute 'keymaps' Traceback (most recent call last): File "C:\Users\r00414643\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\blenderbim\bim\handler.py", line 223, in setDefaultProperties if len(bpy.context.scene.DocProperties.drawing_styles) == 0: AttributeError: 'Scene' object has no attribute 'DocProperties'

Moult commented 3 years ago

@koji-dan thanks, this is a pretty fascinating error and I'm not quite sure how to fix it.

It seems that when Blender is in background mode, the keymaps cannot be updated. As a short term fix, you can delete the lines of code you see here: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.6.0/src/blenderbim/blenderbim/bim/module/model/workspace.py#L17-L32 that I have highlighted (L17-L32).

It seems as though the existence of a bl_keymap will cause the add-on to fail to load in background mode.

Pinging @s-leger and @Gorgious56 in case they know how to fix this.

To replicate do:

$ cat foo.py
import bpy
bpy.ops.import_ifc.bim(filepath="/home/dion/wall.ifc")
$ blender --background --python foo.py

We'll keep this open until we find a proper fix, but I hope the workaround helps you solve your immediate problem.

s-leger commented 3 years ago

Easy fix, do not register the tool.

if bpy.app.background:
    return
koji-dan commented 3 years ago

thank you so much ! i could confirm no error without --backgournd in command line according to your comment.