Skip to main content
Inspiring
October 17, 2022
Question

list open and update group of link and note single link

  • October 17, 2022
  • 1 reply
  • 1091 views

hi with this function

 

function OpenAndUpdate(doc){
	app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
    //$.writeln("ouverture d'un sous lien : " +  doc);
	internal_link = doc.links;
	var nb_link = 0;
	try {
  		nb_link = internal_link.length;
	} catch (error) {}
    //$.writeln(internal_link);
    //$.writeln("nombre de liens dans ce fichier : " + internal_link.length + "nombre de link : " + nb_link ) //+ internal_link[k]);
	if (nb_link > 0) {
			doc.links.everyItem().update();
			doc.save();
	    for(var k = 0; k < nb_link; k++){
			internal_link = doc.links;
			if (k > 0){
			internal_link[k].update();
			}
		    // On vérifie que le lien est OK :
		    if (internal_link[k].status == LinkStatus.LINK_MISSING){
			    var folderPath = (Folder.selectDialog(internal_link[k].filePath));
			    var imglist = Folder(folderPath).getFiles(internal_link[k].name+".*");
			    if (imglist.length == 1){
				internal_link[k].relink(imglist[0]);
			    }

		    }
		    // Si le lien est ok. On l'ouvre pour vérifier ses propres lien. La recursivité a lieu ici:
		    //$.writeln("Lien numéro " + k + " : type de fichier " + internal_link[k].linkType + " alors que seul les indd sont mis à jour");
		    if (internal_link[k].linkType == 'InDesign Format Name') { // Je ne veux ouvrir que les fichier indd
                //$.writeln("ouverture d'un sous lien. entrée dans une boucle récursive");
				newdoc = app.open(internal_link[k].filePath);
			    OpenAndUpdate(newdoc) // pas sur. peut etre Filepath à la place de File. cf la doc: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Link.html
			}
		}
	}
	if(doc.links.length > 0)
	{
		app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
		doc.links.everyItem().update();
		doc.close (SaveOptions.YES);
	}
	else{
		doc.close();
	}
    return 0; // fin de la fonction. Elle ne renvoie rien normalement
	alert("merci")
};

 

we open with recursion all link inside a file

 

but i have so much link into my source file, arround 130 link divide into only 9 different files

 

if i open and update the group of link and not the only the single link, i will save my time per 10

 

i attached 2 picture for show you

 

i need to update 70 principal indd file, each file contain 130link divide in 9 files, each file contain again lot of link....

 

 

thanks for your help

 

i give an idea, but if it s too complicate to find the "group of link file"

mauybe we can write the path file into a csv, and before open a new link, we read the csv, if path file exist we not open, if not exist we can open?

 

i give idea but i m not able to write script for that

This topic has been closed for replies.

1 reply

Loic.Aigon
Legend
October 17, 2022

There is no such thing as a links group in the InDesign DOM. I think that from the UI perspective, it's just a commodity. So basically, you have to update all Link instances.

Inspiring
October 17, 2022

i feel update all link will take several day, it s not really possible

 

maybe my second solution is possible?

for each open link will read a pathfile memory, if it is empty, we note the pathfile in it. if the pathfile already exists, can't we open the file a second time? What do you think?

Loic.Aigon
Legend
October 17, 2022

we have do that 

var updated_list = []; // SIMON1710 initialisation d'une liste vide de fichier déjà mis à jour

var defaultFolder = "/M/infographie/Dossier Phykidis/base de donnée produit/pkd"
//var topFolder = Folder(defaultFolder).selectDlg("Select the top level folder.");
function findAll (f, flist) 
{
    var f = Folder(f).getFiles("*.*");
    for (var i = 0; i < f.length; i++) 
    {
        if (f[i] instanceof Folder && f[i].name[0] != ".") 
            findAll (f[i], flist);
        else 
        {
            if(f[i].displayName == "étiquette finie.indd")
                flist.push(f[i])
        }
    }
}

var myFolder = Folder(defaultFolder).selectDlg("Select the folder containing InDesign Files");
//var myFolder = Folder.selectDialog("Select the folder containing InDesign Files", "");
if (!myFolder) exit();

var f = []
findAll(myFolder, f)
var doc;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
//Opens each ID file and runs the 
for (var i = 0; i < f.length; i++){
    doc = app.open(File(f[i]));
    // doc.links.everyItem().update(); // déjà fait dans le la fonction OpenAndUpdate(doc)
    OpenAndUpdate(doc);
}; 


/**
* Updates a document’s links 
* @ param the document to update 
* @ return value 0 
* 
*/
function OpenAndUpdate(doc){
	app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
    //$.writeln("ouverture d'un sous lien : " +  doc);
	internal_link = doc.links;
	var nb_link = 0;
	try {
  		nb_link = internal_link.length;
	} catch (error) {}
    //$.writeln(internal_link);
    //$.writeln("nombre de liens dans ce fichier : " + internal_link.length + "nombre de link : " + nb_link ) //+ internal_link[k]);
	if (nb_link > 0) {
			// doc.links.everyItem().update(); // SIMON1710 : Pour moi c'est non. Il faut mettre à jour APRES que tous les sous documents soient ouvert, maj et fermés. C'est dejà le cas ligne 65. Donc à supprimer 
			// doc.save(); //idem
	    for(var k = 0; k < nb_link; k++){
			// internal_link = doc.links; // SIMON1710 : on les a déjà listé ligne 29. à retirer
			if (k > 0){
			internal_link[k].update();
			}
		    // On vérifie que le lien est OK :
		    if (internal_link[k].status == LinkStatus.LINK_MISSING){
			    var folderPath = (File.openDialog(internal_link[k].filePath));
			    var imglist = Folder(folderPath).getFiles(internal_link[k].name+".*");
			    if (imglist.length == 1){
				internal_link[k].relink(imglist[0]);
			    }
		    }
			else {
					doc.links.everyItem().update();
					doc.save();
			}

		    
		    // Si le lien est ok. On l'ouvre pour vérifier ses propres lien. La recursivité a lieu ici:
		    //$.writeln("Lien numéro " + k + " : type de fichier " + internal_link[k].linkType + " alors que seul les indd sont mis à jour");
		    if (internal_link[k].linkType == 'InDesign Format Name') { // Je ne veux ouvrir que les fichier indd
                //$.writeln("ouverture d'un sous lien. entrée dans une boucle récursive");
				//alert(updated_list);
				if (updated_list.indexOf(internal_link[k].filePath)>0) { // SIMON1710 si updated_list n'inclue PAS le fichier internal_link[k].filePath (le PAS c'est le ! devant le updated_list)
					newdoc = app.open(internal_link[k].filePath);
			   		OpenAndUpdate(newdoc) // pas sur. peut etre Filepath à la place de File. cf la doc: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Link.html
					updated_list.push(internal_link[k].filePath); // SIMON1710 J'ajoute le fichier à mettre à jour dans la liste des fichiers déjà mis à jour
				}
			}
		}
	}
	if(doc.links.length > 0)
	{
		app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
		doc.links.everyItem().update();
		doc.close (SaveOptions.YES);
	}
	else{
		doc.close();
	}
    return 0; // fin de la fonction. Elle ne renvoie rien normalement
};

 

 

but error is updatelist.indexOf() is not a function, we have try with include it s same


It might be the last time I get into this because you really need to take a step back and think about what you are doing. Keeping track of processed files is good but you are applying incorrectly. I told you I used an object, because objects have properties (here the link filePath) that the script can easily access at any time.

If you do use an array, why not, but you loose all the interest as you will have to loop through your array every time.

At last, you are not just writing InDesign Script, you are coding in Javascript as well and Javascript although quite permissive has some rules you need to follow such as trying to understand the objects you are manipulating. Your updated_list is an Array object. Arrays have methods and indexOf is not one of Array's. indexOf is a String utility.

Because or thanks to Javascript nature, you need to think about what you are doing and besides, Google is a friend regarding those quite explicit issues (once again javascript related, not InDesign).