Results 1 to 15 of 15

Thread: How to delete a screen layout via Python?

  1. #1
    Member simplecarnival's Avatar
    Join Date
    Feb 2014
    Location
    Pittsburgh, PA
    Posts
    270

    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...

    Code:
    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": bad scene layout.blend
    Last edited by simplecarnival; 09-Sep-17 at 13:36.



  2. #2
    Member Spirou4D's Avatar
    Join Date
    Jul 2010
    Location
    Lille, France
    Posts
    1,248
    is it something like this if you want delete the "Animation" layout :

    Code:
    import bpy
    
    bpy.context.window.screen=bpy.data.screens["Animation"]
    bpy.ops.screens.delete()
    Last edited by Spirou4D; 09-Sep-17 at 13:15.
    Words are Images that loosed Light!
    Linux Mint 18.1 Serena Bi-Quad Intel 2.66Ghz x64Bytes - Nvidia OpenGL GT 630 4Go-vram



  3. #3
    Member simplecarnival's Avatar
    Join Date
    Feb 2014
    Location
    Pittsburgh, PA
    Posts
    270
    Originally Posted by Spirou4D View Post
    is it something like this :

    Code:
    import bpy
    
    bpy.data.screens["Default"].user_clear()
    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.



  4. #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)



  5. #5
    Member simplecarnival's Avatar
    Join Date
    Feb 2014
    Location
    Pittsburgh, PA
    Posts
    270
    Originally Posted by AFWS View Post
    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)
    I did this...
    Code:
    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'".



  6. #6
    Member Spirou4D's Avatar
    Join Date
    Jul 2010
    Location
    Lille, France
    Posts
    1,248
    @simplecarnival
    I have corrected my code and it's run perfectly now!
    Words are Images that loosed Light!
    Linux Mint 18.1 Serena Bi-Quad Intel 2.66Ghz x64Bytes - Nvidia OpenGL GT 630 4Go-vram



  7. #7
    Member simplecarnival's Avatar
    Join Date
    Feb 2014
    Location
    Pittsburgh, PA
    Posts
    270
    Originally Posted by Spirou4D View Post
    @simplecarnival
    I have corrected my code and it's run perfectly now!
    Code:
    import bpy 
    bpy.context.window.screen=bpy.data.screens["Animation"]
    bpy.ops.screens.delete()
    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.



  8. #8
    Member simplecarnival's Avatar
    Join Date
    Feb 2014
    Location
    Pittsburgh, PA
    Posts
    270
    Here's an example .blend file that demonstrates the problem. See if you can delete the screen layout called "bad": bad scene layout.blend



  9. #9
    Member Spirou4D's Avatar
    Join Date
    Jul 2010
    Location
    Lille, France
    Posts
    1,248
    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...
    https://blender.stackexchange.com

    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
    Last edited by Spirou4D; 09-Sep-17 at 14:19.
    Words are Images that loosed Light!
    Linux Mint 18.1 Serena Bi-Quad Intel 2.66Ghz x64Bytes - Nvidia OpenGL GT 630 4Go-vram



  10. #10
    Here, tons of fun,lol
    Looks like Spirou4D beat me

    bad scene layout_fixed.blend
    Last edited by AFWS; 09-Sep-17 at 14:54.



  11. #11
    Originally Posted by Spirou4D View Post
    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...
    https://blender.stackexchange.com

    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
    How did you end up doing it? I tried several things that should have worked ,but didn't.



  12. #12
    Member Spirou4D's Avatar
    Join Date
    Jul 2010
    Location
    Lille, France
    Posts
    1,248
    you blend was corrupted, I have append all asset in a new file simply!
    Words are Images that loosed Light!
    Linux Mint 18.1 Serena Bi-Quad Intel 2.66Ghz x64Bytes - Nvidia OpenGL GT 630 4Go-vram



  13. #13
    Member simplecarnival's Avatar
    Join Date
    Feb 2014
    Location
    Pittsburgh, PA
    Posts
    270
    Originally Posted by Spirou4D View Post
    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:

    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.
    Last edited by simplecarnival; 09-Sep-17 at 15:47.



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


    screen_delete.zip



  15. #15
    Member simplecarnival's Avatar
    Join Date
    Feb 2014
    Location
    Pittsburgh, PA
    Posts
    270
    Originally Posted by AFWS View Post
    I put this together, see if it works on your blend. Might be handy if you come across problem again.


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



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •