How to delete a screen layout via Python?


(simplecarnival) #1

I have a screen layout in my project file which appears to be corrupt. If I try selecting it via the Blender UI, Blender freezes and I have to quit out of the application.

I would like to remove this screen layout from the project, and I was thinking I could do it in Python with something like this…


import bpy
bpy.data.screens.remove(bpy.data.screens["bad"])

…but am unable to do so. I get an “AttributeError: ‘bpy_prop_collection’ object has no attribute ‘remove’” message.

What is the correct syntax to remove a screen layout? Thanks!

**** UPDATE: Here’s an example .blend file that demonstrates the problem. See if you can delete the screen layout called “bad”: [ATTACH]497741[/ATTACH]


(Spirou4D) #2

is it something like this if you want delete the “Animation” layout :

import bpy

bpy.context.window.screen=bpy.data.screens["Animation"]
bpy.ops.screens.delete()

(simplecarnival) #3

That puts a zero next to the bad screen layout in the screen layout dropdown. However, after saving the project file, closing Blender, then reloading the saved project file, the bad screen layout is still there. When I try to select the bad screen layout (either after executing the above code or after reloading the file), Blender still hangs.


(AFWS) #4

For materials do something like this, prolly works the same way.

delete_material = bpy.data.materials[“Material”]
bpy.data.materials.remove(delete_material, do_unlink = True)


(simplecarnival) #5

I did this…


import bpy
delete_screen = bpy.data.screens["bad"]
bpy.data.screens.remove(delete_screen, do_unlink=True)

…and got me the same result as the original code I posted – “AttributeError: ‘bpy_prop_collection’ object has no attribute ‘remove’”.


(Spirou4D) #6

@simplecarnival
I have corrected my code and it’s run perfectly now!


(simplecarnival) #7

Theoretically, that updated code should work, but it doesn’t because it’s first selecting the corrupt scene layout. So running that first line freezes Blender; it never gets to the second line where it deletes the scene layout.

I need a way to remove the corrupt scene layout without actually trying to display it in Blender. I tried going through the Outliner’s Data Blocks but didn’t see a way to delete the scene through there (if there is, please tell me!). That’s why I figured there had to be a way to do it via Python.


(simplecarnival) #8

Here’s an example .blend file that demonstrates the problem. See if you can delete the screen layout called “bad”: bad scene layout.blend (605 KB)


(Spirou4D) #9

Yes may be you can’t delete a layout if you are not on it:
I agree with you: Difficult problem! I don’t know but go to the blender stack-exchange to tell your question to the blender dev…

but I know that the standart layouts can’t to be delete, only new custom layouts.

Here is your file without your bad layout: good_scene_layout.blend (813 KB)


(AFWS) #10

Here, tons of fun,lol
Looks like Spirou4D beat me

bad scene layout_fixed.blend (572 KB)


(AFWS) #11

How did you end up doing it? I tried several things that should have worked ,but didn’t.


(Spirou4D) #12

you blend was corrupted, I have append all asset in a new file simply!


(simplecarnival) #13

Great trick! Thanks for figuring that out. Now at least I have a startup file that isn’t corrupted.

OK, now for the trickier part. I’m working with a 112 MB .blend file. It has rigged characters (via BlenRig), tons of animation data, models, lattices and curves that affect models, Python Code (from BlenRig)…just a LOT of data in it. It also has a corrupted screen layout. I am unable to just append a scene into a ‘clean’ file, as Blender crashes when I try that.

I’ve got the following possible folders when I try to append the 112 MB .blend file into a clean .blend file:

Action
Armature
Brush
Camera
Curve
FreestyleLineStyle
Group
Image
Lamp
Lattice
Material
Mesh
MovieClip
NodeTree
Object
Scene
Sound
Text
Texture
World

Do you have any recommendations as far as which order I should append things into the clean file?

I can make some educated guesses on the correct order, but I wanted to first see if there were any “known good” ways to accomplish this before I sink any more time into this particular issue.


(AFWS) #14

I put this together, see if it works on your blend. Might be handy if you come across problem again.

screen_delete.zip (873 Bytes)


(simplecarnival) #15

Beautiful! That works perfectly. Thank you so much, AFWS!