Mercurial > code > home > repos > blender-addons
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paste_stencil.py Sat Mar 28 15:57:33 2020 -0700 @@ -0,0 +1,49 @@ +import subprocess, os +import bpy + +class PasteStencil(bpy.types.Operator): + """Paste system clipboard into a new stencil brush""" + bl_idname = "brush.paste_stencil" + bl_label = "Paste Stencil" + + def execute(self, context): + png = subprocess.check_output([ + 'xclip', + '-selection', 'clipboard', + '-target', 'image/png', + '-o']) + for count in range(10000): + outPath = os.path.join(bpy.app.tempdir, 'paste-%d.png' % count) + if not os.path.exists(outPath): + break + else: + raise ValueError('out of filenames') + with open(outPath, 'wb') as f: + f.write(png) + tx = bpy.data.textures.new('paste0', 'IMAGE') + tx.image = bpy.data.images.load(outPath) + print('loaded %s' % outPath) + slot = bpy.data.brushes['TexDraw'].texture_slot + slot.texture = tx + slot.tex_paint_map_mode = 'STENCIL' + + return {"FINISHED"} + + +def register(): + bpy.utils.register_class(PasteStencil) + +def unregister(): + bpy.utils.unregister_class(PasteStencil) + +bl_info = { + 'name': 'Paste Stencil', + "version": (1, 0), + "blender": (2, 79, 0), + "location": "Brush", + "category": "Paint", +} + +if __name__ == "__main__": + register() + bpy.ops.brush.paste_stencil()