How to delete a screen layout via Python?

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["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]

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

import bpy["Animation"]

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.

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

delete_material =[“Material”], do_unlink = True)

I did this…

import bpy
delete_screen =["bad"], do_unlink=True)

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

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

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.

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)

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)

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

bad scene layout_fixed.blend (572 KB)

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

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

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:


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.

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

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