Make a Blender script run an external program I'm making a script to share data between Blender and After Effects: i created an addon in Blender which exports a .txt file in the After Effects directory (or a custom one) and I created a After Effects script (which uses Java) with ExtendScript ToolKit that reads the file and import the data.

To improve the user's experience I wanted to execute the Ae script from Blender (if Ae is already open), and maybe share some info with it, like the path to the .txt file, the current version and some settings needed in Ae (I could generate another .txt in the windows Temp folder, but a direct connection would be better, I think).

Is it possible to do so?
The way i think to do so, (if you want it to be dynamic) is by doing a socket connection. (But i dont know After Effects). Here you have an example using the fancy async way.
* you'll have to run this somehow from After Effecs [that's what im not sure you'll be able to do]. The idea is to make a server and a client to send data between your programs, blender &amp; A.E. in the case.

import asyncio

async def tcp_echo_client(message, loop):

    reader, writer = await asyncio.open_connection('127.0.0.1', 8888,
                                               loop=loop)

    print('Send: %r' % message)
    writer.write(message.encode())

    data = await reader.read(100)
    print('Received: %r' % data.decode())

    print('Close the socket')
    writer.close()

message = 'Hello World!'

loop = asyncio.get_event_loop()

loop.run_until_complete(tcp_echo_client(message, loop))

loop.close()



this is going to be the server, you have to run it from AE i guess.
then you have to configure your client from Blender side with this other script


&nbsp;

import asyncio


async def _send(message, loop):

        reader, writer = await asyncio.open_connection('127.0.0.1', 8888,
                                                   loop=loop)

        print('Send: %r' % message)
        writer.write(message.encode())

        data = await reader.read(100)
        print('Received: %r' % data.decode())

        print('Close the socket')
        writer.close()

def send(data):

        loop = asyncio.get_event_loop()
        loop.run_until_complete(_send(data, loop))

data = "hello world"

send(data)


"""
i dont know if you need all the code or it is redundant, i edited an example from asyncIO site and worked for me. good luck"""