Script to simply delete all cameras and lights
Martirilla
Posts: 181
Is there really no Python script that will delete all lights (lamps) and cameras from a Blender scene? And yet, after a great deal of searching, that appears to be the case. Does anyone have such a thing that they can share, please?
Comments
Ok, I patched it together myself, from a Stack Overflow discussion on resetting a Blender file to the default. This works in 2.7, which is where my target assets are... and I have added the 2.8 tweak in the script's header.
I'm still astounded that such a simple helper script is not to be easily found.
Not sure if one exists, but in the meantime you can click on the filter in the top right, then isolate all the cameras and lights, then delete.
Thanks Krampus. Yes, I'm getting the distinct impression that the Blender crowd just love doing things manually, time after time, the hard way. :-)
Great start, Martirilla.
One thing to note, though; For going from B2.7x to B2.8x, you also need to change the lights variable as you have with the select variable.
Lights TYPE has changed from 'LAMP' in 2.7x to 'LIGHT' in 2.8x.
So, your type selection code would be :
o.type == 'LIGHT':
I believe your opening post as to why you can't find a script for this is more want vs need, and maybe no coders saw a need for this yet, or this function already exists in a specific addon you haven't found yet. I know of none, but that does not mean it does not exist.
You have a need (and a great idea!), so creating the script (and sharing) was a good thing to do.
I think this could be fleshed-out to a full (simple) addon with user selected preferences for where user would like to employ it.
I believe 3 delete buttons would be good; One for delete all cameras, one for delete all lights, and one for delete all (both).
My idea would be to add 2 or 3 variables for it to be used from either an addon Tool Tab (SideBar -- user selectable location), the TopBar (or toggleable Header), or possibly from one of the Properties Tabs.
* If usable from one of the Properties Tabs, which PT do you feel would be most appropiate to locate the delete buttons in?
Regarding the Blender crowd just wanting to do everything manually, if this were true, there wouldn't be so many paid-for addons which basically are just automation macros combining many manual steps into single button operations, or modal actions.
I do this heavily, myself, with my addons -- So, I do not have to do everything manually (time after time, the hard way)...