• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Can a script determine number of lines in a paragraph?

Community Beginner ,
Oct 19, 2017 Oct 19, 2017

Copy link to clipboard

Copied

I found the exact same question in the InDesign scripting, but there is no such question in the photoshop scripting.

Generally, I have a textitem that I created in the script. I set up the length is 200px cause I know it would be the maximum. But generally I don't know how many lines are there. I need to know the total number of lines is because I will add extra textitem. By determine the height of my words, I would not overlay other textitems.

This is what I have so far.

if (app.activeDocument.activeLayer.kind == LayerKind.TEXT){

      var textItemRef = app.activeDocument.activeLayer.textItem;

      var content = textItemRef.contents;    //<--- the contents is already set up.

      textItemRef.contents = content.substring(1);

      //3. fix it to the paragraph

      textItemRef.kind = TextType.PARAGRAPHTEXT;

      textItemRef.width = UnitValue(150,"px");

      textItemRef.height = UnitValue(200,"px");

      var just = Justification.LEFT;

      activeDocument.activeLayer.textItem.justification = just;

      //4. fixed to the correct location

      textItemRef.position = new Array(pos[0], pos[1] );

     //5. should return lines number

     return textItemRef.lines??????

Thanks in advance!

TOPICS
Actions and scripting

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Oct 20, 2017 Oct 20, 2017

You need to have a text layer selected for this example...

#target photoshop;

if(app.activeDocument.activeLayer.kind == LayerKind.TEXT){

var aT = app.activeDocument.activeLayer.textItem; 

if (aT.kind == TextType.PARAGRAPHTEXT) {

aT.kind = TextType.POINTTEXT;

var tArray = aT.contents.split("\r");

var line = (tArray.length == 1) ? " line" : " lines";

executeAction( charIDToTypeID('undo'), undefined, DialogModes.NO );

alert (tArray.length+line);

}else{

var tArray = aT.contents.split("\r");

var line = (tAr

...

Votes

Translate

Translate
Adobe
Enthusiast ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

You could convert box text into non-box text. This will convert end of lines into break line characters and you can count these characters.

This works with entire layer. If you want only specific part of text layer... it will be harder.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

I didn't know my text is called "box text". Do you know how to convert it into "non-box text". Sorry, I'm really new to this. T_T

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

You need to have a text layer selected for this example...

#target photoshop;

if(app.activeDocument.activeLayer.kind == LayerKind.TEXT){

var aT = app.activeDocument.activeLayer.textItem; 

if (aT.kind == TextType.PARAGRAPHTEXT) {

aT.kind = TextType.POINTTEXT;

var tArray = aT.contents.split("\r");

var line = (tArray.length == 1) ? " line" : " lines";

executeAction( charIDToTypeID('undo'), undefined, DialogModes.NO );

alert (tArray.length+line);

}else{

var tArray = aT.contents.split("\r");

var line = (tArray.length == 1) ? " line" : " lines";

alert (tArray.length+line);

    }

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

monica.L: code from SuperMerlin should do what I said.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 21, 2017 Oct 21, 2017

Copy link to clipboard

Copied

LATEST

monica.L  написал(а)

By determine the height of my words, I would not overlay other textitems.

May be more useful is to determine hieight of total text in such way

text_height = app.activeDocument.activeLayer.bounds[3] - app.activeDocument.activeLayer.bounds[1];

?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines