Skip to main content
Inspiring
July 20, 2016
Answered

Why illustrator allowed pathItem store error msg?

  • July 20, 2016
  • 3 replies
  • 1917 views

So this happen, I cycle through my artwork, compare their typename ono by one, and my script keep crushing.

Turns out there is often one or two pathItem's object tree property completely lose their mind.

No property, but error msg like this image, and this happens so often.

This topic has been closed for replies.
Correct answer zertle

I have run into that same error too.  Unfortunately I still don't know what causes it.  Some ways to fix the problem that I've found are to select all, cut, and paste then try running the script again. This can be automated:

var done = false;

var firstTry = false;

while( !done ) {

  try {

    if( !firstTry ) {

       app.activeDocument.selectObjectsOnActiveArtboard();

       app.cut();

       app.paste();

    }

 

    /* CODE TO PROCESS GROUPS */

    

    done = true;

  }

  catch(err) {

    firstTry = false;

  }

}

This would all be inside of your function.  You could also add code to auto quit after 5 or so tries, just add a 'count' variable.

Other fixes I have found are closing and reopening the file or restarting Illustrator.  Sorry I don't have a better answer.

3 replies

Silly-V
Legend
August 12, 2016

Can you please post a working piece of your code that an Adobe person can help work with and debug?

Inspiring
August 15, 2016

main();

function main(){

    if (app.documents.length > 0) {

        var docRef = app.activeDocument;

        var selectedObjects = docRef.selection;

        if (selectedObjects.length > 0) {

            processArrayItem(selectedObjects);

        } else {

            //do nothing

        }

    } else {

        alert("there are no open documents");

    }

}

function processArrayItem(targetArray){

    for (var i = 0; i <= targetArray.length - 1; i++) {

        if(targetArray.typename == "CompoundPathItem") {

            //do nothing

        } else if(targetArray.typename == "GroupItem") {

            //cycle through the group

            processGroupItem(targetArray);

        } else {

            if(targetArray.filled == false) {

                // do nothing

            } else if(targetArray.fillColor.typename == "GradientColor") {

                // do nothing

            } else if(targetArray.fillColor.typename == "PatternColor") {

                // do nothing

            } else if(targetArray.fillColor.typename == "SpotColor") {

                // do nothing

            } else if(targetArray.fillColor.typename == "GrayColor") {

                // do nothing

            } else {

                changeSolidColorToGradient(targetArray);

            }

        }

    }

}

function processGroupItem(targetGroup){

    for (var i = 0; i <= targetGroup.pageItems.length - 1; i++) {

        if(targetGroup.pageItems.typename == "CompoundPathItem") {

            //do nothing

        } else if(targetGroup.pageItems.typename == "GroupItem") {

            //cycle through the group

            processGroupItem(targetGroup.pageItems);

        } else {

            if(targetGroup.pageItems.filled == false) {

                // do nothing

            } else if(targetGroup.pageItems.fillColor.typename == "GradientColor") {

                // do nothing

            } else if(targetGroup.pageItems.fillColor.typename == "PatternColor") {

                // do nothing

            } else if(targetGroup.pageItems.fillColor.typename == "SpotColor") {

                // do nothing

            } else if(targetGroup.pageItems.fillColor.typename == "GrayColor") {

                // do nothing

            } else {

                changeSolidColorToGradient(targetGroup.pageItems);

            }

        }

    }

}

function changeSolidColorToGradient(targetPathItem){

    var originalColor = targetPathItem.fillColor;

    var myGradientAngle = -60;

    var startColor = new RGBColor();

    var endColor = new RGBColor();

    var darkenColor;

    var finalColor = new GradientColor();

    var finalGradient = app.activeDocument.gradients.add();

    startColor.red = originalColor.red;

    startColor.green = originalColor.green;

    startColor.blue = originalColor.blue;

    darkenColor = RGBtoHSV(originalColor.red, originalColor.green, originalColor.blue);

    darkenColor = HSVtoRGB(darkenColor.h, darkenColor.s, darkenColor.v*0.8);

    endColor.red = darkenColor.r;

    endColor.green = darkenColor.g;

    endColor.blue = darkenColor.b;

    finalGradient.type = GradientType.LINEAR;

    finalGradient.gradientStops[0].color = startColor;

    finalGradient.gradientStops[0].rampPoint = 50;

    finalGradient.gradientStops[1].color = endColor;

    finalColor.gradient = finalGradient;

    targetPathItem.fillColor = finalColor;

    targetPathItem.rotate(myGradientAngle, false, false, true, false, Transformation.CENTER);

}

function HSVtoRGB(h, s, v) {

    var r, g, b, i, f, p, q, t;

    if (arguments.length === 1) {

        s = h.s, v = h.v, h = h.h;

    }

    i = Math.floor(h * 6);

    f = h * 6 - i;

    p = v * (1 - s);

    q = v * (1 - f * s);

    t = v * (1 - (1 - f) * s);

    switch (i % 6) {

        case 0: r = v, g = t, b = p; break;

        case 1: r = q, g = v, b = p; break;

        case 2: r = p, g = v, b = t; break;

        case 3: r = p, g = q, b = v; break;

        case 4: r = t, g = p, b = v; break;

        case 5: r = v, g = p, b = q; break;

    }

    return {

        r: Math.round(r * 255),

        g: Math.round(g * 255),

        b: Math.round(b * 255)

    };

}

function RGBtoHSV(r, g, b) {

    if (arguments.length === 1) {

        g = r.g, b = r.b, r = r.r;

    }

    var max = Math.max(r, g, b), min = Math.min(r, g, b),

        d = max - min,

        h,

        s = (max === 0 ? 0 : d / max),

        v = max / 255;

    switch (max) {

        case min: h = 0; break;

        case r: h = (g - b) + d * (g < b ? 6: 0); h /= 6 * d; break;

        case g: h = (b - r) + d * 2; h /= 6 * d; break;

        case b: h = (r - g) + d * 4; h /= 6 * d; break;

    }

    return {

        h: h,

        s: s,

        v: v

    };

}

Silly-V
Legend
August 15, 2016

Thank you, I will pass this along!

zertleCorrect answer
Inspiring
August 8, 2016

I have run into that same error too.  Unfortunately I still don't know what causes it.  Some ways to fix the problem that I've found are to select all, cut, and paste then try running the script again. This can be automated:

var done = false;

var firstTry = false;

while( !done ) {

  try {

    if( !firstTry ) {

       app.activeDocument.selectObjectsOnActiveArtboard();

       app.cut();

       app.paste();

    }

 

    /* CODE TO PROCESS GROUPS */

    

    done = true;

  }

  catch(err) {

    firstTry = false;

  }

}

This would all be inside of your function.  You could also add code to auto quit after 5 or so tries, just add a 'count' variable.

Other fixes I have found are closing and reopening the file or restarting Illustrator.  Sorry I don't have a better answer.

Inspiring
August 9, 2016

Awesome!

Silly-V
Legend
August 9, 2016

What AI version is this still happening on?

tpk1982
Legend
July 22, 2016

not sure why you used -1 in the for loop

try

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

Inspiring
July 22, 2016

Hi, thanks for reply, your code is same as mine

  • Mine

     for(i=0; i<=targetGroup.pageItems.length - 1; i++){

  • Yours

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

both run the same times

tpk1982
Legend
July 22, 2016

agree.. but did you tried with my coding?