0
$\begingroup$

Hey when executing this code it works perfectly the first part of it

import bpy;
oldScene = bpy.context.area.type;
print(oldScene);
bpy.context.area.type = 'OUTLINER';
bpy.ops.outliner.orphans_purge();
#it works fine till this end
bpy.context.area.type = 'TEXT_EDITOR';

After that, calling the current area.type will always return an error! Like pointing to a deleted instance or something. I don't understand so far the problem.

$\endgroup$

1 Answer 1

3
$\begingroup$

If you actually want to change the area, store the area in your variable and change its type.

import bpy

old_area = bpy.context.area
old_type = old_area.type
area_types = [  # available types differ based on blender version check API docs
    'VIEW_3D',
    'TIMELINE',
    'GRAPH_EDITOR',
    'DOPESHEET_EDITOR',
    'NLA_EDITOR',
    'IMAGE_EDITOR',
    'SEQUENCE_EDITOR',
    'CLIP_EDITOR',
    'TEXT_EDITOR',
    'NODE_EDITOR',
    'LOGIC_EDITOR',
    'PROPERTIES',
    'OUTLINER',
    'USER_PREFERENCES',
    'INFO',
    'FILE_BROWSER',
    'CONSOLE',
    ]

for a in area_types:  # cycle through possible area types
    old_area.type = a  # change area to new type
    print(old_area.type)

old_area.type = old_type  # return to original type

Alternatively setup a context override like answer here

$\endgroup$
2
  • $\begingroup$ Dear Ratt, thanks. The code works well but the thing is like this: I am working on a python script that executes directly and I want to do purging for all the accumulated data every while without interrupting the code. I want to open the "OUTLINER" from the "TEXT_EDITOR" side and execute "purge" and then reopen "TEXT_EDITOR" again as if nothing happened. I don't know if this can happen but seems so far like a bug or the "context" loses the pointer of the panel or points to another place after changing the screen. I tried to assign this by pointer of location but It didn't work. Thanks. $\endgroup$ Commented Dec 20, 2018 at 16:38
  • $\begingroup$ or actually we can just point to the outliner and excecute the codes there without changuing the current screen. $\endgroup$ Commented Dec 20, 2018 at 16:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .