Copy link to clipboard
Copied
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.
// 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();
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();
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
Thank you so much, it helped.
Copy link to clipboard
Copied
Did it stop the error, or it still happens sometimes?
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now