-
Notifications
You must be signed in to change notification settings - Fork 2
/
misc_functions.py
74 lines (49 loc) · 1.93 KB
/
misc_functions.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
# -----------------------------------------------------------------------------
# Determine which mode is currently Selected (Vert, Edge, Face, etc)
# Returned: (0=Multiple modes, 1=Vertice Mode, 2=Edge Mode, 3=Face Mode)
# -----------------------------------------------------------------------------
def getCurrentSelectMode(self, context):
#Create empty list
tempList = []
#check current mesh select mode
for bool in bpy.context.tool_settings.mesh_select_mode:
tempList.append(bool)
#convert list into a tuple
tempTuple = tuple(tempList)
currentSelectMode = int()
if tempTuple == (True, False, False):
currentSelectMode = 1
elif tempTuple == (False, True, False):
currentSelectMode = 2
elif tempTuple == (False, False, True):
currentSelectMode = 3
else:
pass #(defaults currentSelectMode to 0)
return currentSelectMode
# END getCurrentSelectMode(self, context)
def getSelectedVerts(self, context, obj):
mesh = obj.data
#switch to object mode before getting edgeList
bpy.ops.object.mode_set(mode='OBJECT')
vertList = [v for v in mesh.vertices if v.select]
#switch back to edit mode
bpy.ops.object.mode_set(mode='EDIT')
return vertList
def getSelectedEdges(self, context, obj):
mesh = obj.data
#switch to object mode before getting edgeList
bpy.ops.object.mode_set(mode='OBJECT')
edgeList = [e for e in mesh.edges if e.select]
#switch back to edit mode
bpy.ops.object.mode_set(mode='EDIT')
return edgeList
def getAllEdges(self, context, obj):
mesh = obj.data
#switch to object mode before getting edgeList
bpy.ops.object.mode_set(mode='OBJECT')
edgeList = [e for e in mesh.edges]
#edgeList = list(filter(lambda e: e, mesh.edges))
#switch back to edit mode
bpy.ops.object.mode_set(mode='EDIT')
return edgeList