3

I'm working on a script which pastes my clipboard in every selected frame. After searching around I didn't figure out how to paste something into a frame (or polygon).

I'm stuck at something like this:

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

What should mySelection[i].contents = app.paste() be?

Malte
  • 454
  • 2
  • 5
  • 20

1 Answers1

1

Here's something that will help, based on another answer I provided not long ago. For this snippet to paste anything, you MUST HAVE SELECTED TEXT in your Document. That's how this snippet know where to 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");
}

Updated following comment: For this snippet I created an indesign document into which I created 2 objects. One object is a textBox into which I typed a bunch of text, and the second item is simply just a polygon I drew below the textBox. I did not set the content type of the polygon, I simply drew the polygon. In order to effectively find the pageItems I actually want and need, I used Script Labels, though using labels is not mandatory. As long as you have a mechanism to know you're dealing with the right object.

The idea behind this snippet is really simple:

  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();
blaze_125
  • 2,262
  • 1
  • 9
  • 19
  • With which command can I insert my clipboard directly **into** one polygon? E.g. I select a polygon, run the script and after that I've pasted a textframe into that polygon. – Malte Aug 28 '17 at 12:53
  • Thanks! The point was `app.pasteInto()` which I didn't know about. I was using `app.paste()` – Malte Aug 29 '17 at 07:41
  • @Malte, If you are using Adobe ExtendScript Toolkit, you can access the object model viewer with `F1` or `Help -> Object Model Viewer`. It's awful to navigate through, but most everything is there. – blaze_125 Aug 29 '17 at 12:50