1
$\begingroup$

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?

$\endgroup$
2
$\begingroup$

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 & 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

 

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"""

$\endgroup$
  • $\begingroup$ mmm ok, it seems tricky but duable... so, i guess i need the Ae script to start at startup, which is a bummer (i think it would consume more resources than needed), but i'll try it anyway... the message in your example is a simple string, but i guess that if i placed the name of the main Ae script function it would work right? (like sending the name of an operator to Blender) Also, since this seems quite tricky to understand, (i'd like to know better how it worksbefore implementing), do you know if there is any tutorial/ guide/ documentation about this? $\endgroup$ – Tareyes Dec 10 '18 at 10:45
  • $\begingroup$ I dont think it'll take very much resources (is a matter of the amount of data you send / receive. data = await reader.read(100) i think it means 100 bytes. i saw some example of async on blender nation i beleave (not sure...) but was way more complex than this one. $\endgroup$ – Javier Dec 10 '18 at 18:25
  • $\begingroup$ I dont think it'll take very much resources (is a matter of the amount of data you send / receive. data = await reader.read(100) think it means 100 bytes. i saw some example of async on blender nation i beleave (not sure...) but was way more complex than this one. I dont know very much about operators work, i cant tell. And finally i think data = "hello world" it can be whatever you want to send, you just have to make it to match to your AE data needs. As said, i dont know AE but i beleave there's an asyncIO bind library for JS. $\endgroup$ – Javier Dec 10 '18 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.