comparison paste_stencil.py @ 2:d22d386c5e04

some old addons that need updating
author drewp@bigasterisk.com
date Sat, 28 Mar 2020 15:57:33 -0700
parents
children
comparison
equal deleted inserted replaced
1:d07887d9837e 2:d22d386c5e04
1 import subprocess, os
2 import bpy
3
4 class PasteStencil(bpy.types.Operator):
5 """Paste system clipboard into a new stencil brush"""
6 bl_idname = "brush.paste_stencil"
7 bl_label = "Paste Stencil"
8
9 def execute(self, context):
10 png = subprocess.check_output([
11 'xclip',
12 '-selection', 'clipboard',
13 '-target', 'image/png',
14 '-o'])
15 for count in range(10000):
16 outPath = os.path.join(bpy.app.tempdir, 'paste-%d.png' % count)
17 if not os.path.exists(outPath):
18 break
19 else:
20 raise ValueError('out of filenames')
21 with open(outPath, 'wb') as f:
22 f.write(png)
23 tx = bpy.data.textures.new('paste0', 'IMAGE')
24 tx.image = bpy.data.images.load(outPath)
25 print('loaded %s' % outPath)
26 slot = bpy.data.brushes['TexDraw'].texture_slot
27 slot.texture = tx
28 slot.tex_paint_map_mode = 'STENCIL'
29
30 return {"FINISHED"}
31
32
33 def register():
34 bpy.utils.register_class(PasteStencil)
35
36 def unregister():
37 bpy.utils.unregister_class(PasteStencil)
38
39 bl_info = {
40 'name': 'Paste Stencil',
41 "version": (1, 0),
42 "blender": (2, 79, 0),
43 "location": "Brush",
44 "category": "Paint",
45 }
46
47 if __name__ == "__main__":
48 register()
49 bpy.ops.brush.paste_stencil()