File Prompt with AEGP_ExecuteScript
After some advice from Shachar, I've set out to use AEGP_ExecuteScript to trigger a file prompt, for loading a file from within my plugin. After some research from the forum, this is what I've got that should work:
AEGP_SuiteHandler suites(in_data->pica_basicP);
A_Boolean outAvailablePB;
AEGP_MemHandle outResultPH;
AEGP_MemHandle outErrorStringPH;
const char* javascriptCode =
"var fileToOpen = File.openDialog('Select a file to open');\r\n"
"if (fileToOpen) {\r\n"
" app.open(fileToOpen);\r\n"
"}";
ERR(suites.UtilitySuite4()->AEGP_IsScriptingAvailable(&outAvailablePB));
ERR(suites.UtilitySuite4()->AEGP_ExecuteScript(NULL, javascriptCode, true, &outResultPH, &outErrorStringPH));
A_char* result = NULL;
ERR(suites.MemorySuite1()->AEGP_LockMemHandle(outResultPH, reinterpret_cast<void**>(&result)));
ERR(suites.MemorySuite1()->AEGP_FreeMemHandle(outResultPH));
ERR(suites.MemorySuite1()->AEGP_FreeMemHandle(outErrorStringPH));
FILE* file = fopen(result, "r");
if (file) {
... Do Stuff Here...
From my understanding, outResultPH contains the selected filename and it needs to be passed to a char (result) using AEGP_LockMemHandle which I am doing above.
However, it crashes. When I debug, I can see that it crashes on the AEGP_ExecuteScript line.
I've got this in my SmartRender function for now - whether that is the right or wrong place for it isn't the main issue right now. I just want to get it working.
What am I doing wrong?
Thanks,
-Rich
