Skip to main content
Participating Frequently
April 25, 2012
Question

Preserve Bold & Italics while cut paste

  • April 25, 2012
  • 2 replies
  • 1613 views

hi,

I am trying to cut some text and paste into another location through scripting.  While pasting it,does'nt preserves the bold and

italic. All the text fall as a normal text only. Anybody tell me how to preserve the overrides(Bold and Italics) while pasting.

Thanks

Ranjan

This topic has been closed for replies.

2 replies

Community Expert
April 27, 2012

@Ranjan – instead of "cut" and "paste" you could use the move() method of the texts object of your source text frame or your selection, if text ist selected.

See screenshot:

See my snippet with annotations:

//In InDesign CS5.5 you can use the click order in the UI to determine

//what selected object is [0] and [1] etc.

//if you select two objects, [0] is the first one, [1] the second one.

//So to move formatted text from the left to the right text frame

//first click on the left text frame, hold shift and click on the right one

//before executing this code:

var sel = app.selection;

sel[0].texts[0].move(LocationOptions.AFTER,sel[1].insertionPoints[0]);

More generally spoken:

sourceTextFrame.texts[0].move(LocationOptions.AFTER,targetTextFrame.insertionPoints[0]);

You could also move selected text to another insertionPoint:

app.selection[0].texts[0].move(LocationOptions.AFTER,targetTextFrame.insertionPoints[0]);

Uwe

Peter Kahrel
Community Expert
Community Expert
April 25, 2012

You need to set Clipboard Handling in the preferences. You can do that in the interface (Edit > Preferences > Clipboard Handling), and you can probably set it in your script, too.

Peter

Participating Frequently
April 25, 2012

Hi Peter,

          I tried to do it manually. I set the clipboard handling paste to All information, but it wont work .I dont have idea how to set Clipboard Handling in the preferences through scripting.. Can you please tell me how to do it through scripting.

Thanks

Ranjan

Peter Kahrel
Community Expert
Community Expert
April 25, 2012

I don't know. You can find that in Jongware's object-model reference. It's in many posts in this forum, and Google will certainly find it.

Peter