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