Skip to main content
Known Participant
March 6, 2023
Answered

Force rendering on an event in a separate thread/Coming back to the main UI thread on an event

  • March 6, 2023
  • 1 reply
  • 3219 views

Hi,
    I'm new to the After Effects sdk. I've set the out_data->out_flags to include PF_OutFlag_REFRESH_UI and PF_OutFlag_FORCE_RERENDER in the PF_Cmd_USER_CHANGED_PARAM handler. This works correctly when the parameter value is changed within the user interface.

I recently integrated WebSocket using easywsclient to receive messages from an external application, and I'm handling the messages in a separate thread using tinythread, which is from easywsclient.

Whenever I want to force render on a button tap or anywhere, I set the out_data->out_flags with PF_OutFlag_REFRESH_UI andPF_OutFlag_FORCE_RERENDER. 
But if I set these out_flags in the separate thread in which I'm handling the messages received from the websocket, the UI isn't force rendered.
Is there a way to come back to the main UI thread or call a function in the main thraed when receiving message in the other thread?
Or another way to force render when I receive a message in the separate thread.
Thank you!

This topic has been closed for replies.
Correct answer shachar carmi

If I try to force render in an Idle hook, how will I get out_data, to call the

out_data->out_flags |= PF_OutFlag_REFRESH_UI | PF_OutFlag_FORCE_RERENDER
Storing the out_data as global however doesn't work


I had another workaround in mind. Can I add a command in Edit menu to force a rerender? And when in the other thread I want to re-render, I can call the command with the DO_Command. But the problem is again that I don't have the out_data for which to call force render and refreshUI

 


add some hidden param, and change it's value when you can to force a re-render in idle_hook.

1 reply

Community Expert
March 6, 2023

it's possible only via idle hook. wait for an idle event (happens 30-50 times per second), check your other thread for messages and act. idle calls happen on the UI thread, so it's a valid time to make changes to the project.

you can either:
1. change some invisible param value that would force a re-render.

2. call the command number to purge the cache.

3. call AEGP_EffectCallGeneric and have the effect instance act on itself.

Veena2411Author
Known Participant
April 5, 2023

1. I tried changing an invisible param value, which does force a re-render, but not in a separate thread. Is there a right way to change the param value in the main UI thread?
2. If I call the commands 2372 or 2373, it usually doesn't cause the re-render (although sometimes it does). If I call the command 10200, it does force a render but it gives me a popup "Are you sure you want to delete caches". And I don't want a popup to be there everytime.

3. I tried to find about the AEGP_EffectCallGeneric but not sure how it can help me

Community Expert
May 2, 2023

Ok currently I'm incrementing. But my param is a slider type, which will have a max value. Is there a param that can have infinite values?


well, maybe an arb param, bu that's a bit of an overkill.

i'd go with a timestamp. the chances of hitting 2 equal values that happen to be cached are negligible.