Copy link to clipboard
Copied
I have a script that looks like
//some codes
function fun(){
return "something";
}
function t(){
return 3;
}
fun();
t();
and then I run the script inside plugin. and get the return. but I can get last return value only.
PMString path("path\to\jsx\file");
IDFile tmp;
FileUtils::PMStringToIDFile(path, tmp);
const IDFile file(tmp);
if(FileUtils::DoesFileExist(file))
CAlert::InformationAlert("eeee");
IScriptRunner* script_runner = Utils<IScriptUtils>()->QueryScriptRunner(file);
if(!script_runner)
break;
RunScriptParams parms(script_runner);
if(!script_runner->CanHandleFile(file))
break;
if(kSuccess == script_runner->RunFile(file, parms))
CAlert::InformationAlert("success");
else
break;
IScript* iS = parms.QueryTarget();
if(!iS)
break;
int t = parms.QueryScriptRequestData()->GetNumReturnData(iS);
PMString str;
for(int i = 0; i < t; i++){
int32* k = new int32(2);
int16* k16 = new int16(2);
int64* k64 = new int64(2);
if(!parms.QueryScriptRequestData())
continue;
if(kSuccess == parms.QueryScriptRequestData()->GetNthReturnData(iS, i).GetReturnValue().GetInt32(k))
{
PMString p;
p.AsNumber(*k);
CAlert::InformationAlert(p);
}
else if(kSuccess == parms.QueryScriptRequestData()->GetNthReturnData(iS, i).GetReturnValue().GetInt16(k16))
{
PMString p;
p.AsNumber(*k16);
}
else if(kSuccess == parms.QueryScriptRequestData()->GetNthReturnData(iS, i).GetReturnValue().GetInt64(k64))
{
PMString p;
p.AsNumber(*k64);
CAlert::InformationAlert(p);
}
else if(kSuccess == parms.QueryScriptRequestData()->GetNthReturnData(iS, i).GetReturnValue().GetPMString(str))
{
CAlert::InformationAlert(str);
}
else
CAlert::InformationAlert("no data");
}
Is there a way to get that both returned data.
Copy link to clipboard
Copied
vinothr
Manan Joshi
any idea please?
Copy link to clipboard
Copied
Hi ddarz4u,
As pointed by Markus this should return only a single value and that is the last one. I have never tried to achieve this, but thinking over it, i see this is not feasible at all. Imagine it this way that you might have many function calls in your script that returned some value and if all of it is appended to the return data, imagine the load on the script engine. Every other api that exists returns something which in most cases is ignored by us.
Even running your script on Extendscript would show you just 3 as the result.
On another note what do you want to achieve by getting multiple return values, an alternate workflow can surely be thought of. Let us know if we can help in giving you suggestions on some alternate workflows to achieve what you wanna do.
-Manan
Copy link to clipboard
Copied
Hi ddarz4u,
a script call is like a function call and returns one value only, i.e. the last used value. In your case it is the return value from t().
Markus
Copy link to clipboard
Copied
ScriptRequestData can have multiple results for cases where you address multiple objects.
E.g. the Javascript "app.documents.everyItem().name" first does a kGetObjectRequest that returns a single array object (script list) with my three open documents. Those three documents are then used as three targets for one following kGetPropertyRequest, producing three return data values - the three document names.
So if you run my script of above, you might encounter multiple return values, but I doubt that because the JS engine will likely turn them into an array before it returns them to the plugin (not tried).
Anyway, to return the multiple values from your script, use the same trick and return them as array. You'll receive a ScriptList where you can extract the entries.