I get an unnerving error im my python script when running blender 2.91 (same for 2.92) from the command-line under windows 10 and executing a python script on the blend-file with the --python-text command-line argument. the script works fine when running it manually inside blender.

start command

blender "D:\_RENDER\BLENDS\my_file.blend" --python-text the_script -- TESTARGTEXT

error thrown:

(full stack trace further down)

AttributeError: 'NoneType' object has no attribute 'type'

the stacktrace shows that the error is thrown when the script calls the updateSeparation() method from the AnimationNodes addon and that at this point there is no area type.

as mentioned already, when I run the same script manually from the blender gui (play button in TextEditor-view) it runs just fine - even if it is the same blender-instance that was started from cmd. NOTE: blender is NOT running in the background - GUI is loaded. It looks to me as if blender is executing the script on startup before the file is finished loading - and therefore passes a NoneType at some stage where there should be a valid object. In a happy-go-lucky attempt I tried a 10-second delay at the beginning of the script with time.sleep(10) (importing python time module) but, of course, it did not help. however, it hardened my suspicion that the script is running too early in the start-up sequence of blender because with the 10 second delay the contents of the 3D-Editor view only showed after these 10 seconds.

How to solve this? Maybe there is a better way, but at this point I believe the solution must be somehow forcing blender to wait with executing the script until everything else has finished loading, hence area.type is not None. executing the script from the command-line should have the same result as running it from within the GUI. especially as I'm not even trying to run blender in background here (as I read this can cause additional issues with certain addons).

I am really desparate at this point because I have no clue how to solve, or even properly trouble-shoot this. I find my way around the blender API quite o.k. but when it comes to debugging this "from the inside" (inner workings of the addon, blender source) I'm blank.

full stacktrace:

Traceback (most recent call last):
  File "D:\_RENDER\BLENDS\my-file.blend\the_script", line 180, in <module>
  File "D:\_RENDER\SCRIPTS\GENERAL_HELPERS.py", line 48, in separate_text_to_letters
  File "C:\Users\MSI\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\animation_nodes\nodes\text\separate_text_object.py", line 92, in updateSeparation
    objects = splitTextObject(source)
  File "C:\Users\MSI\AppData\Roaming\Blender Foundation\Blender\2.92\scripts\addons\animation_nodes\utils\blender_ui.py", line 85, in wrapper
    oldType = area.type
AttributeError: 'NoneType' object has no attribute 'type'


The cause really must be that the blender instance started from command-line (with GUI, not in background-mode) tries to run the script before bpy.context.area is providing any value for the plugin. This is the method from AnimationNodes addon that's throwing: addons\animation_nodes\utils\blender_ui.py

def executeInAreaType(areaType):
    def changeAreaTypeDecorator(function):
        def wrapper(*args, **kwargs):
            **area = bpy.context.area** # <- addon asks blender for current area
            oldType = area.type
            area.type = areaType
            output = function(*args, **kwargs)
            **area.type = oldType** # <- line error occurs because area is None
            return output
        return wrapper
    return changeAreaTypeDecorator

The addon wants to read the current area.type but gets none because blender hasn't loaded it yet. (A second later, when I run the script again manually from the GUI, everything is fine). I tried making blender wait (with time.sleep() and threading.Timer) but that does not work - so my next attempt will be to setup the area.type / area myself - but this really exceeds my blender python skills.

bpy.context.area (readonly) <- this is None when blender tries to access it during startup. How, if at all, can I set it myself?


I changed line 85 of scripts\addons\animation_nodes\utils\blender_ui.py

from area = bpy.context.area to

areas  = [area for area in bpy.context.screen.areas if area.type == 'TEXT_EDITOR']
area = areas[0]

this works because bpy.context.screen.areas is populated with areas even right at startup, while bpy.context.area is not.

A dirty trick. I would still like to know how to set bpy.context.area. Or any other way to truly solve this issue.

Any help is highly appreciated.

  • $\begingroup$ No UI, no Window.Area? blender.stackexchange.com/questions/144233/… $\endgroup$
    – brockmann
    Jul 9, 2021 at 6:51
  • $\begingroup$ @brockmann there IS UI. as I stated twice I run from command-line BUT without the -B argument - so blender is started with GUI. After running the start command blender opens up just like if I run it with double-clicking the blender.exe file. I can use this blender instance normally, interacting with it in the GUI. and the script can be executed successfully in that same blender instance (=started from CMD) if I run it manually when blender is finished loading. I will of course have a look into the linked topic. $\endgroup$ Jul 9, 2021 at 8:35
  • $\begingroup$ I feel like Neo the great hacker because I made it work by changing one line in the addon. This is a dirty workaround. So any help on how to solve this properly is still very, very welcome. Adding the workaround to the question. $\endgroup$ Jul 9, 2021 at 12:02
  • $\begingroup$ Interesting! I'm thankful you shared your answers, but for whatever reason, I'm finding that my bpy.context.screens is also None. Any thoughts? $\endgroup$ Jun 23, 2022 at 0:19


You must log in to answer this question.

Browse other questions tagged .