DispatchScriptRunner()
How to pass Java script parameters into DispatchScriptRunner() Function.
Tried Code:
WideString scriptPath("InDesign\\CS5\\scripting\\indesign\\samplescripts\\JavaScript\\AddGuides.jsx" );
IDFile scriptFile(scriptPath);
InterfacePtr<IScriptRunner>scriptRunner(Utils<IScriptUtils>()->QueryScriptRunner(scr iptFile));
if(scriptRunner)
ScriptRecordData arguments;
ScriptIDValuePair arg;
ScriptID aID;
ScriptData script(scriptFile);
ScriptData resultData;
PMString errorString;
//To add pair into KeyValuePair
KeyValuePair<ScriptID,ScriptData> ScriptIDValuePair(aID,script);
arguments.push_back(ScriptIDValuePair);
int length=arguments.size();
PMString str;
str.AppendNumber(length);
//CAlert::InformationAlert(str);
Utils<IScriptUtils>()->DispatchScriptRunner(scriptRunner,script,arguments,resultData,erro rString,kFalse);
Value of ScriptId is cuming null or (0);
Please provide a solution to get a scriptId
Qn 2. How to pass a particular Java script methd's parameters into DispatchScriptRunner() Function in c++ code.
IScriptArgs is aggregated on the Utils boss, so you would use it as follows:
In your C++ code:
Utils<IScriptArgs>()->Save(); // Saves the current set of scripting parameters on the context stack and creates a new current context, that has no parameters set.
// Now set up the parameters that you want to access from within your JavaScript as key-value pairs
Utils<IScriptArgs>()->Set(PMString("paramkeyname1"),PMString("ParamValueAsString1") );
Utils<IScriptArgs>()->Set(PMString("paramkeyname2"),PMString("ParamValueAsString2") );
// Call your script
Utils<IScriptArgs>()->Restore(); // Replaces the current existing context with the top context on the stack of saved contexts. In other words, returns the parameter stack to the Save() position.
In your JavaScript code:
if(app.scriptArgs.isDefined("paramkeyname1")) {
var yourvalueStr = app.scriptArgs.get("paramkeyname1")
HTH
Similar Messages
-
How to get a value from JavaScript
How to get return value from Java Script and catch it in c++ code. I have tried following code, but its not working in my case.
what I want is if it returns true then call some function if it returns false then do nothing, so how to get those values in c++
ScriptData::ScriptDataType fDataType = resultData.GetType();
if (fDataType == kTrue)
CAlert::InformationAlert("sucess");
//call some function
else
CAlert::InformationAlert("Error");
// do nothing
JavaScript Code:
if(app.scriptArgs.isDefined("paramkeyname1"))
var value = app.scriptArgs.get("paramkeyname1");
alert(value);
return true;
else
alert ("SORRY");
return false;How to get java script result into JSResult i m not getting it.
I have wriiten follwing code in c++ :
WideString scriptPath("\\InDesign\\Source1.jsx");
IDFile scriptFile(scriptPath);
InterfacePtr<IScriptRunner>scriptRunner(Utils<IScriptUtils>()->QueryScriptRunner(scriptFi le));
if(scriptRunner)
ScriptRecordData arguments;
ScriptIDValuePair arg;
ScriptID aID;
ScriptData script(scriptFile);
ScriptData resultData;
PMString errorString;
KeyValuePair<ScriptID,ScriptData> ScriptIDValuePair(aID,script);
arguments.push_back(ScriptIDValuePair);
PMString paramkeyname1;
Utils<IScriptArgs>()->Save();
Utils<IScriptArgs>()->Set("paramkeyname1",scriptPath);
Utils<IScriptUtils>()->DispatchScriptRunner(scriptRunner,script,arguments,resultData,erro rString,kFalse);
Utils<IScriptArgs>()->Restore();
ScriptData::ScriptDataType fDataType = resultData.GetType(); // here i should get true or false which i m passing it from javascript code......not as s_boolean
if (fDataType == kTrue)
//CAlert::InformationAlert("sucess");
iOrigActionComponent->DoAction(ac, actionID, mousePoint, widget);
else
this->PreProcess(PMString(kCstAFltAboutBoxStringKey));
Java script code:
function main()
var scrpt_var;
var scriptPath,scrptMsg;
var frntDoc=app.documents[0];
if(app.scriptArgs.isDefined("paramkeyname1"))
var value = app.scriptArgs.get("paramkeyname1");
alert(value);
return true; // i want this value i should get in c++ code...How to get these values in c++
else
alert ("Error");
return false; // i want this value i should get in c++ code...How to get these values in c++ -
Launch javascript function from a C++ plug-in
Hello,
I succeed to launch a javascript file from my c++ code but I would like to directly go to a specific function.
I used IScriptUtils to get a result data
WideString scriptPath("/path/myscript.jsx");
IDFile scriptFile(scriptPath);
InterfacePtr<IScriptRunner>scriptRunner(Utils<IScriptUtils>()->QueryScriptRunner(scriptFile));
if(scriptRunner)
ScriptRecordData arguments;
ScriptID aID;
ScriptData script(scriptFile);
ScriptData resultData;
PMString errorString;
result = Utils<IScriptUtils>()->DispatchScriptRunner(scriptRunner,script,arguments,resultData,errorString,kFalse);
ScriptData::ScriptDataType aType = resultData.GetType();
I would like to know if someone succeeded to launch a javascript function with arguments and with a result.
Regards,
DavidDziękuję Maciej!
I wrote a javascript in a PMString and dispatch it as the main script :
InterfacePtr<IScriptRunner>scriptRunner(Utils<IScriptUtils>()->QueryScriptRunner(scriptFile));
if(scriptRunner)
//Write down a javascript to include the functional script and use the proper function
PMString scriptStr("//@include \"");
scriptStr.Append(scriptPath);
scriptStr.Append("\"\nmain();\nfunction main()\n{\n\treturn ");
scriptStr.Append(myFunctionName);
scriptStr.Append("();\n}");
ScriptRecordData arguments;
ScriptID aID;
ScriptData script(scriptStr);
ScriptData resultData;
PMString errorString;
result = Utils<IScriptUtils>()->DispatchScriptRunner(scriptRunner,script,arguments,resultData,errorString,kFalse);
ScriptData::ScriptDataType aType = resultData.GetType();
Regards,
David Descamps
Maybe you are looking for
-
Check settings combinations to achieve good Optical Flow HDV 50i -ProRes422
Hi Guys RE: Motion 3, HDV 50i, standard ProRes 422, optical flow I'm trying to decide which combination of settings I should choose in order to ensure the highest possible standard of optical flow-treated video for a video clip which just features li
-
WAVE [BAE] files?
Does anyone know what this means? I haven't encountered this before, but now when I bounce wave files (24/44.1) in Logic my partner can't open them with any audio player he has. When I open the files in Peak it says that it's a WAVE [BAE] file and al
-
A couple of years ago I bought Adobe CS3 Web Premium. About six months or so ago, I downloaded Photoshop Elements 6 for the Mac, just to try it out. I decided I didn't really need another photo processing program, so I deleted it after the trial peri
-
Shared Services - Your system already has the instance with name epmsystem1
Hi, I'm installing EPM System 11.1.2.1 in a new development enviropment. I thought I could connect to a previously configured database Shared Services database and configure the new instance to epmsystem1 (the default) but it is complaining with the
-
Prevent Assignment Object to Lease-In Contract
Dear experts. I have the RO (rental unit) that still being attached to an occupancy lease-in contract. Therefore during the period of contract there is not possible to assign this RO to another lease-in contract. Now I'm doing an exercise on creating