CS5 Scripting (JavaScript): Changing Text in a Text Layer?

Started by G_G, January 28, 2011, 06:23:12 pm

Previous topic - Next topic

G_G

Because of my ultimate lazyness I decided to make a script for photoshop to make my work a lot faster.

I have a button with two text layers. I'm basically trying to make a script where it makes both text layers invisible, then sets the first one visible, change the text, export it as text_off.png then turn off the layer and turn the second layer on and do the same thing except saving it would be text_on.png.

I've been digging into the Object Model Viewer and found out that an artLayer contains a textItem which contains the variable I need to change. However apparently the document thats open doesn't have any art layers as I keep getting an undefined error when I call document.ArtLayers. A normal layer doesn't have a TextItem variable.

Any ideas?

Oh and the fact that I grab the layer.
layer = document.layers[0];
alert(layer.typename);


Guess what it prints out? ArtLayer. Then when I try this.
layer.textitem.contents = "Hello"; // Get an error
alert(layer.textitem); // Prints undefined
alaert(layer.kind); // Prints LayerKind.TEXT


And under Object Model Viewer it says the ArtLayer has a text item and I know for a fact that the layer I'm dealing with is indeed the text layer. It makes no sense D: