Hey,
It drives me crazy…I run a script in ‘scripting’ area in blender it work.
But through a panel it returns a context error ?
here an example :
Working on blender scripting area
import bpy
import os
path = 'path/of/myFile.blend'
scenes = []
with bpy.data.libraries.load(path) as (data_from, data_to):
#print([i for i in dir(data_to)])
for itm in data_from.collections :
if itm.endswith('.anim'):
#print(itm)
scenes.append({"name": itm})
collPath = os.path.join(path, 'Collection')
print(scenes[0]["name"])
bpy.ops.wm.link(directory=collPath, files=scenes)
And through __init__.py
placed on addons folder :
Not working
class simpleClass(bpy.types.Operator):
bl_idname = "myPanel.simple_class"
bl_label = "my simple script"
bl_description = "simple script"
def execute(self, context):
... my script above
return {'FINISHED'}
...register stuff
Error :
location: <unknown location>:-1
Error: Traceback (most recent call last):
File "C:\Program Files\Blender Foundation\Blender 2.82\2.82\scripts\addons\MyAddon\__init__.py", line 124, in execute
bpy.ops.wm.link(directory=collPath, files=scenes)
File "C:\Program Files\Blender Foundation\Blender 2.82\2.82\scripts\modules\bpy\ops.py", line 201, in __call__
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.wm.link.poll() failed, context is incorrect
location: <unknown location>:-1
Have an idea ?