Custom image format importer I've created an importer for an obscure texture format and I can invoke it as an operator successfully. Because I'm chaining two addons together, (a model importer that also automatically imports textures), I really want to get the resultant image object from the texture import operator so that I can properly . However, because operators can only return success or failure codes (eg. {'FINISHED'}), I can only really guess as to what the resultant image name might be.

The texture importer execute function looks like this:

def execute(self, context):
    dtx = DTX(self.filepath)
    image_name = os.path.splitext(os.path.basename(self.filepath))[0]
    image = bpy.data.images.new(image_name, dtx.width, dtx.height, alpha=True)
    image.pixels[:] = dtx.pixels[:]
    # I want to "return" the image to the caller, indirectly, somehow.
    return {'FINISHED'}


The model import script calls the texture importer like so:

bpy.ops.io_lithtech.import_dtx(filepath=texture)


Is there a way to indirectly return anything from the execution of an operator?
Normally you should implement the Operation as a wrapper on existing code. This way you can call an internal method what can return more information. This is also faster as operations creates undo files.

def load_dtx_texture(filepath):
        dtx = DTX(filepath)
        image_name = os.path.splitext(os.path.basename(filepath))[0]
        image = bpy.data.images.new(image_name, dtx.width, dtx.height, alpha=True)
        image.pixels[:] = dtx.pixels[:]
        return image

class MyTextureImporter(Operator):
    def execute(self, context):
        load_dtx_texture(self.filepath)
        return {'FINISHED'}

class MyMeshImporter(Operator):
    def execute(self, context):

        ....

        image = load_dtx_texture(self.filepath)

        ....

        return {'FINISHED'}