Beenden
  • Globale Community
    • Sprache:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

[SCRIPT} Update links in placed InDesign files

Enthusiast ,
Nov 20, 2021 Nov 20, 2021

Hello, there.

I have an InDesign document with lots of indd files placed in.

Those placed indd files have another indd files placed in.

I need to recursively open all (including the nested ones) indd placed files (links) and update the out of date links. I always get stucked in recursive things...

 

Any help?

THEMEN
Skripterstellung
1.3K
Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines

correct answers 1 richtige Antwort

Community Expert , Nov 21, 2021 Nov 21, 2021

Just realized you have to do the updating AFTER you've done the recursive call. You also shouldn't be opening the root doc since it's already open. How's this? 

 

//========================================================================================
//========================================================================================
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

var doc = app.activeDocument;
var f = doc.fullName;
doc.linkedPageItemO
...
Übersetzen
Community Expert ,
Nov 20, 2021 Nov 20, 2021

Just decompose the problem of what you need the recursive function to do, then operate on it at the top level. Something like this: 

 

var openDocAndUpdateLinks = function(docFile) {
    var d = app.open(docFile);
    d.links.everyItem().update();
    var allLinks = d.links.everyItem().getElements();
    for (var i = 0; i < allLinks.length; i++) {
        if (/\.indd$/gi.test(allLinks[i].name)) {
            openDocAndUpdateLinks(File(allLinks[i].filePath));
        }
    }
}

var main = function() {
    var f = File.openDialog("Select root file");
    openDocAndUpdateLinks(f);
}
Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Enthusiast ,
Nov 20, 2021 Nov 20, 2021

Thanks for your quick reply, Brian.

Nothing happens when I run it.

I made some changes, since I need to run it in the opened document, and need to save the linked indd files after the links update. So, I tried this code below in the attached file(s).

 

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

var f = File.openDialog("Select root file");
openDocAndUpdateLinks(f);

function openDocAndUpdateLinks(docFile) {
    var d = app.open(docFile);
    d.links.everyItem().update();
    var allLinks = d.links.everyItem().getElements();
    for (var i = 0; i < allLinks.length; i++) {
        if (/\.indd$/gi.test(allLinks[i].name)) {
            openDocAndUpdateLinks(File(allLinks[i].filePath));
        }
    }
	d.close(SaveOptions.YES);
}

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

 

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
Nov 20, 2021 Nov 20, 2021

Yeah, guess I left out the call to main(), and figured you might need to do other operations like saving after updating. Was just trying to demonstrate what the recursive call looks like. If you're running on an open doc, then your main loop would look a bit different, but you could still pass link.filePath to the recursive call. 

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Enthusiast ,
Nov 21, 2021 Nov 21, 2021

Well, thanks.

I can not make it work. The final result is never a document with all links updated.

My last attempt:

 

//========================================================================================
//========================================================================================
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

var doc = app.activeDocument;
var f = doc.fullName;
doc.linkedPageItemOptions.updateLinkWhileSaving = true;
var nm = File.decode(doc.name);

openDocAndUpdateLinks(f , nm);

doc.links.everyItem().update();

alert("Done." , "Script by LFCorullón");
//========================================================================================
//========================================================================================
function openDocAndUpdateLinks(docFile , nm) {
	var d = app.open(docFile);
	d.linkedPageItemOptions.updateLinkWhileSaving = true;
	d.links.everyItem().update();
	var allLinks = d.links.everyItem().getElements();
	for (var i=allLinks.length-1; i>=0; i--) {
		if (/\.indd$/gi.test(allLinks[i].name)) {
			openDocAndUpdateLinks(File(allLinks[i].filePath));
			}
		}
	d.save();
	if (File.decode(d.name) != nm) d.close(SaveOptions.YES);
	}

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
//========================================================================================
//========================================================================================

 

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
Nov 21, 2021 Nov 21, 2021

Just realized you have to do the updating AFTER you've done the recursive call. You also shouldn't be opening the root doc since it's already open. How's this? 

 

//========================================================================================
//========================================================================================
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

var doc = app.activeDocument;
var f = doc.fullName;
doc.linkedPageItemOptions.updateLinkWhileSaving = true;
var nm = File.decode(doc.name);

openDocAndUpdateLinks(f , nm);

doc.links.everyItem().update();

alert("Done." , "Script by LFCorullón");
//========================================================================================
//========================================================================================
function openDocAndUpdateLinks(docFile , nm) {
    if (File.decode(docFile.name) == nm) {
        var d = app.activeDocument;
    } else {
        var d = app.open(docFile);

    }
	d.linkedPageItemOptions.updateLinkWhileSaving = true;
	var allLinks = d.links.everyItem().getElements();
	for (var i=allLinks.length-1; i>=0; i--) {
        if (/\.indd$/gi.test(allLinks[i].name)) {
			openDocAndUpdateLinks(File(allLinks[i].filePath));
		}
        if (allLinks[i].status == LinkStatus.LINK_OUT_OF_DATE) {
            allLinks[i].update();
        }
	}
    d.save();
    if (File.decode(d.name) != nm) d.close(SaveOptions.YES);
}

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
//========================================================================================
//========================================================================================

 

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Enthusiast ,
Nov 22, 2021 Nov 22, 2021

Wow, Brian, thank you so much for your help!

This is absolutely brilliant. Thanks!!!

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Neu hier ,
Dec 04, 2021 Dec 04, 2021

Brian, I am new to InDesign scripts and using Creative Cloud version. Any scripting resources you recommend for doing batch updates to linked XML data in multiple InDesign files? Not sure if the earlier Javascript toolkit scripting guides work with InDesign CC. Any pointers appreciated.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
Dec 05, 2021 Dec 05, 2021

Yes. The early scripting guides still apply. A nice searchable DOM is available here: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

 

 

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
Dec 06, 2021 Dec 06, 2021
AKTUELL

If you're after XML scripting the best source is 

https://www.amazon.co.uk/InDesign-CS5-Automation-Using-JavaScript/dp/1460915380/ref=sr_1_1?keywords=...

 

It covers CS5, but as Brian mentioned, early scripting guides still apply.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines