Custom Expression Functions
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
to the best of my knowledge, it's not possible.
perhaps ZacLam​ would know better.
Copy link to clipboard
Copied
Dang, that's a shame. Looks like I'll have to find some way to work around it.

Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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

Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
It was very promising... Probably too much 🙂
Copy link to clipboard
Copied
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

