如何在InDesign中设置(文本框架)页面项目以在页面中手动更改后从母版页更新位置/大小?

时间:2013-04-16 15:25:24

标签: javascript adobe-indesign

我有一个执行以下操作的脚本:

    var document = app.documents.item(0);
    var layer = document.layers.itemByName("Normal");
    var allTextFrames = toArray(layer.textFrames);
    var moved = selectWhere("moved", "label", allTextFrames)[0];
    var notMoved = selectWhere("notMoved", "label", allTextFrames)[0];
    var instance = selectWhere("instance", "label", allTextFrames)[0];
    $.writeln("Moved          : " + moved.geometricBounds.join(", "));
    $.writeln("Moved overr: " + moved.overriddenMasterPageItem.geometricBounds.join(", "));
    $.writeln("notMoved          : " + notMoved.geometricBounds.join(", "));
    $.writeln("notMoved overr: " + notMoved.overriddenMasterPageItem.geometricBounds.join(", "));



    var overr = moved.overriddenMasterPageItem;
    moved.geometricBounds = [moved.overriddenMasterPageItem.geometricBounds[0] 
                                            ,moved.overriddenMasterPageItem.geometricBounds[1]
                                            ,moved.overriddenMasterPageItem.geometricBounds[2]
                                            ,moved.overriddenMasterPageItem.geometricBounds[3]];
    moved.visibleBounds =      [moved.overriddenMasterPageItem.visibleBounds[0] 
                                            ,moved.overriddenMasterPageItem.visibleBounds[1]
                                            ,moved.overriddenMasterPageItem.visibleBounds[2]
                                            ,moved.overriddenMasterPageItem.visibleBounds[3]];

但是如果我更改母版页中的文本框架,它就不会更新“移动”的文本框架......

例如,pageItem有一个属性,当when设置为“-1”时,它将使用母版页值。我正在寻找类似的东西,但是位置和大小。

fillTint number readonly在PageItem的填充颜色中使用的色调百分比。 (要指定色调百分比,请使用0到100范围内的数字;要使用继承或覆盖的值,请使用-1。) src:http://jongware.mit.edu/iccs5_html_3.0.3d/iccs5/pc_PageItem.html

1 个答案:

答案 0 :(得分:0)

我不会将其标记为anwser,因为有时不起作用;

以下是删除文本框架和恢复的脚本。然后它为它提供旧文本框架的数据。它还会将文本框架链接到上一个和下一个文本框架。

使用方法:

  • 创建脚本并粘贴以下内容
  • 选择移动的文本框并运行脚本。
  • 完成!!!

    #target "indesign"
    #targetengine "mySessionX"
    var SCRIPT_NAME = "Restore moved text frames";
    try{
    app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, SCRIPT_NAME);
    }catch(e){
        alert(e);
    }
    
    function main(){
        removeOverrides(app.selection[0]);
    }
    
    function removeOverrides(textFrame){
        if(textFrame.constructor.name != "TextFrame"){
            throw new Error("No text frame selected");
        }
        // save data
        var contents = textFrame.contents;
        var contentType = textFrame.contentType;
        var nextTextFrame = textFrame.nextTextFrame;
        var previousTextFrame = textFrame.previousTextFrame;
        var masterPageTextFrame = textFrame.overriddenMasterPageItem;
        var page = textFrame.parentPage;
        if(nextTextFrame){
            nextTextFrame.previousTextFrame = null;
        }
        if(previousTextFrame){
            previousTextFrame.nextTextFrame = null;
        }
    
        // remove overrides
        textFrame.removeOverride();
    
        // restore state
        var newTextFrame = masterPageTextFrame.override(page);
        newTextFrame.contents = contents;
        newTextFrame.contentType = contentType;
    
        // update right and left
        if(nextTextFrame){
            nextTextFrame.previousTextFrame = newTextFrame
        }
        if(previousTextFrame){
            previousTextFrame.nextTextFrame = newTextFrame
        }
    
    
        newTextFrame.recompose();
        alert("Restored");
    }