The only way you can make a script wait is to use 'sleep'. What you need to do is have bridge talk sat in a while loop waiting for a response from your illustrator script. Have illustrator return a value after it has done. Also I think in this case you would be better served by using toSource() & having illustrator do eval() at the other end of the bt message body (both these methods are over my head at the minute but heres a sample by someone else that may help you with some of the syntax with waiting and timing out)
function GetFilesFromBridge() {
var fileList;
if ( BridgeTalk.isRunning( "bridge" ) ) {
var bt = new BridgeTalk();
bt.target = "bridge";
bt.body = "var theFiles = photoshop.getBridgeFileListForAutomateCommand();theFiles.toSource();";
bt.onResult = function( inBT ) { fileList = eval( inBT.body ); }
bt.onError = function( inBT ) { fileList = new Array(); }
bt.send();
bt.pump();
$.sleep( 100 );
var timeOutAt = ( new Date() ).getTime() + 5000;
var currentTime = ( new Date() ).getTime();
while ( ( currentTime < timeOutAt ) && ( undefined == fileList ) ) {
bt.pump();
$.sleep( 100 );
currentTime = ( new Date() ).getTime();
}
}
if ( undefined == fileList ) {
fileList = new Array();
}
return fileList;
}
the target that you want to test 'is running' here is 'illustrator' no point in sending a message if its not
if ( BridgeTalk.isRunning( "illustrator" ) ) {
}
Hi pvisell,
I think you overcomplicated things in the script you posted.
Here is my implementation of what I suggested in post #2.
The key points are:
1. Define an empty onResult function
bt.onResult = function(resObj) {}
2. provide a timeout value for send method as Bob advised (and I forgot to mention in my previous post)
bt.send(30);
I don't know why we should do both of these things — I found this out by experimenting.
Interapplication communication with scripts is explained very obscurely in documentation, so it's hard to understand. But once you sorted it out — it's easy. I would never understood this on my own, if Bob hadn't helped me. Thanks Bob a lot for this!!!
Kasyan
//-----------------------------------------
#target indesign
var myXmlPath = "/c/Test/Capella Gross Sector Exposure.xml";
var mySetName = "Capella";
var myDoc = app.activeDocument;
ProcessLinks();
UpdateLinks()
alert("Done");
// ------------------------- FUNCTIONS -------------------------
function ProcessLinks() {
for (var j = 0; j < myDoc.links.length; j++) {
var myLink = myDoc.links;
CreateBridgeTalkMessage(myLink.filePath, myXmlPath, mySetName);
}
}
function CreateBridgeTalkMessage(myAiPath, myXmlPath, mySetName) {
var bt = new BridgeTalk();
bt.target = "illustrator";
var myScript = UpdateDataset.toString() + '\r';
myScript += 'UpdateDataset(\"' + myAiPath + '\", \"' + myXmlPath + '\", \"' + mySetName + '\");';
bt.body = myScript;
bt.onResult = function(resObj) {}
bt.send(30);
}
function UpdateDataset(myAiPath, myXmlPath, mySetName) {
var myAiFile = new File(myAiPath);
var myDoc = app.open(myAiFile);
var myXmlFile = new File(myXmlPath);
if (myXmlFile.exists) {
myDoc.importVariables(myXmlFile);
myDoc.activeDataset = myDoc.dataSets.getByName(mySetName);
myDoc.activeDataset.display();
myDoc.close(SaveOptions.SAVECHANGES);
}
}
function UpdateLinks() {
for (var i = myDoc.links.length-1; i >= 0; i--) {
if (myDoc.links.status == LinkStatus.linkOutOfDate) {
myDoc.links.update();
}
}
}