Skip to main content
Participating Frequently
February 27, 2017
Question

Editting CopyCutter to break at hard returns?

  • February 27, 2017
  • 3 replies
  • 1086 views

So I wanted to do what this guy wanted in this thread and break a long frame of text down to multiple text frames based on hard returns and he was told to use Copycutter and it seemed to work for him but I can only get it to create new text frames at each space not hard turn. I can't figure out how to read the script to change it. Could anyone help me please?

//DESCRIPTION:CopyCutter -- Run Me On A Text Frame To Shred It Into Strips

// A Jongware script 7-Aug-2011

// w/Thanks to SebastiaoV to find a working version

if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline") && app.selection[0].length > 1)

{

  app.selection[0].insertionPoints[0].contents = "\r";

  app.selection[0].insertionPoints[-1].contents = "\r";

  app.findGrepPreferences = null;

  app.changeGrepPreferences = null;

  app.findGrepPreferences.findWhat = " +";

  app.changeGrepPreferences.changeTo = "\\r";

  app.selection[0].changeGrep();

  p = app.selection[0].parentTextFrames[0];

  lh = (p.lines[-1].baseline - p.lines[0].baseline) / (p.lines.length-1);

  top = app.selection[0].lines[0].baseline - lh;

  while (app.selection[0].length > 0)

  {

  f = app.activeDocument.layoutWindows[0].activePage.textFrames.add ({geometricBounds:[top, p.geometricBounds[3]+2*lh, top+lh, 2*(lh+p.geometricBounds[3])-p.geometricBounds[1] ]});

  app.selection[0].lines[0].move (LocationOptions.AFTER, f.texts[0]);

  top += lh;

  }

  app.selection[0].insertionPoints[-1].contents = "";

} else

  alert ("please select some text to shred");

This topic has been closed for replies.

3 replies

Jongware
Community Expert
Community Expert
February 27, 2017

Ah that script again. Yeah ... unfortunately, it proves to be popular to lots of people – but everyone and his aunt seems to have slightly different demands, and so there are lots and lots of edited versions floating around. This one doesn't really look like mine as I remember it – it slices everything into words, rather than lines.

I've found what appears to be the original proto-version online (well, a v.2) in the archives of Fabian (thank you!) on Github IDSnippets/splitTextFrame.jsx at master · fabianmoronzirfas/IDSnippets · GitHub , and this one does look a lot like the original. It does not depend on 'spaces' or 'returns', it literally slices and dices a frame into the actual lines that you currently see in that text frame. It does not rely on findGrep, it merely iterates over the current text lines, not matter for what reason they wrap to a new line. You can see that if one of the lines end with a soft hyphen, the line will be broken at that point (although the soft hyphen itself is not saved, because according to the Document Model there never was one to begin with).

This should be good for you:

//DESCRIPTION:CopyCutter 2 — Cut your Copy into Slivers

// Jongware, 3-Jun-2010

if (app.selection.length == 1 && app.selection[0] instanceof TextFrame)

{

  f = app.selection[0];

  for (i=0; i<f.lines.length; i++)

  {

  newf = f.duplicate();

  newf.texts[0].remove();

  f.lines.duplicate (LocationOptions.BEFORE,newf.lines[0]);

  if (i > 0)

  top = f.lines[i-1].baseline;

  else

  top = f.geometricBounds[0];

  bot = f.lines.baseline;

  newf.geometricBounds = [ top, f.geometricBounds[1], bot, f.geometricBounds[3] ];

  }

  f.remove();

}

Participating Frequently
February 27, 2017

That new code gives me this error

Community Expert
February 28, 2017

Hi Cody,

you did not copy all of the code.

The last closing } is perhaps missing in your script file.

Regards,
Uwe

Mike Witherell
Community Expert
Community Expert
February 27, 2017

Then I suppose I would do a Find/Change for \n soft returns and replace them with spacebar spaces; ... then run the script where you removed the two lines.

Mike Witherell
Participating Frequently
February 27, 2017

Oh i hope it doesn't come to that, I have 25 pages of size 9 font to do.......

Mike Witherell
Community Expert
Community Expert
February 27, 2017

Did you try taking out lines 12 and 13?

Mike Witherell
Participating Frequently
February 27, 2017

Nope cause I dunno how to read this type of script , but i'll try that now!