-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
74 lines (52 loc) · 1.66 KB
/
utils.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import bpy
import subprocess
import sys
import platform
import os
def hide(obj_name):
obj = bpy.data.objects.get(obj_name)
obj.hide_render = True
obj.hide_set(True)
def deselect_all():
for obj in bpy.context.selected_objects:
obj.select_set(False)
def hide_all_except(except_obj_name):
for obj_name in [obj.name for obj in bpy.data.objects]:
hide(obj_name)
un_hide(except_obj_name)
def select_obj(obj):
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
def un_hide(obj_name):
obj = bpy.data.objects.get(obj_name)
obj.hide_render = False
obj.hide_set(False)
def remove_all_materials_from(obj_name):
obj = bpy.data.objects.get(obj_name)
obj.data.materials.clear()
def remove_unused_images():
for img in bpy.data.images:
if not img.users:
bpy.data.images.remove(img)
def remove_unused_materials():
for material in bpy.data.materials:
if not material.users:
bpy.data.materials.remove(material)
def get_absolute_path(relative_path):
filepath = bpy.data.filepath
directory = os.path.dirname(filepath)
return os.path.abspath(directory + relative_path)
def open_os_directory(path):
if platform.system() == 'Windows':
os.startfile(path)
elif platform.system() == 'Darwin':
subprocess.Popen(['open', path])
else:
subprocess.Popen(['xdg-open', path])
def copy_object(source_obj, obj_copy_name):
obj_copy = source_obj.copy()
obj_copy.data = source_obj.data.copy()
obj_copy.animation_data_clear()
bpy.context.collection.objects.link(obj_copy)
obj_copy.name = obj_copy_name
return obj_copy