I've been trying for days to create a script for my addon that does the following things:

  1. Open an existing file A.
  2. Link an existing B file using a Link link.
  3. Create an Override Library on this file.

The problem is that when you open the A file the context disappears and does not allow the command to run


The error message is that the context is incorrect.


finally i've found the solution...

  for w in bpy.context.window_manager.windows:
    if w.screen.name  == "Layout":
      for area in w.screen.areas:
        if area.type == 'VIEW_3D':
          for region in area.regions:
             if region.type == 'WINDOW':
                override = bpy.context.copy()
                override[ 'area'] = area
                override['region'] = region

Not the answer you're looking for? Browse other questions tagged or ask your own question.