Copy link to clipboard
Copied
I have an issue with a script I’m trying to develop. I’m using a third party app that allows the client to update tables, I import their changes into Indesign and then charts will get updated based on the updated tables. I have tried some event listeners to see what I would get. When I import the updates from the client an afterPlace is fired for each table that gets updated, also an afterImport would do the same. My issue is that I have no way of knowing when there are no more imports coming so I can begin the next part of the script, is there anything I can do?
Thank you
Alex
Hi @Alex25077296wbvx , You should be able to do it by adding an idleTask, which takes a sleep parameter. You could set any amount of sleep time for it to trigger after the afterPlace event.
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#IdleTask.html
Copy link to clipboard
Copied
If I understand your situation correctly, then InDesign script functions won't help you here. You need to address this at your workflow management level. To have some kind of marker/event that indicates that no more imports are coming etc.
Copy link to clipboard
Copied
Hi @Alex25077296wbvx , You should be able to do it by adding an idleTask, which takes a sleep parameter. You could set any amount of sleep time for it to trigger after the afterPlace event.
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#IdleTask.html
Copy link to clipboard
Copied
Here’s an example
#targetengine "placedone"
//add an afterplace listener
app.eventListeners.add("afterPlace", addIdle);
var iTask;
var pc = false;
/**
* Add an idletask after the first place with a 2 sec sleep delay, adjust as needed
* @ param e the afterPlace event
*/
function addIdle(e){
if (!pc) {
//make an idletask event with a 2 sec delay
iTask = makeIdleTask("waitPlace", 2000);
iTask.addEventListener(IdleEvent.ON_IDLE, placeDone);
pc = true
}
}
/**
* Alert 2 sec after last place and remove listeners
* @ param e idle event
*/
function placeDone(e){
alert("Place Done")
//remove listeners
app.removeEventListener("afterPlace", addIdle);
app.idleTasks.itemByName("waitPlace").remove();
}
/**
* Makes a new named idleTask
* @ param the task name
* @ param the sleep time
* @ return the named idleTask
*/
function makeIdleTask(n, s){
if (app.idleTasks.itemByName(n).isValid) {
return app.idleTasks.itemByName(n);
} else {
return app.idleTasks.add({name:n, sleep:s});
}
}
Copy link to clipboard
Copied
This is a great suggestion I will give it a go. Thank you and thanks for all the suggestions this has been very helpful
Alex
Copy link to clipboard
Copied
Hi Rob, can I just say first off you are on another level of genius! This is what I’m looking for. Sorry to bother you with my ignorance but could I just ask a questions. When does the 2 seconds start, if say there was loads of imports and they took say 10 seconds to load would the 2 seconds start after the last one was loaded or after the first one was loaded? I was thinking if it was after the first one then could I introduce a beforePlace to delete the wait then it would be reset in the afterPlace so the 2 seconds would only start after the last item was placed? Am I over thinking this?
Copy link to clipboard
Copied
When does the 2 seconds start,
Unless you know the number of items that are being placed it has to happen on the first afterPlace event.
You only want 1 idleTask listener so the pc false boolean creates it on the first afterPlace event. Unless you are placing very large assets, the sleep time would not have to be very long.
Copy link to clipboard
Copied
Also, you will have to experiment, but the application wouldn't be idle during the place operations, so in your case the sleep time might be the total idle time after the last place?
Copy link to clipboard
Copied
Thank you for all your help that has been very useful
All the best
Alex
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi, The reason is that I’m not allowed to get stuff from the 3rd party software that we use which is, of course, a point of much annoyance to me as that would have made the process so much easier in ways that have already been mentioned on this feed. So I only have what’s happening in Indesign to work with. I don’t know how many items will have been updated so I can’t tell how many times the afterPlace is going to be triggered and I can only continue with the script once all the items have been placed.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
FWIW, I ran a loop that places a bunch of very hi res images with a timer at the end of the loop and one when the idle task is complete, and while the images are being placed the application is active, so the idleTask sleep time does not include the time it takes to place the asset—2 secs would probably be more than you need.
Copy link to clipboard
Copied
Thank you for that and all your help. I will use your method
Alex
Copy link to clipboard
Copied
If you import changes - then you should be able to know which table has been updated?