Skip to main content
Known Participant
March 4, 2011
Answered

How to get color info of text in Text Layer?

  • March 4, 2011
  • 1 reply
  • 2927 views

How to get color info of text in Text Layer?  I mean using Photoshop Scripting ,  Version of Photoshop  is  CS 8.0

This topic has been closed for replies.
Correct answer Michael_L_Hale

I am sure there is a text layer named "标题"! 

PS: a few days ago , I read the Photoshop cs2 VisualBasic Reference Guide,  the TextItem object have a  Color property, Read-Write.  but  when i test on computer, it says Color property only write  can't read.  


The textItem color is readable for me in VBS Note expects the activeLayer to be a textLayer and displays the HexValue of the text's color.

Option Explicit

Dim appRef
Dim docRef
Dim textItemRef
Dim artLayerRef
Dim textColor

Set appRef = CreateObject( "Photoshop.Application" )

appRef.BringToFront

Set docRef = appRef.ActiveDocument
Set artLayerRef = docRef.ActiveLayer
Set textItemRef = artLayerRef.TextItem
Set textColor = textItemRef.Color

MsgBox textColor.RGB.HexValue

And will return the color of the text if all the text is the same color. But if the text is more than one color textItem.color only returns the color of the first text range.

1 reply

Inspiring
March 4, 2011

I can't text this in Photoshop CS but it should work. It also returns more info than you requested but shows how to get the text color.

///////////////////////////////////////////////////////////////////////////////
// Function: getFontInfo
// Description: Gets info about font for all textranges
// Usage: getFontInfo() works on activeDocument.activeLayer
// Input: None
// Return: Array. array[idx] = info for textRange idx
///////////////////////////////////////////////////////////////////////////////
function getFontInfo(){
var ref = new ActionReference();
     ref.putEnumerated( stringIDToTypeID( "layer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ));
var desc= executeActionGet( ref )
var list =  desc.getObjectValue(charIDToTypeID("Txt ")) ;
var tsr =  list.getList(charIDToTypeID("Txtt")) ;
var info = new Array;
for(var i = 0;i<tsr.count;i++){
     var tsr0 =  tsr.getObjectValue(i) ;
     var from = tsr0.getInteger(charIDToTypeID("From"));
     var to = tsr0.getInteger(charIDToTypeID("T   "));
     var range = [from,to];
     var textStyle = tsr0.getObjectValue(charIDToTypeID("TxtS"));
     var font = textStyle.getString(charIDToTypeID("FntN" ));
     var size = textStyle.getDouble(charIDToTypeID("Sz  " ));
     var color = textStyle.getObjectValue(charIDToTypeID('Clr '));
     var textColor = new SolidColor;
          textColor.rgb.red = color.getDouble(charIDToTypeID('Rd  '));
          textColor.rgb.green = color.getDouble(charIDToTypeID('Grn '));
          textColor.rgb.blue = color.getDouble(charIDToTypeID('Bl  '));
     info.push([range,font,size, textColor.rgb.hexValue]);
     }
return info;
}     

var info = getFontInfo();
alert("there are "+info.length+" textRanges\rRange 1 details\rRangeStart "+info[0][0][0]+", rangeEnd:"+info[0][0][1]+", Font:"+info[0][1]+", size:"+info[0][2]+", colorHexValue:"+info[0][3]);

leezjnuAuthor
Known Participant
March 5, 2011

Thank you  ! I test it on Photoshop cs  , it works well. But a little sad, I want to use VbScript not JScript, Could you help me do this?  I can't  change this

Inspiring
March 5, 2011

Sorry, I only know a little VBS. Enough to know that the same thing can be done with VBS as it is almost all action manager code.