3 Replies Latest reply: Jul 23, 2013 11:37 AM by Michael L Hale RSS

    "No Such Element". Intro to scripting.

    spdorsey6969 Community Member

      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!"

        • 1. Re: "No Such Element". Intro to scripting.
          Michael L Hale Community Member

          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!"

          • 2. Re: "No Such Element". Intro to scripting.
            spdorsey6969 Community Member

            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.

            • 3. Re: "No Such Element". Intro to scripting.
              Michael L Hale Community Member

              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.