[Bf-extensions-cvs] [8f33ffc] master: Copy and Paste UV =================== - Upload script - Wiki update
Nutti
noreply at git.blender.org
Sat Sep 6 14:52:21 CEST 2014
Commit: 8f33ffcebed445755d3453b8f486306bcf2b142a
Author: Nutti
Date: Fri Sep 5 22:27:09 2014 +0900
Branches: master
https://developer.blender.org/rBAC8f33ffcebed445755d3453b8f486306bcf2b142a
Copy and Paste UV
===================
- Upload script
- Wiki update
The wiki page is ready, see here:
http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/UV/Copy_Paste_UVs
Modified Paths:
-------------------
blender-addons-contrib/uv_copy_and_paste_uv.py
blender-addons-contrib/uv_copy_paste_uvs.py
===================================================================
A uv_copy_and_paste_uv.py
D uv_copy_paste_uvs .py
===================================================================
diff --git a/uv_copy_and_paste_uv.py b/uv_copy_and_paste_uv.py
new file mode 100644
index 0000000..84a74bf
--- /dev/null
+++ b/uv_copy_and_paste_uv.py
@@ -0,0 +1,171 @@
+# <pep8-80 compliant>
+
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+import bpy
+
+bl_info = {
+ "name" : "Copy and Paste UV",
+ "author" : "Nutti",
+ "version" : (1,1),
+ "blender" : (2, 6, 5),
+ "location" : "UV Mapping > Copy and Paste UV",
+ "description" : "Copy and Paste UV data",
+ "warning" : "",
+ "wiki_url" : "",
+ "tracker_url" : "",
+ "category" : "UV"
+}
+
+src_indices = None # source indices
+dest_indices = None # destination indices
+src_obj = None # source object
+
+
+# copy UV
+class CopyAndPasteUVCopyUV(bpy.types.Operator):
+ """Copying UV coordinate on selected object."""
+
+ bl_idname = "uv.copy_uv"
+ bl_label = "Copy UV"
+ bl_description = "Copy UV data"
+ bl_options = {'REGISTER', 'UNDO'}
+
+ def execute(self, context):
+
+ # global variables
+ global src_indices
+ global dest_indices
+ global src_obj
+
+ # get active (source) object to be copied from
+ active_obj = bpy.context.active_object;
+
+ # change to 'OBJECT' mode, in order to access internal data
+ mode_orig = bpy.context.object.mode
+ bpy.ops.object.mode_set(mode='OBJECT')
+
+ # create source indices list
+ src_indices = []
+ for i in range(len(active_obj.data.polygons)):
+ # get selected faces
+ poly = active_obj.data.polygons[i]
+ if poly.select:
+ src_indices.extend(poly.loop_indices)
+
+ # check if any faces are selected
+ if len(src_indices) == 0:
+ self.report({'WARNING'}, "No faces are not selected.")
+ bpy.ops.object.mode_set(mode=mode_orig)
+ return {'CANCELLED'}
+ else:
+ self.report(
+ {'INFO'},
+ "%d indices are selected." % len(src_indices))
+ src_obj = active_obj
+
+ # revert to original mode
+ bpy.ops.object.mode_set(mode=mode_orig)
+
+ return {'FINISHED'}
+
+
+# paste UV
+class CopyAndPasteUVPasteUV(bpy.types.Operator):
+ """Paste UV coordinate which is copied."""
+
+ bl_idname = "uv.paste_uv"
+ bl_label = "Paste UV"
+ bl_description = "Paste UV data"
+ bl_options = {'REGISTER', 'UNDO'}
+
+ def execute(self, context):
+
+ # global variables
+ global src_indices
+ global dest_indices
+ global src_obj
+
+ # check if copying operation was executed
+ if src_indices is None or src_obj is None:
+ self.report({'WARNING'}, "Do copy operation at first.")
+ return {'CANCELLED'}
+
+ # get active (source) object to be pasted to
+ active_obj = bpy.context.active_object
+
+ # change to 'OBJECT' mode, in order to access internal data
+ mode_orig = bpy.context.object.mode
+ bpy.ops.object.mode_set(mode='OBJECT')
+
+ # create source indices list
+ dest_indices = []
+ for i in range(len(active_obj.data.polygons)):
+ # get selected faces
+ poly = active_obj.data.polygons[i]
+ if poly.select:
+ dest_indices.extend(poly.loop_indices)
+
+ if len(dest_indices) != len(src_indices):
+ self.report(
+ {'WARNING'},
+ "Number of selected faces is different from copied faces." +
+ "(src:%d, dest:%d)" % (len(src_indices), len(dest_indices)))
+ bpy.ops.object.mode_set(mode=mode_orig)
+ return {'CANCELLED'}
+ else:
+ dest_obj = active_obj
+
+ # update UV data
+ src_uv = src_obj.data.uv_layers.active # source UV data
+ dest_uv = dest_obj.data.uv_layers.active # destination UV data
+ for i in range(len(dest_indices)):
+ dest_data = dest_uv.data[dest_indices[i]]
+ src_data = src_uv.data[src_indices[i]]
+ dest_data.uv = src_data.uv
+
+ self.report(
+ {'INFO'},
+ "%d indices are copied." % len(dest_indices))
+
+ # revert to original mode
+ bpy.ops.object.mode_set(mode=mode_orig)
+
+ return {'FINISHED'}
+
+
+# registration
+
+def menu_func(self, context):
+ self.layout.operator("uv.copy_uv")
+ self.layout.operator("uv.paste_uv")
+
+
+def register():
+ bpy.utils.register_module(__name__)
+ bpy.types.VIEW3D_MT_uv_map.append(menu_func)
+
+
+def unregister():
+ bpy.utils.unregister_module(__name__)
+ bpy.types.VIEW3D_MT_uv_map.remove(menu_func)
+
+
+if __name__ == "__main__":
+ register()
diff --git a/uv_copy_paste_uvs .py b/uv_copy_paste_uvs .py
deleted file mode 100644
index b4283a0..0000000
--- a/uv_copy_paste_uvs .py
+++ /dev/null
@@ -1,180 +0,0 @@
-# BEGIN GPL LICENSE BLOCK #####
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# END GPL LICENSE BLOCK #####
-
-bl_info = {
- "name": "Copy/Paste UVs",
- "author": "Jace Priester",
- "version": (1, 1),
- "blender": (2, 6, 3),
- "location": "UV Mapping > Copy/Paste UVs",
- "description":
- "Copy/Paste UV data between groups "
- "of vertices in the same mesh object",
- "warning": "",
- "wiki_url": "http://wiki.blender.org/index.php?title=Extensions:2.6/"
- "Py/Scripts/Mesh/Copy_Paste_UVs",
- "tracker_url": "http://projects.blender.org/tracker/"
- "?group_id=153&atid=467&func=detail&aid=32562",
- "category": "UV"}
-
-
-import bpy
-
-
-#source_object = None
-copy_buffer = ''
-
-
-class CopyPasteUVs_Copy(bpy.types.Operator):
-
- ''''''
- bl_idname = "uv.copy_uvs"
- bl_label = "Copy UVs"
- bl_description = "Copy UVs"
- bl_options = {'REGISTER', 'UNDO'}
-
- ''' Properties
- def draw(self, context):
- layout = self.layout
- col = layout.column()
- col.prop(self, 'error', expand=True) '''
-
- # execute
- def execute(self, context):
- # print("------START------")
-
- global copy_buffer
- #global source_object
-
- copy_buffer = []
- #source_object = None
-
- obj = bpy.context.active_object
- bpy.ops.object.mode_set(mode='OBJECT')
-
- vertex_indexes = [i for i, v in enumerate(obj.data.vertices) if v.select]
-
- if len(vertex_indexes) == 0:
- self.report({'WARNING'}, "Must have selected vertices to copy.")
- else:
- copy_buffer = vertex_indexes
- #source_object = obj
-
- bpy.ops.object.mode_set(mode='EDIT')
-
- # print("-------END-------")
- return {'FINISHED'}
-
-
-class CopyPasteUVs_Paste(bpy.types.Operator):
-
- ''''''
- bl_idname = "uv.paste_uvs"
- bl_label = "Paste UVs"
- bl_description = "Paste UVs"
- bl_options = {'REGISTER', 'UNDO'}
-
- ''' Properties
- def draw(self, context):
- layout = self.layout
- col = layout.column()
- col.prop(self, 'error', expand=True) '''
-
- # execute
- def execute(self, context):
- # print("------START------")
-
- global copy_buffer
- #global source_object
-
- if len(copy_buffer) == 0:
- print("Must have copied first!")
- else:
- obj = bpy.context.active_object
- bpy.ops.object.mode_set(mode='OBJECT')
-
- selectedVertexIndexes = [i for i, v in enumerate(obj.data.vertices) if v.select]
-
- if len(selectedVertexIndexes) == 0:
- self.report(
- {'WARNING'},
- "Must have vertices selected to paste.")
- elif len(selectedVertexIndexes) != len(copy_buffer):
- self.report(
- {'WARNING'},
- "Number of copied verts is not the same as number selected now.")
- else:
-
- source_loops = []
- destination_loops = []
-
- for i, source_index in enumerate(copy_buffer):
- #source_index = copy_buffer[i]
- destination_index = selectedVertexIndexes[i]
-
- for loop_index, loop_obj in enumerate(obj.data.loops):
- if obj.data.loops[loop_index].vertex_index == destination_index:
- destination_loops.append(loop_index)
-
- if obj.data.loops[loop_index].vertex_index == source_index:
- source_loops.append(loop_index)
-
- if len(source_loops) != len(destination_loops):
- self.report(
- {'WARNING'}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list