Does anyone know of any scrips that splits text layers into separate lines?

I have one right now, but when it splits the layers it goes way too far down. Here's the code for the script that doesn't work if anyone can fix it or wants it:

doc = app.activeDocument;
layer = doc.activeLayer;

var text = layer.textItem.contents;
var textArray = text.split("\r");

var pos = layer.textItem.position;
var leading = 0;
if (layer.textItem.useAutoLeading){
        leading = layer.textItem.size/100*Math.round(layer.textItem.autoLeadingAmount)

    leading = Number(layer.textItem.leading)

layer.name = textArray[0]
for (var k=1; k<textArray.length;k++){
    tmp = layer.duplicate();
    tmp.textItem.position = [pos[0], pos[1]+(Number(leading)*k)] //I think this is whats causing the text to go crazy
    tmp.textItem.contents = textArray[k];
  • For what application? – Scott Sep 25 '19 at 6:33
  • @jvadi , Welcome to GDSE, at first it seems ou're using script for Illustrator but stills it's full of errors so please consider adding details about your situation and if possible add the source link of that code and mention about software as Scott mentioned. – Mr.Online Sep 25 '19 at 7:33
  • Yea: divideTextFrame.js. You might want to check his other scripts too, like joinTextFrames.js. – Joonas Sep 25 '19 at 10:03
  • 1
    Welcome to GD.SE - Please look through tour to get a sense of our community – who we are and what we’re about. Then look over How to Ask and How to Answer a question to see what makes a good query here, and how best to frame it. As initially posted your question is pretty unclear - which application you're scripting for, where the script came from, what you've tried and its results - Please read How to Ask and edit your question to better fit our guidelines. Thanks! – GerardFalla Sep 26 '19 at 16:33

Since the provided script is for Photoshop (there's a textItem), I'll go with Photoshop answer.

This script doesn't account for text scale: and if your text layer explodes this is probably because it was scaled. For some reason, there's an obscure property inside text layers in Photoshop that's used for calculations: basically if you've typed text in 15pt using 20 leading and scaled layer by 200%, Photoshop will show you that the text size is 30pt and leading is 40, but internally it's still 15pt with 20 leading, just multiplied by 2.

Here's an example to illustrate this: I used your script on both layers, the left one was initially typed in 30pt, the right one was typed in 15pt: script used the leading that's written in the layer, which is actually the same for both layers, so the distance between the lines is wrong in the right image:

enter image description here

Solutions are:

  • Retype your text in the size you need and use the script you have;
  • Use a script that accounts for hidden properties, I wasn't able to find one so I wrote it myself and it is a part of a free scripts pack;

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.