I am in need of a way to remove a UV Map datablock of the same name from all selected objects in my scene. I have accomplished this...
import bpy
for obj in bpy.context.selected_objects:
uvt = obj.data.uv_textures
uvt.remove(uvt['UVMap'])
BUT I am looking to improve the functionality of my code to filter through all the selected objects, check to see which objects have the unwanted UV Map datablock, and remove the UVMap from only the matching objects.
For example: Plane.001 has "UVMap" & "Map2", and Plane.002 has only "Map2". Right now, if I have both objects selected, I get an error saying that it couldn't find bpy_prop_collection[key] "UVMap" and fails to execute the script. This must be because Plane.002 doesn't have a "UVMap" datablock...
Here's my current code:
import bpy
for obj in bpy.context.selected_objects:
uvt = obj.data.uv_textures
if uvt != "UVMap":
obj.select = False
uvt.remove(uvt['UVMap'])
How can I have blender deselect Plane.002 and then run the script only on objects that actually have "UVMap" datablock?