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

Editing Existing Text Layer...

New Here ,
Jul 05, 2009 Jul 05, 2009

Hi,

I am running CS4 on Vista 64 bit and programming a PS script in Javascript...

I have trouble editing an existing layer in a .psd file that I open.

The script is fairly simple:

1. open .psd file

2. edit font size, content, alignment of the EXISTING text layer

     --> Note: this EXISTING text layer has an existing LAYER STYLE applied

3. close file

Everything works fine except part 2. The reason why I edit this EXISTING text layer is, b/c it is already exactly positioned where it needs to be and the desired layer style is already applied...

Here's what I tried :

I. I thought since the layer is already a TEXT LAYER there is no need to define the TEXT properties again - I used this code:

var textLayer = docRef.layers['text layer']; // define the existing text layer to a var
docRef.activeLayer = textLayer;

textLayer.font = '_Aviano-Regular';
textLayer.size = 36;
textLayer.style = "Regular";
textLayer.antiAliasMethod = AntiAlias.SHARP;
textLayer.contents = "test change";

--> Problem: the script runs without an error but the changes are NOT applied...

II. I defined the existing text layer to be a TEXT LAYER - I used this code:

var textLayer = docRef.layers['text layer']; // define the existing text layer to a var
docRef.activeLayer = textLayer;
textLayer.kind = LayerKind.TEXT;
var T1 = textLayer.textItem;
T1.font = '_Aviano-Regular';
T1.size = 36;
T1.style = "Regular";
T1.antiAliasMethod = AntiAlias.SHARP;
T1.contents = "test change";

--> Problem: this applies the changes, BUT the actual text font size applied is 120 (!!!) - I have to multiply with 0.3 to actually get to 36 and this does not work all the time.... very, very strange.... I'm assuming this has to do with that we redefine an EXISTING text layer as a text item...

III. I though about...:

1. creating a NEW text layer
2. applying all my properties

3. then position it at the exact position where the EXISTING text layer is located

Problem: the creation and the styles (properties) work fine, BUT when I get the coordinates through .bounds and when I apply the [0] and [1] values it does NOT match the position (too high).... applying the [0] and [3] values does NOT mtach either (too low)... do I need to split the difference between those two ???

Thanx for your help in advance !!!

- M

TOPICS
Actions and scripting
2.2K
Translate
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

Guru , Jul 06, 2009 Jul 06, 2009

The reason the text did not change in your first example is you are setting the font, size, etc prperties to the layer not the textItem. You corrected that in you next example.

When working with pixels you need to set the baseUnit if the doc is not 72 dpi. Something like this

UnitValue.baseUnit = UnitValue( (1/docRef.resolution),'in');// the default is 1/72
var textLayer = docRef.layers['text layer']; // define the existing text layer to a var
docRef.activeLayer = textLayer;
var T1 = textLayer.textIt

...
Translate
Adobe
Advisor ,
Jul 05, 2009 Jul 05, 2009

In CS3 and before the 'size' property was in points. And probably still defaults to points., so be explicit:

T1.size = UnitValue(36, 'pt');

or

T1.size = UnitValue(36, "px");

-X

Translate
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
New Here ,
Jul 05, 2009 Jul 05, 2009

xbytor2,

thank you for your answer

I did change the values to UnitValues and also I defined top of the page:

app.preferences.typeUnits = TypeUnits.PIXELS;
app.preferences.rulerUnits = Units.PIXELS;

... still no success I have to multiply with 0.3 to assign the values I want.

E.g. to apply a value of 36 px I actually assign a value of 10.8 px (--> 36 * 0.3) and the script will apply a value of 36 px to the existing text layer...

I have no idea why that is, but this is what it does...

Also, one thing that might be of interest, but I don't know how this could trigger this kind of behavior is, that I am running this script in a for() loop...

I have so many images and names to process that I am running it in a for() loop...

All temp vars (processed in each loop) are being nulled at the end of each loop and then redefined with new values every loop...

I have tested the script without the loop and the text font size var still needs to be adjusted by 0.3....

Any ideas ?

- M

Translate
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
Advisor ,
Jul 06, 2009 Jul 06, 2009

Change the doc's resolution to 72ppi. That way pts=pxls.

Translate
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
Guru ,
Jul 06, 2009 Jul 06, 2009

The reason the text did not change in your first example is you are setting the font, size, etc prperties to the layer not the textItem. You corrected that in you next example.

When working with pixels you need to set the baseUnit if the doc is not 72 dpi. Something like this

UnitValue.baseUnit = UnitValue( (1/docRef.resolution),'in');// the default is 1/72
var textLayer = docRef.layers['text layer']; // define the existing text layer to a var
docRef.activeLayer = textLayer;
var T1 = textLayer.textItem;
T1.font = '_Aviano-Regular';
T1.size = UnitValue( 36,'px');
T1.style = "Regular";
T1.antiAliasMethod = AntiAlias.SHARP;
T1.contents = "test change";

The size will now be 36 pixels. If you don't want to change the baseUnit you could change the resolution as Xbytor suggested.

Also if you want to match the position of a text layer, use the textItem.position property instead of the layer bounds.

Translate
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
New Here ,
Jul 06, 2009 Jul 06, 2009

Xbytor & Michael,

setting the doc's resolution to 72 dpi and the setting the UnitValue.baseUnit solved the problem...

The resolution of the docs was 300 dpi before that, that's why the font size changed to a different value than the one applied...

Thanx for your help !!!

- M

Translate
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
Guru ,
Jul 07, 2009 Jul 07, 2009
LATEST

Iron_Mike wrote:

setting the doc's resolution to 72 dpi and the setting the UnitValue.baseUnit solved the problem...

Just so it's clear. You only need to do one or the other. When the resolution is 72 dpi the baseUnit's default value is the correct value. It only needs to be changed when the dpi is not 72.

Translate
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