-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_blender.py
47 lines (43 loc) · 1.42 KB
/
utils_blender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import bpy
def deselect(scene):
#scene = bpy.context.scene
for obj in scene.objects:
obj.select_set(False)
def clear_mesh():
"""
Clears all meshes in the scene. Removes left-over materials.
"""
bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.data.objects:
if obj.type == 'MESH':
obj.select_set(True)
# Remove materials and images to save memory
if obj.data.materials != None:
for i, mat in reversed(list(enumerate(obj.data.materials))):
if mat != None:
bpy.data.materials.remove(mat)
bpy.ops.object.delete()
for mesh in bpy.data.meshes:
bpy.data.meshes.remove(mesh)
def clear_cameras():
"""
Clears all lights in the scene. Removes left-over materials.
"""
bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.data.objects:
if obj.type == 'CAMERA':
obj.select_set(True)
bpy.ops.object.delete()
for mesh in bpy.data.meshes:
bpy.data.meshes.remove(mesh)
def clear_lights():
"""
Clears all lights in the scene. Removes left-over materials.
"""
bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.data.objects:
if obj.type == 'LIGHT':
obj.select_set(True)
bpy.ops.object.delete()
for mesh in bpy.data.meshes:
bpy.data.meshes.remove(mesh)