Well, here is my addon:
# -*- coding: utf-8 -*-
import bpy
import os
import sys
import subprocess
import time
from threading import *
class Repeat(Thread):
def __init__(self,delay,function,*args,**kwargs):
Thread.__init__(self)
self.abort = Event()
self.delay = delay
self.args = args
self.kwargs = kwargs
self.function = function
def stop(self):
self.abort.set()
def run(self):
while not self.abort.isSet():
self.function(*self.args,**self.kwargs)
self.abort.wait(self.delay)
class ExportToGIMP(bpy.types.Operator):
bl_idname = "uv.exporttogimp"
bl_label = "Export to GIMP"
def execute(self, context):
try:
os.remove("/home/antoni4040/blender.txt")
except:
pass
self.filepath = os.path.join(os.path.dirname(bpy.data.filepath), "Layout")
bpy.ops.uv.export_layout(filepath=self.filepath, check_existing=True, export_all=False, modified=False, mode='PNG', size=(1024, 1024), opacity=0.25, tessellated=False)
self.files = os.path.dirname(bpy.data.filepath)
cmd = " (python-fu-bgsync RUN-NONINTERACTIVE)"
subprocess.Popen(['gimp', '-b', cmd])
self.object = bpy.context.active_object
self.file = Repeat(3, self.up)
self.file.start()
return {'FINISHED'};
def up(self):
try:
f = open("/home/antoni4040/blender.txt", "r")
string = f.read()
if "ok" in string:
self.materialize()
self.doit()
self.file.stop()
else:
pass
except:
pass
def doit(self):
r = Repeat(3, self.update)
r.start()
def materialize(self):
self.layout_texture = bpy.data.textures.new(name = "Layout_Texture", type = "IMAGE")
self.material = bpy.data.materials.new(name="Layout")
self.material_texture = self.material.texture_slots.add()
self.material_texture.texture = self.layout_texture
self.material_texture.texture_coords = "UV"
self.filepath2 = "/home/antoni4040/Έγγραφα/Layout1.png"
self.texture_image = bpy.data.images.load(self.filepath2)
self.layout_texture.image = self.texture_image
self.con_obj = self.object.data
self.con_obj.materials.append(self.material)
bpy.data.screens['UV Editing'].areas[1].spaces[0].image = self.texture_image
def update(self):
self.layout_texture.image.reload()
for area in bpy.data.screens['Default'].areas:
if area.type in ['IMAGE_EDITOR', 'VIEW_3D']:
area.tag_redraw()
def exporttogimp_menu(self, context):
self.layout.operator(ExportToGIMP.bl_idname, text="Export To GIMP")
bpy.utils.register_class(ExportToGIMP)
bpy.types.IMAGE_MT_uvs.append(exporttogimp_menu)
The only problems are the Segmentation Faults… What’s going wrong?