InDesign 脚本:粘贴到框架中

InDesign scripts: paste into frames

我正在编写一个脚本,它将我的剪贴板粘贴到每个选定的帧中。四处搜索后,我没有弄清楚如何将内容粘贴到框架(或多边形)中。

我遇到了这样的问题:

function pasteSelection(mySelection) {
    for (var i = mySelection.length - 1; i > -1; i--) {
        mySelection[i].contents = app.paste();
    }
}

mySelection[i].contents = app.paste() 应该是什么?

根据 ,这里有一些有用的东西。要让此片段粘贴任何内容,您必须在文档中选择文本。这就是此代码段知道粘贴位置的方式。

var myDoc = app.activeDocument;

if(app.documents.length != 0){
    if(app.selection.length == 1){
        try{           
            var frame1 = app.selection[0];
            frame1 = app.paste();//works
            //app.pasteWithoutFormatting(frame1);;works too
         }
        catch(e){
            alert ("Exception : " + e, "Exception");
        }
    }
 else{
    alert ("Please select text", "Selection");
  }  
}
else{
    alert("Something wrong");
}

更新了以下评论: 对于这个片段,我创建了一个 indesign 文档,我在其中创建了 2 个对象。一个对象是一个文本框,我在其中键入了一堆文本,第二个对象只是我在文本框下方绘制的一个多边形。我没有设置多边形的内容类型,我只是简单地绘制了多边形。为了有效地找到我真正想要和需要的 pageItems,我使用了 Script Labels,尽管使用标签不是强制性的。只要你有一种机制知道你正在处理正确的对象。

这段代码背后的想法非常简单:

  1. Select the Source object
  2. Copy the selected object
  3. Select the Destination object
  4. Paste into the selected object

.

var myDoc = app.activeDocument;
var source;
var destination;

for(var i = 0; i < myDoc.pageItems.length; i++)
{
    if(myDoc.pageItems[i].label == "source") 
    {
        source = myDoc.pageItems[i];
        app.selection = myDoc.pageItems[i];
        app.copy();
        }
    else if(myDoc.pageItems[i].label == "destination")
    {
        destination = myDoc.pageItems[i];
        }

    if(source !== undefined && destination !== undefined)
    {
        break;
        }
}
app.selection = destination;
app.pasteInto();