• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Listen for imports in Indesign

Explorer ,
Sep 25, 2024 Sep 25, 2024

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

TOPICS
Scripting

Views

242

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 25, 2024 Sep 25, 2024

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

Votes

Translate

Translate
Community Expert ,
Sep 25, 2024 Sep 25, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2024 Sep 25, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2024 Sep 25, 2024

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});
    }
}


 

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 26, 2024 Sep 26, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 26, 2024 Sep 26, 2024

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

Thank you for all your help that has been very useful

All the best

Alex

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

@Alex25077296wbvx

 

May I ask why do you need workarounds? 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 26, 2024 Sep 26, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

@Alex25077296wbvx

 

How exactly this 3rd party software works? 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 26, 2024 Sep 26, 2024

Copy link to clipboard

Copied

LATEST

Thank you for that and all your help. I will use your method

Alex

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2024 Sep 25, 2024

Copy link to clipboard

Copied

@Alex25077296wbvx

 

If you import changes - then you should be able to know which table has been updated?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines