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

crash indesign during a script without reason (all test done)

Explorer ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

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..

TOPICS
Scripting

Views

89

Likes

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 ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

There's some brilliant scripters here  who might be able to help.

@m1b  comes to mind or perhaps @Manan Joshi 

Likes

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 ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

i see one thing when my alert() windows is open, i have check performance and processor 1 is really hight

 

the processus who use proc1 is system and kernel, and my mouse is jerk

indesign use proc 8

with the alert trick, i can finish my full script

Likes

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 ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

I suspect it has something to do with the accent characters in the filename. I have encountered I/O errors when dealing with filenames with special characters. Can you try on a doc that has no special characters? Do you get the same error? Also, to make your isinlist function more efficient, I would change it to this:

function isinlist(list, element) {
  for (var l = 0; l < list.length; l++) {
    if (list[l] == element) {
      return true;
    }
  }
  return false;
}

Likes

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 ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

Hi @laurence roussel12011930,

Your's is a very specific problem that is difficult to troubleshoot remotely, even the suggestions would be very generic in nature to help you out in a big way. This issue has transformed into something that only an experienced person with access to real data/use cases could help with. Since you have spent numerous days resolving this and other related issues that we discussed quite thoroughly in different posts, but still no big progress came out of it. I would suggest you hire someone to fix this job for you or design an alternative solution that would better serve you.

-Manan

Likes

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 ,
Nov 03, 2022 Nov 03, 2022

Copy link to clipboard

Copied

hi manan, how are you? the problem is if you speak about data, that mean you have not really understand the problem

 

problem is for // thread,2 specialised personn are come on my job, without find solution, all told java is sh*t (or reac for jsx)

 

about my problem is we need to put a non blocking pause between each main files, for do not burnout processor 1 (system and kernel)

or i don t know if it s possible, during script, down and restart indesign, and restart script

 

 

actually , need to test several time, my solution is put 2 alert during the script, and i can finish it, but i feel alter() is blocking somewhere, but that help

Likes

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 ,
Nov 04, 2022 Nov 04, 2022

Copy link to clipboard

Copied

My pointing to data meant that unless someone recreates or has access to the same files/folders etc that you have it is going to be difficult to reproduce. Also, the issue is time taking so again getting it tested would require much effort. I do understand you issue but it's a general setup where we do open files process it someway and then export a PDF, the fact that such crashes are not reported frequently and also the CPU load is manageable points that there is something unique to your setup.

-Manan

Likes

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 ,
Nov 05, 2022 Nov 05, 2022

Copy link to clipboard

Copied

LATEST

my neighbourg told me the problem is // process is not possible with kernel system it will work only with 1 processor, during my script this processor turn at 80%

 

he try to do a non blocking timer with an other processor

with this script 

function delay (miliseconds) {
    return new Promise((resolve) => {
        window.setTimeout(() => {
            resolve();
        }, miliseconds);
    });
}

Ca marche pour moi et c'est pas bloquant si elle est bien appelée avec await :

await delay(2000);

 

but it not work

Likes

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