Skip to main content
Inspiring
February 11, 2022
Answered

Split sentence words to a single text column

  • February 11, 2022
  • 1 reply
  • 775 views

Script at this post works fine for breaking a single line text  words seperated with a space character,  and turn it into a text column

https://community.adobe.com/t5/photoshop-ecosystem-discussions/i-want-to-break-the-text-with-a-space

How  it can be adpted to tiurn senence to into a text column ?

CIRCLE TRIANGLE SQUARE RECTANGLE
OVAL SEMICIRCLE PARALLELOGRAM DIAMOND
TRAPEZOID STAR CROSS ARROW
PENTAGON HEXAGON OCTAGON DECAGON

to this

CIRCLE
TRIANGLE
SQUARE
RECTANGLE
OVAL
SEMICIRCLE
PARALLELOGRAM
DIAMOND
TRAPEZOID
STAR
CROSS
ARROW
PENTAGON
HEXAGON
OCTAGON
DECAGON
This topic has been closed for replies.
Correct answer Kukurykus

Yout code is fine, the split by letter occurs at next lines of my code!

I am trying to find where

doc = app.activeDocument;
layer = doc.activeLayer;
var text = layer.textItem.contents;
var textArray = text.split(/ |\r/).join('\n');
var pos = layer.textItem.position;
var textFontHeight = layer.textItem.size;
var pos0 = parseInt(layer.textItem.position[0]);
var pos1 = parseInt(layer.textItem.position[1]);
layer.textItem.contents=textArray[0]
layer.name = textArray[0]

for (var k=1; k<textArray.length;k++){
	newtextFontHeight = textFontHeight * k ; 
tmp = layer.duplicate();
tmp.textItem.position = [pos0,pos1 + newtextFontHeight];
tmp.textItem.contents = textArray[k].toString();

}

 


 

with(activeDocument.activeLayer.textItem)
	contents = contents.split(/ |\r/).join('\r')

 

Or if you want something else then change one line in your code to:

 

var textArray = text.split(/ |\r/)//.join('\r');

 

1 reply

Kukurykus
Legend
February 11, 2022

You probably meant: I want to break the text with a space character and turn it into a text column.

 

txt = '''CIRCLE TRIANGLE SQUARE RECTANGLE
OVAL SEMICIRCLE PARALLELOGRAM DIAMOND
TRAPEZOID STAR CROSS ARROW
PENTAGON HEXAGON OCTAGON DECAGON'''

txt.split(/ |\r/).join('\n')
siomospAuthor
Inspiring
February 11, 2022

Thank you @Kukurykus 

yes i meant the script at your link!

About your code, it is splitting every letter, not every word!

 

 

Kukurykus
Legend
February 11, 2022

I used it on the text you posted so that is no possible it does what you showed, as there are no spaces between letters but only words. Try it on the text taken from forum and see it yourself.