Skip to main content
Henrique_Rude
Participant
August 23, 2017
Question

Create and delete text layer

  • August 23, 2017
  • 1 reply
  • 992 views

Hello.

I've searched the web upside down searching for a script that would do the following:

In the first script would be for text creation and searching I was able to find how to create a script, but it only creates in a composition. How do I create in all compositions?

{

activeComp = app.project.activeItem;

T = activeComp.layers.addText ();

T.name = "COMPOSITION";

T.startTime = 0;

T.outPoint = activeComp.duration;

T.text.sourceText.expression = "thisComp.name";

T.transform.position.setValue ([40,82,0]);

T.locked = true;

}

The second script would be delete in all the compositions the layer text created above.

If anybody can provide a script that would be such a thing - it would be highly appreciated.

Regards,

Hernrique

This topic has been closed for replies.

1 reply

Tomas Sinkunas
Legend
August 23, 2017

Here's two options in one script. Main function will loop through all the items in the project to find compositions. If composition is found, it will execute function and will pass projectItem as an argument. Make sure to uncomment one you need.

Function addTextLayer(composition) will add a text layer that has custom comment "myTextLayer" and label = 0, so we can find this layer later.

Function removeTextLayer(composition) will loop through all the layers in composition to find a layer, that has comment "myTextLayer" and label = 0. Once it's found, it will remove it.

Enjoy.

(function () {

    try {

        app.beginUndoGroup("This is great");

       

        var projectItem;

        for (var i = 1, il = app.project.numItems; i <= il; i ++) {

            projectItem = app.project.item(i);

            if (projectItem instanceof CompItem) {

                // addTextLayer(projectItem);

                // removeTextLayer(projectItem);

            }

        }

        app.endUndoGroup();

    } catch (e) {

        alert(e.toString() + "\nScript File: " + File.decode(e.fileName).replace(/^.*[\|\/]/, '') +

            "\nFunction: " + arguments.callee.name +

            "\nError on Line: " + e.line.toString());

    }

    function addTextLayer(composition) {

        var textLayer = composition.layers.addText();

        textLayer.name = "COMPOSITION";

        textLayer.startTime = 0;

        textLayer.outPoint = composition.duration;

        textLayer.text.sourceText.expression = "thisComp.name";

        textLayer.transform.position.setValue([40, 82, 0]);

        textLayer.comment = "myTextLayer";

        textLayer.label = 0;

        textLayer.locked = true;

    }

    function removeTextLayer(composition) {

        var layer;

        for (var i = 1, il = composition.numLayers; i <= il; i ++) {

            layer = composition.layer(i);

            if (layer.comment === "myTextLayer" && layer.label === 0) {

                layer.locked = false;

                layer.remove();

            }

        }

    }

})();