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

Illustrator CS6 stops responding during script and crashes at end...

New Here ,
Oct 17, 2017 Oct 17, 2017

Copy link to clipboard

Copied

Hello Everyone,

I'm having a serious problem. I need to optimize about 170+ Illustrator files for export to *.svg for the UI elements of our Tech Demo. Each of these Illustrator files has in excess of 500 paths. (They're vegetation, so tons of leaves and such.) In order to fully optimize these files, I need to basically take the black outline filled paths and cut them out of all of the non-black filled paths beneath them and then merge that "cutter" path with the bottom-most black outline filled path.

I've created a script to automate this process. The script is working fine. The only problem is that once I get about 15 - 20 paths in, Illustrator locks up to the "Not Responding" stage and then, once the script is done executing, it crashes. Now, I've run the script on a much simple version of one of the most complex files (640 paths). My test file has 10 paths in it. On the 10 path version, no problems. On the 640 path version, the crashing behavior.

Can anyone take a look at my script to see if there is anything I can do to rectify this situation? I've tried putting in sleep and app.redraw() calls to see if that could force Illustrator to keep up, but that just exacerbates the situation. I think because Illustrator is waiting for the script to execute. I'm really stumped and frustrated as to what I can do. I'm Including the script at the end.

Thanks In Advance!

var debugLevel = $.level;

var uiDisplayAlerts = false;

var actionFile = new File("E:/Adobe/Adobe Illustrator CS6 (64 Bit)/Presets/en_US/Actions" + '/optimizationActions.aia');

var originalPathItems = [];

var cutterName = "Cutter Path";

var cutterRed, cutterGreen, cutterBlue;

$.level = 2;

if (app.userInteractionLevel == UserInteractionLevel.DISPLAYALERTS)

{

    uiDisplayAlerts = true;

} else {

    uiDisplayAlerts = false;

}

// Populate our array with all of the path items before modification.

for (i = 0; i < app.activeDocument.layers[0].pathItems.length; i++) {

    originalPathItems.push (app.activeDocument.layers[0].pathItems);

}

app.loadAction(actionFile);

if ( app.documents.length > 0 ) {

    if (!app.activeDocument.saved) {

        Window.alert ("This script needs to modify your document. Please save it before running this script.", "Please Save Your Document");

    } else {

        if (app.activeDocument.selection.length < 1) {

            Window.alert ("You need to have at least one cutter path selected.", "Select A Single Path");

        } else if (app.activeDocument.selection.length > 1) {

            Window.alert ("You need to have only one cutter path selected.", "Select A Single Path");

        } else {

            app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

            cutterIndex = app.activeDocument.layers[0].pathItems.length - app.activeDocument.selection[0].zOrderPosition;

            cutterRed = app.activeDocument.selection[0].fillColor.red;

            cutterGreen = app.activeDocument.selection[0].fillColor.green;

            cutterBlue = app.activeDocument.selection[0].fillColor.blue;

            app.cut();

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

                //$.bp(i > originalPathItems.length - 2 && i < originalPathItems.length);

                // If this is the bottom path in the stack, we need to do a Unite.

                if (i == originalPathItems.length - 1) {

                    originalPathItems.selected = true;

                    app.doScript('oaPasteInFront', 'optimizationActions', false);

                    originalPathItems.selected = true;

                    app.doScript('oaUnite', 'optimizationActions', false);

                    app.selection = null;

                } else {

                    // If this isn't the bottom path in the stack, we need to do a minus front.

                    if (!originalPathItems.hidden && i > cutterIndex &&  originalPathItems.fillColor.red != cutterRed  &&  originalPathItems.fillColor.green != cutterGreen &&  originalPathItems.fillColor.Blue != cutterBlue) {

                        originalPathItems.selected = true;

                        app.doScript('oaPasteInFront', 'optimizationActions', false);

                        app.activeDocument.selection[0].name = cutterName;

                        originalPathItems.selected = true;

                        app.doScript('oaMinusFront', 'optimizationActions', false);

                        // Now we need to handle the outcomes for a minus front

                        if (app.activeDocument.selection.length == 2 && app.activeDocument.selection[0].name == cutterName) {

                            // If we've got two selected paths and the first one is the same color as the cutter, it means

                            // that the cutter completely overlaps the path to be cut and we need to delete them both.

                            for (i = app.activeDocument.selection.length - 1 ; i >= 0 ; i--) {

                                app.activeDocument.selection.remove();

                            }

                        } else if (app.activeDocument.selection[0].typename == "GroupItem") {

                            // If we've got  a group selected, it means the path cut and split the other path into multiple

                            // paths, so we've got to ungroup them and deselect. them.

                            var groupToUngroup = app.activeDocument.selection[0];

                            var pathsToUngroup = [];

                            var compoundPathsToUngroup = [];

                            var placementGroup;

                            var placementPath;

                            var placementCompoundPath;

                           

                            app.selection = null;

                           

                            if (groupToUngroup.pathItems.length >= 1) {

                                for (j = 0 ; j < groupToUngroup.pathItems.length ; j++) {

                                    pathsToUngroup = groupToUngroup.pathItems;

                                }

                            }

                       

                            if (groupToUngroup.compoundPathItems.length >= 1) {

                                for (j = 0 ; j < groupToUngroup.compoundPathItems.length ; j++) {

                                    compoundPathsToUngroup = groupToUngroup.compoundPathItems;

                                }

                            }

                           

                            placementGroup = groupToUngroup;

                           

                            if (pathsToUngroup.length >= 1) {

                                for (j = 0 ; j < pathsToUngroup.length ; j++) {

                                    if (j < 1) {

                                        pathsToUngroup.move(placementGroup, ElementPlacement.PLACEBEFORE);

                                        placementPath = pathsToUngroup;

                                    } else {

                                        pathsToUngroup.move(placementPath, ElementPlacement.PLACEAFTER);

                                        placementPath = pathsToUngroup;

                                    }

                                }

                            }

                       

                            if (compoundPathsToUngroup.length >= 1) {

                                for (j = 0 ; j < compoundPathsToUngroup.length ; j++) {

                                    if (j < 1) {

                                        compoundPathsToUngroup.move(placementPath, ElementPlacement.PLACEAFTER);

                                        placementCompoundPath = compoundPathsToUngroup;

                                    } else {

                                        compoundPathsToUngroup.move(placementCompoundPath, ElementPlacement.PLACEAFTER);

                                        placementCompoundPath = compoundPathsToUngroup;

                                    }

                                }

                            }

                       

                            app.selection = null;

                        } else {

                            // If it's anything else, it either means that the two paths don't overlap at all or the cutter

                            // overlaps the other path, but doesn't completely chop it into pieces, so we just need to

                            // deselect the remaining path.

                            app.selection = null;

                        }

                    }

                }

            }

        }

    }

} else {

    Window.alert("You must open at least one document.", "No Document Open");

}

app.unloadAction('optimizationActions','');

if (uiDisplayAlerts) {

    app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;

} else {

    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

}

$.level = debugLevel;

TOPICS
Scripting

Views

613

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
Valorous Hero ,
Oct 17, 2017 Oct 17, 2017

Copy link to clipboard

Copied

It's tough to say, but hopefully your script is being broken by differences in the artwork. Maybe the ungrouping routine needs to run backwards through the loop, in case the length dynamically changes?

Votes

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
New Here ,
Oct 17, 2017 Oct 17, 2017

Copy link to clipboard

Copied

LATEST

Okay! Got it solved. The script actually works perfectly. Okay, not perfectly. For some reason it doesn't appear to be detecting the groups, now. BUT!!! I figured out why Illustrator was crashing. It was because I was launching the script through the play button of the Extendscript Toolkit. When I run the script from the Scripts menu item (ie, from completely within Illustrator), Illustrator doesn't crash when the script has finished. It still locks up after a while, but when the script is complete, it resolves itself without crashing. Hope that helps y'all!

Votes

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