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

MRAP issue on multiple script runs

Community Beginner ,
Oct 19, 2020 Oct 19, 2020

I have MRAP error when I run the script second time and it's happening inside the "For loop", when I try to change text alignment. I thought it's my code first, but was not able to find an error. So I did try with the example from the Adobe JS script guide. And on the seond run in the ExtendScruipt tool I had the same issue. Here is the code from the Adone PDF. It's probably an issue in AI it self. Please help.

 

Cursor_and___Source1.png

 

 

// Creates a new document with 1 text frame and 3 paragraphs
// gives each paragraph a different justification, then creates
// a paragraph style and applies it to all paragraphs
var docRef = documents.add();
var pathRef = docRef.pathItems.rectangle(600, 200, 200, 400);
var textRef = docRef.textFrames.areaText(pathRef);
textRef.paragraphs.add("Left justified paragraph.");
textRef.paragraphs.add("Center justified paragraph.");
textRef.paragraphs.add("Right justified paragraph.");
textRef.textRange.characterAttributes.size = 28;
// change the justification of each paragraph
// using the paragraph attributes object
var paraAttr_0 = textRef.paragraphs[0].paragraphAttributes;
paraAttr_0.justification = Justification.RIGHT;
var paraAttr_1 = textRef.paragraphs[1].paragraphAttributes;
paraAttr_1.justification = Justification.CENTER;
var paraAttr_2 = textRef.paragraphs[2].paragraphAttributes;
paraAttr_2.justification = Justification.LEFT;
// create a new paragraph style
var paraStyle = docRef.paragraphStyles.add("LeftIndent");
// add some paragraph attributes
var paraAttr = paraStyle.paragraphAttributes;
paraAttr.justification = Justification.LEFT;
paraAttr.firstLineIndent = 10;
// apply the style to each item in the document
var iCount = textRef.paragraphs.length;
for(var i=0; i<iCount; i++) {
paraStyle.applyTo(textRef.paragraphs[i], true);
}
redraw();

 

TOPICS
Bug , Scripting , Tools
609
Translate
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

Valorous Hero , Oct 19, 2020 Oct 19, 2020

Try the following: wrap your entire script in a function and call it at the very end, and also ensure there's no var declarations inside of your loops if you ever have such loops (although your code is just fine as it is using an accessor in the loop it seems).
#target illustrator

function test (){

    var thisItem;

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

        thisItem = x[i];

    }

}

test();

Translate
Adobe
Valorous Hero ,
Oct 19, 2020 Oct 19, 2020

Try the following: wrap your entire script in a function and call it at the very end, and also ensure there's no var declarations inside of your loops if you ever have such loops (although your code is just fine as it is using an accessor in the loop it seems).
#target illustrator

function test (){

    var thisItem;

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

        thisItem = x[i];

    }

}

test();

Translate
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 Beginner ,
Oct 19, 2020 Oct 19, 2020

Thank you so much, it helped. 

Translate
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
Valorous Hero ,
Oct 19, 2020 Oct 19, 2020

Did it stop the error, or it still happens sometimes?

Translate
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 Beginner ,
Oct 19, 2020 Oct 19, 2020

Actually now it's choking with the same error but on a different line, I did remove all the VARs in the loop:

 

textRef[p].textRange.horizontalScale = text[p].xScale;
Translate
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
Valorous Hero ,
Oct 19, 2020 Oct 19, 2020
LATEST

Oh no! But also did you restart your Illustrator too? Restarting will sometimes clean out the error issues, there could be a chance that without a restart this new code still has a problem. Although it could still have a problem nonetheless.

Translate
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