5
$\begingroup$

Is there a way to transfer a whole list (at once) of UV maps from one object to another identical object? By Cmd(ctrl)+L is merely possible copy one by one - super clumsy. Maybe by "bpy.ops.object.join_uvs()" but it does the same and has no more options. enter image description here

$\endgroup$

2 Answers 2

6
$\begingroup$

Select the target meshes (to which you want to copy the UV map), Shift-select the source mesh (that contains the UV maps) and run the following script in the text editor.

import bpy

context = bpy.context
obj = context.active_object
uv_layer_names = [uv.name for uv in obj.data.uv_layers]

if uv_layer_names:
    for ob in context.selected_objects:
        if ob != obj and ob.type =='MESH':
            for uv_map in uv_layer_names:
                obj.data.uv_layers[uv_map].active = True
                if uv_map not in ob.data.uv_layers:
                    ob.data.uv_layers.new(name=uv_map)
                ob.data.uv_layers[uv_map].active = True
                bpy.ops.object.join_uvs()

join_uvs() source for reference: https://developer.blender.org/diffusion/B/browse/master/release/scripts/startup/bl_operators/object.py$583

$\endgroup$
1
  • $\begingroup$ Awesome exactly what I want! Thaks for sharing $\endgroup$ Jan 17 at 10:03
4
$\begingroup$

If you have a lot of objects or data and speed is important:

import bpy
from bpy import context as C
import numpy as np

source = C.active_object
targets = (o for o in C.selected_objects if o is not source)
uvs = np.empty((2 * len(source.data.uv_layers[0].data), 1), "f")

for o in targets:
    target_layers = o.data.uv_layers
    while target_layers:
        o.data.uv_layers.remove(o.data.uv_layers[0])
    for l in source.data.uv_layers:
        l.data.foreach_get('uv', uvs)
        target_layer = target_layers.new(name=l.name, do_init=False)
        target_layer.data.foreach_set('uv', uvs)
        target_layer.active_clone = l.active_clone
        target_layer.active_render = l.active_render
        target_layer.active = l.active

As in pyCod3R's answer it copies UV_layers from active object to other selected objects.

This also makes sure the UV maps of the target objects are exactly the same:

  • number of them
  • names
  • active
  • active_render
  • active_clone

The script works with an assumption the geometry is matching (the number of loops is the same).

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.