crash indesign during a script without reason (all test done)
hi every body, i work since long since long week with your team and my friend, for do my script for open and update specific file into a folder.
before share the full code i explai, the folder container 1000 indd file, we select only 50 for start the update by recursion.
if i give the full folder, it will crash after 1 hour (arround) and at 3/4
if i activate export pdf function, it will not crash exactly same location, but arround
if i desactivate pdf it will crash every time in the same file.
but if i isolate this file, no crash, if i isolate the parent folder, no crash.
i have check the % gpu, cpu, all word finish per pu, all is really ok, arround 12% cpu and 25% memory, 2% graphic processor.
i have do the same job on other coputer same result
all my data are on network, impossible to move it, because all is linked
there is no timer inside the script (i have add one after for test something)
there is a list, where we write each path link, for not re open it, i have try to clear this list during script at the middle.
my original script, does not close the windows while we are in the recursion loop, so the number of windows increases, then decreases, I have a maximum of 5-6 windows open. a friend tried to ensure that only one window is opened at a time. and without doing so, his script did not compare the file to open with those already open before, so it was really long, since it reopened all files in multiple (not at the same time), same result
for resume, it s not a problem:
material
timer (non blocking)
time of script or number of action during a script
export pdf
number of active document
no error message
script continue to turn on, without error and without indesign...
not a file problem, because i rename the file where it crash, now it crash on the next
now i don t know any test i can do... mabe it exist a solution during script, for pause my loop, down indesign, restart indesign, and continue my loop?
or maybe do a multiple folder select, and work the script in 2 time
but how to do a multiple folder select?
now the code
try {
var updated_list = [];
var defaultFolder =
"/M/infographie/Dossier Phykidis/base de donnée produit/pkd";
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" ||
f[i].displayName == "cataloguephykidis - fiche tech.indd" ||
f[i].displayName == "cataloguephykidis.indd"
)
flist.push(f[i]);
}
}
}
var myFolder = Folder(defaultFolder).selectDlg(
"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]));
//chkbox(doc);
//alert(f.length);
OpenAndUpdate(doc);
if (
app.open(File(f[i])).name == "étiquette finie.indd" ||
app.open(File(f[i])).name == "cataloguephykidis.indd"
) {
//exporttopdf(doc);
if (i== f.length/2){
//alert(updated_list.length);
updated_list = [];
}
app.open(File(f[i])).close();
//alert(app.performanceMetric(PerformanceMetricOptions.CPU_TIME));
//alert(app.performanceMetric(PerformanceMetricOptions.OVERALL_SYSTEM_CPU));
//alert(app.performanceMetric(PerformanceMetricOptions.OVERALL_USER_CPU));
}
}
// 2 Opens each ID file and runs the
/* for (var i = 0; i < f.length; i++) {
doc = app.open(File(f[i]));
OpenAndUpdate(doc);
if (
app.open(File(f[i])).name == "étiquette finie.indd" ||
app.open(File(f[i])).name == "cataloguephykidis.indd"
) {
app.open(File(f[i])).close();
}
}
// 3 opens each ID file and runs the
for (var i = 0; i < f.length; i++) {
doc = app.open(File(f[i]));
OpenAndUpdate(doc);
if (
app.open(File(f[i])).name == "étiquette finie.indd" ||
app.open(File(f[i])).name == "cataloguephykidis.indd"
) {
exporttopdf(doc);
app.open(File(f[i])).close();
}
}*/
alert("fini !");
} catch (err) {
alert(err.line + " => " + err.message);
}
/**
* 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();
// doc.save(); //idem
for (var k = 0; k < nb_link; k++) {
// internal_link = doc.links;
if (k > 0) {
}
// On vérifie que le lien est OK :
if (internal_link[k].status == LinkStatus.LINK_MISSING) {
var filePath = File.openDialog(internal_link[k].filePath);
//alert(filePath);
internal_link[k].relink(filePath);
} else if (
!internal_link[k].linkType == "InDesign Format Name" ||
internal_link[k].name == "Assemblage fond couleur + filigrane.indd"
) {
try {
internal_link[k].relink(internal_link[k].linkResourceURI);
}
catch (err) {
alert(err.message);
}
} else {
internal_link[k].update();
}
// 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 (!isinlist(updated_list, internal_link[k].filePath)) {
newdoc = app.open(internal_link[k].filePath);
OpenAndUpdate(newdoc);
doc = app.activeDocument;
internal_link = doc.links; // quand tu reviens de la boucle, recharge les liens
updated_list.push(internal_link[k].filePath);
} else {
internal_link[k].update();
}
}
}
}
if (doc.links.length > 0) {
app.scriptPreferences.userInteractionLevel =
UserInteractionLevels.neverInteract;
doc.links.everyItem().update();
try {
doc.save();
} catch (err) {
$.writeln("i = " + i + " document.name = " + document.name);
$.writeln(err.line + " =>" + err.message);
alert(err.line + " => " + err.message);
}
if (
doc.name != "étiquette finie.indd" ||
doc.name != "cataloguephykidis.indd"
) {
doc.save();
doc.close();
//exporttopdf();
}
/* try {
doc.save();
//doc.close();
} catch (err) {
$.writeln("i = " + i + " document.name = " + document.name);
$.writeln(err.line + " =>" + err.message);
alert(err.line + " => " + err.message);
}*/
} else {
doc.close();
}
return 0; // fin de la fonction. Elle ne renvoie rien normalement
}
function isinlist(list, element) {
var flag = false;
for (var l = 0; l < list.length; l++) {
if (list[l] == element) {
flag = true;
}
}
return flag;
}
function exporttopdf() {
var myDocument = app.activeDocument; //Or set it with or replace it with the document object you might have
//if (myResult == true){
for (var myCounter = 0; myCounter < myDocument.spreads.length; myCounter++) {
myDocument.spreads.item(myCounter).pageTransitionType =
PageTransitionTypeOptions.wipeTransition;
myDocument.spreads.item(myCounter).pageTransitionDirection =
PageTransitionDirectionOptions.down;
myDocument.spreads.item(myCounter).pageTransitionDuration =
PageTransitionDurationOptions.medium;
}
app.interactivePDFExportPreferences.flipPages = true;
app.interactivePDFExportPreferences.flipPagesSpeed = 5;
app.interactivePDFExportPreferences.openInFullScreen = false;
app.interactivePDFExportPreferences.interactivePDFInteractiveElementsOption =
InteractivePDFInteractiveElementsOptions.includeAllMedia;
var docName = myDocument.name.replace(/\.[^\.]+$/, "");
var outputFolder = Folder(myDocument.filePath);
var newFile = File(decodeURI(outputFolder) + "/" + docName + ".pdf");
myDocument.exportFile(ExportFormat.interactivePDF, newFile, false); //Change the file path and file name as needed
// }
}
function chkbox(doc) {
var myDialog = app.dialogs.add({
name: "Export to PDF",
});
with (myDialog.dialogColumns.add()) {
var myCheckBoxField = checkboxControls.add();
myCheckBoxField.staticLabel = "PDF";
}
var myResult = myDialog.show();
}
thanks for your read, for information chkbox function is not activate, because it not work..
