Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

After using an ExtendScript (via ESTK) Illustrator becomes corrupted and "Can't open illustration."

$
0
0

Hey, thanks for reading.

 

I'm having a strange problem with Illustrator CS5 and ESTK CS5. I'm new to writing ExtendScripts, so I haven't a clue what could be going wrong here but here's the skinny:

 

I've written the following code, which is very specialized to the exact document I'm working with. Using the ExtendScript Toolkit, the script goes through the following loops:

 

- - -

The primary problem:

For some reason, running this script causes Illustrator to become somehow corrupted. I can continue working with the document as long as it is open, but if I try to close it and re-open it, I get the infuriatingly unhelpful error dialog "Can't open illustration." With no extra details.

 

The same error comes up if I try to open any other .ai files. Shutting down and rebooting doesn't fix the problem. I have to completely uninstall Illustrator, then re-install it before it will work again. And even then, if I try to open the ExtendScript-corrupted file the whole Illustrator app gets corrupted and needs to be reinstalled.

 

Oh, also Illustrator itself shows up as "(Not responding)" while the script is running, but the ESTK console clearly shows that the script is chugging along as expected.

 

- - -

Specifics about the script:

There are 4 "Buttons" on the document, and a library full of nearly-identical symbols in the Library (different colored backgrounds for the buttons).

 

The script cycles through every symbol in the library, replacing and deleting instances of the previous symbol.

Then, for each symbol, it cycles through an array (technically an object-literal) of { language-code: "string" } pairs, and saves a .png of each artboard for each word.

 

- - -

What follows is a pared-down version of the full script:

(I tried to add a few $.sleep(10); calls, hoping that maybe just a brief slowdown in the processes might help. It didn't.)

 

This script (in its original form) outputs a ton of files very, very quickly.

 

Script Example

 

var folder = Folder.selectDialog();                     // Ask for a folder choice.

var aDoc = app.activeDocument;                        // Declare an active Document reference.

var textLayer = aDoc.layers.getByName('text');   // Get the text layer, for moving it back/forward

var textFrms = aDoc.textFrames;                       // Get all text frames, for language swap

 

var allSymbols = aDoc.symbols;                         // Get array of all symbols in the symbol library

var allSymbolItems = aDoc.symbolItems;            // Get an array of all symbol instances in the active document

 

var helpTextArray =

{

    en: "help",

    az: "Kömək",

    cs: "Nápověda",

    da: "Hjælp",

    de: "hilfe",

    el: "Bοήθεια",

    en: "help",

    es: "ayuda",

 

 

};

 

 

    /*

        * There's normally 3 arrays with many more languages / translations

        */

 

 

if( aDoc &&                                      // We have an activeDocument

     folder &&                                    // and we have a selected output folder

     allSymbols.length > 0 &&             // We've got symbols

     allSymbolItems.length > 0 &&      // and we've got symbol instances "symbolItems"

     textFrms.length > 0 ) {                 // and we've got textFrames to manipulate.

 

    // For each symbol in our symbol library...

    for(var i = 0; i < allSymbols.length; i++) {

        // Run through all instances of symbols (symbolItems), and replace with a different symbol.

        for(var ii = 0; ii < allSymbolItems.length; ii++) {

            // Move text layer out of the line of fire.

            $.writeln('Move text to back');

            textLayer.zOrder(ZOrderMethod.SENDTOBACK);

 

 

            var currObj = allSymbolItems[ii];

            var newObj = aDoc.symbolItems.add(aDoc.symbols[i]);

            var symbolColor = aDoc.symbols[i].name;

 

            // Add the new / replacement symbol.

            newObj.left = currObj.left;

            newObj.top = currObj.top;

            newObj.width = currObj.width;

            newObj.height = currObj.height;

 

            // Remove the old symbol.

            currObj.remove();

 

 

            // Bring text back up to the front.

            $.writeln('Bring text to front');

            textLayer.zOrder(ZOrderMethod.BRINGTOFRONT);

            redraw();

            $.sleep(10)

        }

 

        // Run through each language and each buttonText and save a copy.

        var currArray = helpTextArray;

        var currArrayName = "help";

 

 

        for(currLang in currArray) {

            switchText(currLang, currArray);

            $.sleep(10)

            // Run function to save .pngs of each artboard

            exportAll(currLang, symbolColor, currArrayName);

        } // end for (currLang in currArray)

 

 

    } // end symbols.length

} // end if

 

 

function switchText(lang, array) {

    //var textFrms = activeDocument.textFrames;

    var newText = array[lang];

    newText = (newText === "") ? array["en"] : newText;

 

 

    for(var i = 0; i < textFrms.length; i++) {

        var isHorizontal = ( textFrms[i].width > textFrms[i].height );

        var scale = 100;

        var scaleMatrix;

        textFrms[i].contents = newText;

 

 

        /*

           * There's normally an automatic text-resizer here

           */

 

    } // for var i

}

 

 

function exportAll(lang, color, buttonText) {

    var artBds = aDoc.artboards;

    var options = new ExportOptionsPNG24();

        options.antiAliasing = true;

        options.transparency = true;

        options.artBoardClipping = true;

 

    for(var i = 0; i < artBds.length; i++) {

         var currBoard = artBds.setActiveArtboardIndex(i);

         var buttonPosition =  artBds[i].name;

 

 

         var newFile = new File(folder.fsName+"/"+buttonText+"_"+color+"_"+buttonPosition+"_"+la ng+".png");

 

         aDoc.exportFile(newFile,ExportType.PNG24,options);

         $.writeln('A file was saved with the name:: '+buttonText+'_'+color+'_'+buttonPosition+'_'+lang+'.png');

         $.sleep(10)

     }

}

 

 

function revertToOriginal() {

    $.writeln('Revert');

    // Switch the text back to help.

    switchText("en", helpTextArray);

 

    // For each symbol instance...

    for(var i = 0; i < allSymbolItems.length; i++) {

        // Move text layer out of the line of fire.

        $.writeln('Move text to back');

        textLayer.zOrder(ZOrderMethod.SENDTOBACK);

 

 

        var currObj = allSymbolItems[i];

        // Add in the placeholder since we're reverting.

        var newObj = aDoc.symbolItems.add(aDoc.symbols[0]);

        var symbolColor = aDoc.symbols[0].name;

 

        // Add the new / replacement symbol.

        newObj.left = currObj.left;

        newObj.top = currObj.top;

        newObj.width = currObj.width;

        newObj.height = currObj.height;

 

        // Remove the old symbol.

        currObj.remove();

 

 

        // Bring text back up to the front.

        $.writeln('Bring text to front');

        textLayer.zOrder(ZOrderMethod.BRINGTOFRONT);

        redraw();

        $.sleep(10)

    }

        $.writeln('REVERT');

}

revertToOriginal();


 

 

Are there best practices that I'm unaware of here that could be causing this corruption?

 

Does anyone know what could be happening?

 

The only error I ever get is "Can't open illustration." There's never anything more helpful, so I have no idea what could be going wrong.

 

If there's any more information that would be of use to anyone I'd be happy to share. This is wasting a lot of my time and making me pull my hair out like crazy,


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>