Adobe 0046100128056 Scripting Guide - Page 15
short for script arguments
UPC - 718659087562
View all Adobe 0046100128056 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 15 highlights
CHAPTER 2: Scripting Features Using the doScript Method 15 //To send parameters to a script run using app.doScript(), the doScript //statement must not appear inside a function. If it does, the parameters //will not be passed to the script. var myDocument = app.documents.add(); var myPage = myDocument.pages.item(0); var myTextFrame = myPage.textFrames.add(); myTextFrame.geometricBounds = ["72pt", "72pt", "288pt", "288pt"]; myTextFrame.contents = "Example text frame."; var myDestinationPage = myDocument.pages.add(LocationOptions.after, myPage); var myPageIndex = myDestinationPage.name; var myID = myTextFrame.id; var myJavaScript = "var myDestinationPage = arguments[1];\r" ; myJavaScript += "myID = arguments[0];\r"; myJavaScript += "var myX = arguments[2];\r"; myJavaScript += "var myY = arguments[3]\r;" myJavaScript += "var myPageItem = app.documents.item(0).pages.item(0).pageItems.itemByID(myID);\r"; myJavaScript += "myPageItem.duplicate(app.documents.item(0).pages.item(myDestinationPage));\r" //Create an array for the parameters we want to pass to the JavaScript. var myArguments = [myID, myPageIndex, 0, 0]; var myDuplicate = app.doScript(myJavaScript, ScriptLanguage.javascript, myArguments); //myDuplicate now contains a reference to the duplicated text frame. //Change the text in the duplicated text frame. myDuplicate.contents = "Duplicated text frame."; Another way to get values from another script is to use the scriptArgs (short for "script arguments") object of the application. The following script fragment shows how to do this (for the complete script, see DoScriptScriptArgs): var nameA = "ScriptArgumentA"; var nameB = "ScriptArgumentB"; var nAc = nameA + ": "; var nBc = nameB + ": "; //Create a string to be run as a JavaScript. var p1 = "app.scriptArgs.setValue(\"" + nameA + "\", "; var p2 = "\"This is the first script argument value.\");\r"; var p3 = "app.scriptArgs.setValue(\"" + nameB + "\", "; var p4 = "\"This is the second script argument value.\")"; var p5, p6; //Used later. var myJavaScript = p1 + p2 + p3 + p4; var myScriptArgumentA = app.scriptArgs.getValue(nameA); var myScriptArgumentB = app.scriptArgs.getValue(nameB); alert(nameA + ": " + myScriptArgumentA + "\r" + nameB + ": " + myScriptArgumentB); if(File.fs == "Windows") { //Create a string to be run as a VBScript. p1 = "Set myInDesign = CreateObject(\"InDesign.Application.CS5\")\r"; p2 = "myInDesign.ScriptArgs.SetValue \"" + nameA + "\", "; p3 = "\"This is the first script argument value.\"\r"; p4 = "myInDesign.ScriptArgs.SetValue \"" + nameB + "\", "; p5 = "\"This is the second script argument value.\""; var myVBScript = p1 + p2 + p3 + p4 + p5; app.doScript(myVBScript, ScriptLanguage.visualBasic); } else {