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!
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
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.
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
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);
}
};
Copy link to clipboard
Copied
monica.L: code from SuperMerlin should do what I said.
Copy link to clipboard
Copied
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];
?