Skip to main content
February 6, 2017
Answered

How can I rotate all the text layers in a PSD document by Java Script

  • February 6, 2017
  • 3 replies
  • 1758 views

How can I rotate all the text layers in a PSD document by Java Script, Instead of, rotate the text layers one by one.

This is a pressing problem in the Engineering plan drawing. Thanks anyway!

                                                           by a Green hand

This topic has been closed for replies.
Correct answer Tomas Sinkunas

Hi buddy.

Try this script. Define the angle you want to rate and you should be good.

// Rotate all text layer by a given angle.

// Script by Tomas Sinkunas www.rendertom.com

(function(){

    #target photoshop

    // Define the angle.

    var angle = 180;

  

    // Collect all text layers in the document

    var textLayers = getTextLayers(app.activeDocument);

    // Loop through all text layers in the document

    for (var t = 0, tl = textLayers.length; t < tl ; t ++) {

        // Rotate the layer

        textLayers.rotate (angle, AnchorPosition.MIDDLECENTER);

    }

    function getTextLayers (doc, layers) {

        layers = layers || [];

        for (var i = 0, il = doc.layers.length; i < il; i ++) {

            if (doc.layers.typename == "LayerSet") {

                getTextLayers(doc.layers, layers)

            } else {

                if (doc.layers.kind == "LayerKind.TEXT") {

                    layers.push(doc.layers)

                }

            }

        }

        return layers

    }

})();

3 replies

Tomas Sinkunas
Tomas SinkunasCorrect answer
Brainiac
February 6, 2017

Hi buddy.

Try this script. Define the angle you want to rate and you should be good.

// Rotate all text layer by a given angle.

// Script by Tomas Sinkunas www.rendertom.com

(function(){

    #target photoshop

    // Define the angle.

    var angle = 180;

  

    // Collect all text layers in the document

    var textLayers = getTextLayers(app.activeDocument);

    // Loop through all text layers in the document

    for (var t = 0, tl = textLayers.length; t < tl ; t ++) {

        // Rotate the layer

        textLayers.rotate (angle, AnchorPosition.MIDDLECENTER);

    }

    function getTextLayers (doc, layers) {

        layers = layers || [];

        for (var i = 0, il = doc.layers.length; i < il; i ++) {

            if (doc.layers.typename == "LayerSet") {

                getTextLayers(doc.layers, layers)

            } else {

                if (doc.layers.kind == "LayerKind.TEXT") {

                    layers.push(doc.layers)

                }

            }

        }

        return layers

    }

})();

February 7, 2017

Tanks anyway!  I will have a tray. in addition,  I learn JS just a short time, So, I must Try and Try ...

JJMack
Community Expert
February 6, 2017

It relatively easy to process all text layers in a document with a script.  However, rotating text layers well may be hard. Text can be a line or paragraph rotation can be done from any rotation point and can rotate text off canvas.  Text can be very complex to deal with.

JJMack
February 7, 2017

In the same way, rotate all the text layers whithin one document will be easy in AutoCAD software. But Adobe Photoshop Is another case. Maybe, Adobe Corp should deliberate what to do tomorrow.......

Benjamin Root
Brainiac
February 6, 2017