InDesign Keep Crashing When Executing the JavaScript

Engaged ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

Hi Pros, 

I Tried to Develop an Old Script twice so it will alert the user and save Sperated Outlined Version of the file, in the first example it will show dialog to the user to select location.

var a = app.activeDocument.allPageItems,  t; 
while( t=a.pop() )  {
    if( !(t instanceof TextFrame) ) continue; 
    try{ var outlineList = t.createOutlines(true) ;//removes original
        var thisItem = outlineList[0];//assumes only 1 item in frame
        //in case you want to style polygon created
        thisItem.fillColor = "Dark Red";
        thisItem.strokeWeight = "2 pt";
        thisItem.strokeColor = "Black";
    } catch(_){
    } 
}

//Alert the User that all the Document Outlined
alert("ALL THE DOCUMENT OUTLINED!-I WILL PROTECT YOUR DOCUMENT!\n\nScript By: Mohammad Hasanain - April 2021", "WARNING!");
saveAsIndd();    
//Save Outlined Copy to Desktop - Windows and Mac
function saveAsIndd()
{
     var myDoc = app.activeDocument;
     var folderSelect, saveFile;
     OriginalFile = app.documents[0].fullName;
     fileName = myDoc.name;
     folderSelect = Folder.selectDialog("Please select a Folder to Save Outlined InDesign File");
     if (!folderSelect) return;
     saveFile = File(folderSelect+"/"+"Outlined_"+fileName);
     myDoc.save(new File(saveFile));
     //Re-Open The Original File Before Outlined
     app.open(OriginalFile);
}

 But the InDesing Keep Crashing in long Document Only, if the Document is Short Like 2 or 4 Pages it Working Well, Here is Second Short One that Keep InDesign Crashing also!:

//Outline All The Document
var a = app.activeDocument.allPageItems,  t; 
while( t=a.pop() )  {
    if( !(t instanceof TextFrame) ) continue; 
    try{ var outlineList = t.createOutlines(true) ;//removes original
        var thisItem = outlineList[0];//assumes only 1 item in frame
        //in case you want to style polygon created
        thisItem.fillColor = "Dark Red";
        thisItem.strokeWeight = "2 pt";
        thisItem.strokeColor = "Black";
    } catch(_){
    } 
}

//Alert the User that all the Document Will be Outlined
alert("ALL THE DOCUMENT OUTLINED!,NOW IT WILL BE SAVED AS OUTLIEND COPY!\n\nScript By: Mohammad Hasanain - April 2021", "WARNING!");

//Save Outlined Copy
InddFileName = String(app.documents[0].fullName);
app.activeDocument.save(File(InddFileName.replace (/\.indd$/, "_Outlined.indd")));

Any Help is Appreciated,Thanks in Advance

Best Regards

Mohammad 

TOPICS
Scripting

Views

95

Likes

translate

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

correct answers 1 Correct Answer

Adobe Community Professional , Apr 07, 2021 Apr 07, 2021
Hi Mohammad, your assumption could be wrong, that there is at least one item in the frame left after running t.createOutlines(true). Perhaps even the object in variable t would not exist anymore, because you set the deleteOriginal parameter to true. And perhaps that is crashing InDesign. Sometimes even a try-catch scenarium cannot avoid that. So I would do further tests to pinpoint the case with the crash and solve it with a if-else construction.   Also note, that object story also has the metho...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

Hi Mohammad,

your assumption could be wrong, that there is at least one item in the frame left after running t.createOutlines(true). Perhaps even the object in variable t would not exist anymore, because you set the deleteOriginal parameter to true.

And perhaps that is crashing InDesign. Sometimes even a try-catch scenarium cannot avoid that.

So I would do further tests to pinpoint the case with the crash and solve it with a if-else construction.

 

Also note, that object story also has the method createOutlines().

You could work with that by iterating all the stories of a document.

 

Regards,
Uwe Laubender

( ACP )

Likes

translate

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
Engaged ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

Thank you very much i will try to fix it

Likes

translate

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
Adobe Community Professional ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

A slightly different approach:

Use parameter false in the method createOutlines()

Later, when done with all stories, remove all text containers of all stories.

 

Regards,
Uwe Laubender

( ACP )

Likes

translate

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
Engaged ,
Apr 07, 2021 Apr 07, 2021

Copy link to clipboard

Copied

Thank you i will try it

Likes

translate

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