I'm few simplified the code: without changing the logic I removed unnecessary levels of nesting use the reverse iterators (for objects that moved) simplify the regexp declared variables and simplify some variable names Now it is better to read. Should work. Run it in ESTK and catch the errors: //@target illustrator read_create(activeDocument.layers); function read_create(lays) { var lay_i, txt_i, x, y, xx, xy, count, txtFramesLen, t, t1; for (lay_i = 0; lay_i < lays.length; lay_i++) { if (lays[lay_i].locked) lays[lay_i].locked = false; if (lays[lay_i].name != "NUMBER") continue; var theGrp = lays[lay_i].pathItems; for (var i = theGrp.length - 1; i >= 0 ; i--) { if (theGrp.pathPoints.length != 8) continue; if (!theGrp.stroked || !theGrp.filled) continue; var strkColor = new CMYKColor(); strkColor.cyan = Math.round(theGrp.strokeColor.cyan); strkColor.magenta = Math.round(theGrp.strokeColor.magenta); strkColor.yellow = Math.round(theGrp.strokeColor.yellow); strkColor.black = Math.round(theGrp.strokeColor.black); if (!(Math.round(theGrp.strokeWidth * 25.4 / 72 * 10) / 10 == 0.3 && strkColor.cyan == magentaColor.cyan && strkColor.magenta == magentaColor.magenta && strkColor.yellow == magentaColor.yellow && strkColor.black == magentaColor.black)) { continue; } x = Math.round(theGrp.pathPoints[1].anchor[0]); y = Math.round(theGrp.pathPoints[3].anchor[1]); xx = Math.round(theGrp.pathPoints[5].anchor[0]); xy = Math.round(theGrp.pathPoints[7].anchor[1]); count = 0; txtFramesLen = lays[lay_i].textFrames.length; for (txt_i = txtFramesLen - 1; txt_i >= 0; txt_i--) { var text_frame = lays[lay_i].textFrames; if (!text_frame[txt_i].contents.match(/[A-Z][0-9]{1,3}$/)) continue; t = Math.round(text_frame[txt_i].anchor[1]); t1 = (Math.round(text_frame[txt_i].anchor[0])); alert(text_frame[txt_i].contents); if (!(t1 > xx && t1 < x)) continue; if (!(t > y && t < xy)) continue; var newGroup = lays[lay_i].groupItems.add(); newGroup.name = text_frame[txt_i].contents + ":"; text_frame[txt_i].moveToBeginning(newGroup); } theGrp.moveToBeginning(newGroup); } } }
... View more