Skip to main content
spdorsey6969
Inspiring
July 22, 2013
Answered

"No Such Element". Intro to scripting.

  • July 22, 2013
  • 1 reply
  • 2868 views

Okay...

  Here's my basic script. Cut and pasted from Adobe's Intro to Scripting PDF for CS5. I run it and it produces a "No such element" error in line #2. I want to understand why the very first script that Adobe tells me to use in its Intro to Scripting tutorial does not work properly. Is this my fault? Is there something they assume I already know that leads this script to fail?

thanks.

var myDoc = app.documents.add()

var myLayer = myDoc.layers.add()

var myTextFrame = myLayer.textFrames.add()

     myTextFrame.contents = "Hello world!"

This topic has been closed for replies.
Correct answer Michael_L_Hale

If you look at that PDF again you will see that you copied an Illustrator script. Each app has it's own Object Model. There are some overlaps but you are better off using the Photoshop JavaScript Ref.PDF for the Photoshop Object Model. For example Photoshop layers doesn't have an add method, only artLayers and layerSets have it. And Photoshop doesn't have a textFrame class. Instead it has artLayers with the kind property set to LayerKind.TEXT.

Here is how you could do the same thing in Photoshop.

var myDoc = app.documents.add();

var myLayer = myDoc.artLayers.add();

myLayer.kind = LayerKind.TEXT;

myLayer.textItem.contents = "Hello world!"

1 reply

Michael_L_HaleCorrect answer
Inspiring
July 23, 2013

If you look at that PDF again you will see that you copied an Illustrator script. Each app has it's own Object Model. There are some overlaps but you are better off using the Photoshop JavaScript Ref.PDF for the Photoshop Object Model. For example Photoshop layers doesn't have an add method, only artLayers and layerSets have it. And Photoshop doesn't have a textFrame class. Instead it has artLayers with the kind property set to LayerKind.TEXT.

Here is how you could do the same thing in Photoshop.

var myDoc = app.documents.add();

var myLayer = myDoc.artLayers.add();

myLayer.kind = LayerKind.TEXT;

myLayer.textItem.contents = "Hello world!"

spdorsey6969
Inspiring
July 23, 2013

Oh wow. I didn't even see that. Thanks.

I can see how your script works. I think the hardest part of this is going to be learning the syntax. I'm bad with languages.

I appreciate the reply.

Inspiring
July 23, 2013

It can take a while to learn what 'something.somethingElse.somethingDifferent' means.But it really isn't that hard and I think you will find it easy to learn with a little practice.

So in a Photoshop script;

app means the Photoshop object( the program itself )

app.documents means the documents property of app. That contains a collection of document object.

app.documents.add() means the add method of documents. It is used to create a new document( add to the documents collection ). Note add does except arguments so you can control how the document is created.

artLayers is a docment object property that contains a collection of artLayer in the document. Note that a document object will also have  layers and layerSets properties. layerSets is a collection of  layerSet objects and layers is a collection that has both artLayer and layerSets objects.

artLayer.add() adds an artLayer. It doesn't have any arguments so you can't set the type of layer when creating.

artLayer.kind is a property for the layer's type. Using the Object Model you can only set the kind property to text and then only with an empty layer.

artLayer.textItem is property only a text layer will have. There you can set the contents, font, color, position, etc for the text layer.