_RestrictData problem with addon

I have written a script to import Homeworld Remastered DAE files into Blender. My script works fine when run from the text editor, but when I convert it into a module I get the

AttributeError '_RestrictData' object has no attribute 'objects'

. However, very occasionally my import module works fine, without me changing the code…

I have seen these threads where this is discussed, but I’m not sure how to apply those fixes in my case.

I have tried removing the “import x from y” and doing full imports, and I have also added a couple of time.sleep() commands in case Blender was just not quite ready at the point when the script was runnning.

I have this in my init.py:


import time
import os

print("Sleeping 5 before importing")
time.sleep(5)

import bpy
import bpy_extras

This then calls my import_dae.py as an imported module. import_dae.py also has these imports:

import time
print("Sleeping 5 before importing")
time.sleep(5)

import os
if "bpy" not in locals():
    import bpy
import xml.etree.ElementTree as ET
import math
from mathutils import *

Then I use this, which causes the error:

D = bpy.data
this_jnt = D.objects.new(jnt_name, None)

Please can someone help me understand how to fix this?

Found the problem. At the top of my script (import_dae.py) outside the functions I was defining the variables:

C = bpy.context
D = bpy.data

This works fine in a “normal” script, but not acceptable in an addon it seems. So once I replaced all D. and C. with the lines above, it all works fine :slight_smile:

1 Like

Thank you stranger!! You helped me a lot!!