Skip to main content
Participant
September 27, 2017
Question

Custom Expression Functions

  • September 27, 2017
  • 4 replies
  • 1482 views

Hi,

I'd like to know if it's possible to create custom expression functions with the plugin SDK.

For example, say I wanted to allow users to enter the following expression: "getThingamabob(2, 'yes')". is there any way to "provide" the "getThingamabob" function from a plugin with the SDK?

I've scoured through the SDK guide to see if it mentions anything, but haven't had any luck.

This topic has been closed for replies.

4 replies

françois leroy
Inspiring
October 11, 2017

Hi tomb23568765!

there is one workaround:

expressions can read a file, and grab data from this file, like this:

$.evalFile("~/Desktop/myFunctions.txt");

So, you can write an AEGP plugin that creates a "myFunctions.txt" file on your desktop, and fill it with anything you want, like:

function getThingamabob(num, question) {

if (num == 2 and question == 'yes') {

          return true;

     } else {

          return false;

     }

}

Then, your expression will look like this:

$.evalFile("~/Desktop/myFunctions.txt");

getThingamabob(2, 'yes')

Cheers,

François

October 9, 2017

Yes, that should be easily doable:

You just create an AEGP C++ plugin file that creates a command ID and a command hook, something like this:

    ERR(suites.CommandSuite1()->AEGP_GetUniqueCommand(&S_Commando_cmd));

    ERR(suites.CommandSuite1()->AEGP_InsertMenuCommand(S_Commando_cmd, sPluginName.c_str(), iMenu, iMenuPosition));

    ERR(suites.RegisterSuite5()->AEGP_RegisterCommandHook(aegp_plugin_id, AEGP_HP_BeforeAE, AEGP_Command_ALL, CommandHook, 0));

    ERR(suites.RegisterSuite5()->AEGP_RegisterDeathHook(aegp_plugin_id, DeathHook,    NULL));

    ERR(suites.RegisterSuite5()->AEGP_RegisterUpdateMenuHook(aegp_plugin_id, UpdateMenuHook, NULL));

    ERR(suites.RegisterSuite5()->AEGP_RegisterIdleHook(aegp_plugin_id, IdleHook, NULL));

You can then call your custom commands globally from the AE scripting engine by either searching for the name using app.findMenuCommandId() or by directly calling it with app.executeCommand().

Transferring parameters is also possible, at least I managed to get this working some years ago

françois leroy
Inspiring
October 9, 2017

Hi Toby,

Do you mean expressions can call commands just like scripts? It's very interesting! :-)

How do you actually do that?

Cheers,

François

October 9, 2017

Aaaaaah, I think I understand now. I am sorry but I think I misread the original question. I was under the assumption of wanting to call plugin code from the scripting side, not from the expression side. Ok, in that case, forget my answer

Participant
October 3, 2017

Dang, that's a shame. Looks like I'll have to find some way to work around it.

Community Expert
September 30, 2017

to the best of my knowledge, it's not possible.

perhaps ZacLam​ would know better.