-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathDUV_UVCopy.py
49 lines (38 loc) · 1.84 KB
/
DUV_UVCopy.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
import bpy
import bmesh
class DREAMUV_OT_uv_copy(bpy.types.Operator):
"""Copy selected UVs to other UV set"""
bl_idname = "view3d.dreamuv_uvcopy"
bl_label = "copy selected uvs from uv2 to uv1"
bl_options = {"UNDO"}
#bl_options = {'SEARCH_ON_KEY_PRESS'}
reverse : bpy.props.BoolProperty()
def execute(self, context):
if len(bpy.context.object.data.uv_layers) == 2:
#make sure active object is actually selected in edit mode:
if bpy.context.object.mode == 'EDIT':
bpy.context.object.select_set(True)
#check for object or edit mode:
objectmode = False
if bpy.context.object.mode == 'OBJECT':
objectmode = True
#switch to edit and select all
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='SELECT')
obj = bpy.context.view_layer.objects.active
bm = bmesh.from_edit_mesh(obj.data)
uv_layer = bm.loops.layers.uv[0]
uv_layer2 = bm.loops.layers.uv[1]
for f in bm.faces:
if f.select:
for vert in f.loops:
if self.reverse == True:
vert[uv_layer].uv.x = vert[uv_layer2].uv.x
vert[uv_layer].uv.y = vert[uv_layer2].uv.y
if self.reverse == False:
vert[uv_layer2].uv.x = vert[uv_layer].uv.x
vert[uv_layer2].uv.y = vert[uv_layer].uv.y
bmesh.update_edit_mesh(obj.data)
if objectmode is True:
bpy.ops.object.editmode_toggle()
return {'FINISHED'}