Advertisement
Guest User

Blender - Match Active UV operator

a guest
Jan 13th, 2020
1,178
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This operator will look at all selected objects and match the active UV layer to whatever is the currently active object is.
  2. # if the uv layer does not exist, it will remain the same.
  3.  
  4. import bpy
  5.  
  6. class OBJECT_OT_set_active_uv(bpy.types.Operator):
  7.     """Tooltip"""
  8.     bl_idname = "object.set_active_uv"
  9.     bl_label = "Set Active UV to Match Active Object"
  10.  
  11.     @classmethod
  12.     def poll(cls, context):        
  13.         return context.active_object is not None and hasattr(o, "data") and isinstance(o.data, bpy.types.Mesh)
  14.  
  15.     def execute(self, context):        
  16.         target_uv = [uv.name for uv in context.active_object.data.uv_layers if uv.active][0]
  17.         for o in context.selected_objects:
  18.             if hasattr(o, "data") and isinstance(o.data, bpy.types.Mesh):
  19.                 for key in o.data.uv_layers.keys():
  20.                     if key == target_uv:
  21.                         o.data.uv_layers[key].active = True
  22.                         break
  23.         return {'FINISHED'}
  24.  
  25. def register():
  26.     bpy.utils.register_class(OBJECT_OT_set_active_uv)
  27.  
  28.  
  29. def unregister():
  30.     bpy.utils.unregister_class(OBJECT_OT_set_active_uv)
  31.  
  32.  
  33. if __name__ == "__main__":
  34.     register()
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement