[GastForen Programmierung/Entwicklung JavaScript Search and Replace of Path Links in InDesign as a Batch Job

  • Suche
  • Hilfe
  • Lesezeichen
  • Benutzerliste
Themen
Beiträge
Moderatoren
Letzter Beitrag

Search and Replace of Path Links in InDesign as a Batch Job

Gerald Hemetsberger
Beiträge gesamt: 3

18. Apr 2020, 00:49
Beitrag # 1 von 4
Bewertung:
(6073 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Code
/*  
SearchReplaceLinkPaths.jsx

With the help of this time saving script, you can replace the paths of all linked objects with new ones.
This function is especially helpful if you use an existing InDesign project as a template for a new project, copy it to a new directory,
but the paths for InDesign will not change, relatively.

Tip: In this case, simply rename the old path to the linked objects after copying
so that InDesign does not mistakenly continue to use the old objects. You will then get the warnings in the link panels, instead.

The linked objects can even be located in any nested subdirectories.

The script UI: A dialogue box shows up in the sense of "Search and Replace". You search for and enter the text expression that is to change in all paths, equally.
Note: The paths will only be replaced if the files do actually exist in the new directories.
Paths that do not match the search-replace condition remain unaffected.

Example 1:
Original Path, search for:
"B:\5.3_Cornerstone\Release_7.1"
New Path, replace with:
"D:\2.1.2_Cornerstone\Release_7.2"

Example 2:
Original Path:
"B:\5.3_Cornerstone\Release_7.1\Media..."
New Path:
"B:\5.3_Cornerstone\Release_7.2\Media..."
Search for: "7.1"
Replace by: "7.2"

And: I am not a programmer.
The only thing that annoys me is the poor comfort with the cumbersome handling of file paths in InDesign's Link Panel, as 1000 others on the Internet have been complaining for years.

Feedback and improvements are very welcome!
*/

// the following 4 lines declare variables
// usually I declare all vars at the beginning of the function
// when you declare a variable with var, you limit its scope to the function
// (making them local),
// otherwise the scope is global which may cause you problems
// a rule-of-thumb is to use global vars only you really need them

var i, link, newFile, AbsolutePath;
var NumMatches = 0; // counter of how many file paths actually were found that match the replacement condition
var NumUpdates = 0; // counter of how many files paths were actually updated
var NumOpen = 0; // number of files that still do not exist in the new directories

doc = app.activeDocument; // set variable doc to the front most document
links = doc.links; // set variable links to collection of all links

// call the dialoge window
var shownWindow = setConfigWindow();

// Clicked on Ok = true
if(shownWindow.result == true){
// alert ('Ok!');
alert ('Searching for:\t'+shownWindow.StrSearch+'\n'+
'To be replaced by:\t'+shownWindow.StrReplace);

for (i = links.length-1; i >= 0; i--) { // loop through all links backwards
link = links[i]; // set the variable link to the current link

AbsolutePath = link.filePath;


if (AbsolutePath != AbsolutePath.replace(shownWindow.StrSearch,shownWindow.StrReplace)) {

NumMatches = NumMatches+1;
// alert (AbsolutePath+'\n\n'+AbsolutePath.replace(shownWindow.StrSearch,shownWindow.StrReplace));
// create file object:
newFile = new File(AbsolutePath.replace(shownWindow.StrSearch,shownWindow.StrReplace));

if (newFile.exists){
NumUpdates = NumUpdates+1;
link.relink(newFile); // relink only if the file exists

// I use try-catch block to make the script compatible with CS3 and above
// In other words, if an error occurs here, skip it over and go on
try {
link.update();
}
catch(err) {}
}
}

}
NumOpen = NumMatches - NumUpdates;
alert ('Number of cases that matched the replacement condition:\t'+ NumMatches +
'\nNumber of relinked objects:\t\t\t\t' + NumUpdates +
'\nNumber of files missing in new folders:\t\t\t' + NumOpen);

}
// Clicked on Cancel = if false
else {
alert ('The action was canceled');
}


// provides dialog box as a function
function setConfigWindow() {

// Create dialog box
var configWindow = new Window('dialog','Updating Paths for Linked Objects');


// Adding a display column (siehe auch Adobe JavaScript Tools Guide)
configWindow.column01 = configWindow.add ('group {orientation: "column"}');

// Add framing with "Title"
configWindow.column01.gridPanel = configWindow.column01.add ('panel', undefined,
'Differentiating strings as part of the absolute paths');

// Do the following with the "inside" of the frame...
with(configWindow.column01.gridPanel){

// Set "orientation" of the "frame" to the left
aligment = 'left';

// Add display group for 1st input
var SearchGroup = add('group');

// Add "input label" (statictext) & input field (edittext)
SearchGroup.add('statictext', [0,0,80,15], 'Search for:');
var SearchInputField = SearchGroup.add('edittext', [0,0,150,24], 'A:\\');

// Add display group for 2nd input
var ReplaceGroup = add('group');

// Add "input label" (statictext) & input field (edittext)
ReplaceGroup.add('statictext', [0,0,80,15], 'Replace with:');
var ReplaceInputField = ReplaceGroup.add('edittext', [0,0,150,24], 'B:\\');

}

// Add buttons in the "Display column" but outside the "Frame"
configWindow.column01.btnGrp = configWindow.add('group');
configWindow.column01.btnGrp.add('button', undefined, 'Ok');
configWindow.column01.btnGrp.add('button', undefined, 'Cancel');

// View windows in Adobe InDesign
var usrAction = configWindow.show();

// Return three objects
return {
result: usrAction,
StrSearch: SearchInputField.text,
StrReplace: ReplaceInputField.text

}
}

X

Search and Replace of Path Links in InDesign as a Batch Job

Thomas Richard
  
Beiträge gesamt: 18430

18. Apr 2020, 08:37
Beitrag # 2 von 4
Beitrag ID: #574961
Bewertung:
(6052 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Erinnert mich doch stark an das Script von Kaysan Servetsky: https://indesignsecrets.com/...ipt-help/#post-60792


MfG

Thomas


Und wenn dir geholfen wurde, hilf uns, dies auch weiterhin zu können.
http://www.hilfdirselbst.ch/info/


als Antwort auf: [#574960]

Search and Replace of Path Links in InDesign as a Batch Job

Gerald Hemetsberger
Beiträge gesamt: 3

19. Apr 2020, 18:46
Beitrag # 3 von 4
Beitrag ID: #574967
Bewertung:
(5957 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
I am glad that I found the script from Kaysan Servetsky and could use it as a template. I am not a programmer but a merger. The problem I want to solve is different. I will explain this here briefly.

The strength of Kaysan Servetsky's template is that it can distinguish and select between different file types when relinking graphics. This is not really possible with my script.

The problem that I want to solve more easily is much better described in the description of:
https://community.adobe.com/t5/indesign/simple-link-path-find-replace-script/td-p/9987618?page=1

What's this about? I am faced with a finished InDesign document that has its linked assets in a highly branched directory structure. The focus of this directory structure is not on the possible file types. Rather, it's about thematic structure, such as corporate or project-related, different drives or interfaces to other teams. I have a brochure with 12 pages and about 130 linked assets. And now there is an update. So copy and paste the whole structure. On a node further up in the directory structure there will be a small update. And this task can be solved better if you can search and replace certain expressions in link paths.

Here's another script that allows me to quickly display all current link paths alphabetically, 50 per page. I find it quite useful, but please don't expect any praiseworthy programming skills from me.


als Antwort auf: [#574961]

Search and Replace of Path Links in InDesign as a Batch Job

Gerald Hemetsberger
Beiträge gesamt: 3

19. Apr 2020, 18:49
Beitrag # 4 von 4
Beitrag ID: #574968
Bewertung:
(5949 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
/* myShowAllLinkPaths.jsx

Lists alphabetically all link paths of the active document regardless of whether the files exist or not

*/
var i, k

var doc = app.activeDocument; // set variable doc to the front most document
var links = doc.links; // set variable links to collection of all links

var showList = new Array();
var DisplayList = new Array();

for (i = links.length-1; i >= 0; i--) {
showList[i] =links[i].filePath;
};


showList.sort();

for (k=0;k<=links.length/50;k++){

for (i=0;i<50;i++){

var count = k*50+i+1;

if (count <= links.length) {

DisplayList [i]= leftPad(count,3) + '\t'+ showList [count-1] ;

}
else {
DisplayList [i] = "";
}

};

alert (DisplayList.join('\n'),'Link Paths List');
// alert(print_r(DisplayList));
}


function leftPad(number, targetLength) {
var output = number + '';
while (output.length < targetLength) {
output = '0' + output;
}
return output;
}


// alternative to display:

function print_r(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += " ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
for(var item in arr) {
var value = arr[item];

if(typeof(value) == 'object') { //If it is an array,
dumped_text += level_padding + "'" + item + "' ...\n";
dumped_text += print_r(value,level+1);
} else {
dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
}
}
} else { //Stings/Chars/Numbers etc.
dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
}


als Antwort auf: [#574967]
X

Aktuell

Diverses
03_FM_Stilvorlagen_300x300

Veranstaltungskalender

Hier können Sie Ihre Anlässe eintragen, welche einen Zusammenhang mit den Angeboten von HilfDirSelbst.ch wie z.B. Adobe InDesign, Photoshop, Illustrator, PDF, Pitstop, Affinity, Marketing, SEO, Büro- und Rechtsthemen etc. haben. Die Einträge werden moderiert freigeschaltet. Dies wird werktags üblicherweise innert 24 Stunden erfolgen.

pdf-icon Hier eine kleine Anleitung hinsichtlich Bedeutung der auszufüllenden Formularfelder.

Veranstaltungen
02.06.2020 - 03.06.2020

Digicomp Academy AG, Limmatstrasse 50, 8005 Zürich
Dienstag, 02. Juni 2020, 08.30 Uhr - Mittwoch, 03. Juni 2020, 17.00 Uhr

Kurs

Dieser Basic-Kurs ist der perfekte Einstieg in die Welt von InDesign, dem vielseitigen Layout-Programm. Sie lernen, wie InDesign aufgebaut ist, wie saubere Dokumente erstellt werden und wie man korrekt mit gelieferten InDesign-Projekten umgeht.

Preis: CHF 1'400.–
Dauer: 2 Tage

Nein

Organisator: Digicomp Academy AG

Kontaktinformation: Isil Günalp, E-Mailisil.guenalp AT digicomp DOT ch

https://www.digicomp.ch/weiterbildung/software-anwendungs-trainings/adobe-trainings/desktop-publishing/adobe-indesign-cc/kurs-indesign-cc-basic

Veranstaltungen
02.06.2020 - 03.06.2020

Digicomp Academy AG, virtuell
Dienstag, 02. Juni 2020, 08.30 Uhr - Mittwoch, 03. Juni 2020, 17.00 Uhr

Kurs

Dieser Basic-Kurs ist der perfekte Einstieg in die Welt von InDesign, dem vielseitigen Layout-Programm. Sie lernen, wie InDesign aufgebaut ist, wie saubere Dokumente erstellt werden und wie man korrekt mit gelieferten InDesign-Projekten umgeht.

Preis: CHF 1'400.–
Dauer: 2 Tage

Nein

Organisator: Digicomp Academy AG

Kontaktinformation: Isil Günalp, E-Mailisil.guenalp AT digicomp DOT ch

https://www.digicomp.ch/weiterbildung/software-anwendungs-trainings/adobe-trainings/desktop-publishing/adobe-indesign-cc/kurs-indesign-cc-basic

Neuste Foreneinträge


bedingter Text � Bedingung inkl. Inhalten laden

QXP 2019: dead keys �ffnen Miniaturansicht unten am Dokumentfenster

Grepstil-Problem mit Positiven Lookahead

Meine QuarkXPress-Account Management Webseite kennt mich nicht mehr

zwei Seiten vertauschen

Dateien kopieren

EPS mit Konvertierungsoptionen

Grobes ICC-Profil aus wenigen gemessenen Farben

PDF (Speisekarte) auf Android-Tablet anzeigen, Adobe Reader im Kiosk-Modus m�glich?

Ausschneiden und automatisch Hintergrund ersetzen
medienjobs