illustrator插件--常用功能开发--移除叠印属性--js脚本开发--AI插件

在印刷制版过程中,经常遇到叠印属性的处理过程,本文介绍如何移除叠印属性,源代码如下所示:

var Clr = 0;
var Lock = 0;
var Count = 0;
if (documents.length > 0) {
    doc = activeDocument;
    ans = confirm("你想要删除叠印吗?");
    if (ans == true) {
        Clr = 1
    }
    if (doc.selection.length) {
        sel = doc.selection;
        for (var i = 0; i < sel.length; i += 1) {
            sel[i].selected = false
        }
        for (var i = 0; i < sel.length; i += 1) {
            engine(sel[i])
        }
    } else {
        ans = confirm("检测到有锁定和隐藏的对象,需要包含锁定和隐藏的对象?");
        if (ans == true) {
            Lock = 1
        }
        engine(doc);
    }
    alert("处理对象 : " + Count);
}

function engine(xObj) {
    tname = xObj.typename;
    if (tname == "GroupItem" || tname == "Document") {
        obj = xObj.groupItems;
        for (var i = 0; i < obj.length; i += 1) {
            engine(obj[i])
        }
        selOPs(xObj.pathItems, 0);
        selOPs(xObj.textFrames, 1);
        for (var i = 0; i < xObj.compoundPathItems.length; i += 1) {
            selOPs(xObj.compoundPathItems[i].pathItems, 0);
        }
    } else {
        if (tname == "PathItem") {
            selOP1(xObj, 0)
        } else if (tname == "TextFrame") {
            selOP1(xObj, 1)
        } else {
            if (tname == "CompoundPathItem") {
                selOPs(xObj.pathItems, 0)
            }
        }
    }
}

function selOPs(itm, sw) {
    for (var i = 0; i < itm.length; i += 1) {
        selOP1(itm[i], sw)
    }
}

function selOP1(itm, sw) {
    if (itm.editable == false && Lock == 0) {
        return;
    }
    switch (sw) {
        case 0:
            if (itm.fillOverprint == true || itm.strokeOverprint == true) {
                Count++;
                if (itm.editable == false) {
                    editOn(itm)
                }
                itm.selected = true;
                if (Clr) {
                    itm.fillOverprint = false;
                    itm.strokeOverprint = false;
                }
            }
            break;
        case 1:
            var e1 = itm.layer.locked;
            var e2 = itm.layer.visible;
            var e3 = itm.locked;
            var e4 = itm.hidden;
            var st = itm.story;
            var tr = st.textRanges;
            var op = 0;
            if (itm.editable == false) {
                editOn(itm)
            }
            for (var i = 0; i < tr.length; i += 1) {
                cat = tr[i].characterAttributes;
                if (cat.overprintFill == true || cat.overprintStroke == true) {
                    if (Clr) {
                        itm.textRange.overprintFill = false;
                        itm.textRange.overprintStroke = false;
                    }
                    op = 1;
                    break;
                }
            }
            if (op) {
                Count++;
                itm.selected = true;
            } else {
                itm.locked = e3;
                itm.hidden = e4;
                itm.layer.locked = e1;
                itm.layer.visible = e2;
            }
            break;
    }
}

function editOn(itm) {
    itm.layer.locked = false;
    itm.layer.visible = true;
    itm.locked = false;
    itm.hidden = false;
}

图片.png

你可能感兴趣的:(illustrator插件--常用功能开发--移除叠印属性--js脚本开发--AI插件)