-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathselection.py
44 lines (35 loc) · 1.03 KB
/
selection.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
import bpy
import bpy_types
import contextlib
def select_object(name):
bpy.ops.object.select_all(action='DESELECT')
obj = bpy.data.objects[name]
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
return obj
def all_mesh_objects(root=None):
# Need linked dups that share a mesh to be separately returned
expanded = []
def rec(cur):
if cur.type == 'MESH':
expanded.append(cur.name)
for child in cur.children:
rec(child)
if root is None:
for obj in bpy.data.objects:
if obj.type == 'MESH':
expanded.append(obj.name)
else:
rec(root)
return expanded
def select_objects_in_collection(c: bpy_types.Collection):
bpy.ops.object.select_all(action='DESELECT')
for obj in c.objects:
obj.select_set(True)
@contextlib.contextmanager
def editmode():
if bpy.context.edit_object:
bpy.ops.object.editmode_toggle()
bpy.ops.object.editmode_toggle()
yield
bpy.ops.object.editmode_toggle()