Get Returned text from ScriptManager(javascript) - INDESIGN SDK Plugin

654 views Asked by At

I am using javascript inside my Plugin for Indesign CS6.

It is working fine.

But I need the return value from my javascript code now inside my c++ code.

I am using this site as reference:

https://blogs.adobe.com/indesignsdk/running-a-script-from-an-indesign- plug-in/

I need something like that:

scriptRunner->RunScript("function xpto(){return 'Hello World';};xpto()", params);

// fake method

const char *string_return = scriptRunner->getReturnCode();

are there something like that on scriptManager?

ps: it is not a indesign server. I put this tag because this site do not let me create a new tag...

Best Regards,

2

There are 2 answers

1
Dirk On

Use RunScriptParams::QueryScriptRequestData() .

From the SDK documents:

Query the IScriptRequestData that is used to pass arguments and return the result.

1
Leigh Warren On

The key is to get the iScript object from the 'RunScriptParams' object after the script has run. Then is it straight forward. Here is some sample code:

RunScriptParams params(scriptRunner);
IScriptRequestData* requestData = params.QueryScriptRequestData();
params.SetUndoMode(RunScriptParams::kFastUndoEntireScript);

if (scriptRunner->RunScript(script,params) != kSuccess) return NULL;

IScript *iScript = params.QueryTarget();
int resultsCount = requestData->GetNumReturnData(iScript);
PMString resultString;
if (resultsCount > 0) {
    ScriptReturnData resultOne = requestData->GetNthReturnData(iScript,0);
    ScriptData scriptReturnOne = resultOne.GetReturnValue();


    scriptReturnOne.GetPMString(resultString);
}

The return value is in resultString.