Skip to main content
Inspiring
March 7, 2018
Answered

Display the location of an item in a project.

  • March 7, 2018
  • 1 reply
  • 495 views

I have multiple text layers and fonts in my project. In various comps.
I want to be able to scan through the project and then show all of the locations that a specific font is used.

I used for loops for all the scanning and am able to get that far, but i want to display a list of all of the places a font is used. Any help is appreciated.

My goal is to get an alert box with something like:

Font used in:

1. ThisComp > This Layer

2. ThisComp > This Layer

3. ThisComp > This Layer

4. ThisComp > This Layer

etc.

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

This snippet gets the fontFamily of selected text layer. Then loops through all the compositions in the project and collects all layers that matche fontFamily.

I hope this is something you were looking for.

(function() {

    // Get active composition

    var composition = app.project.activeItem;

    if (!composition || !isComposition(composition))

        return alert("Please select composition first");

    // Get selected layer and make sure it's a Text Layer

    var layer = composition.selectedLayers[0];

    if (!layer || !isTextLayer(layer)) {

        return alert("Please select a text layer.");

    }

    // Get font family

    var fontFamily = getFontFamily(layer);

    var layersThatMatchFontFamily = [];

    // Loop through all the comps and collect all text layers

    // witch matches fontFamily;

    var allCompositions = getAllCompositions();

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

        composition = allCompositions;

        for (var j = 1, jl = composition.numLayers; j <= jl; j++) {

            layer = composition.layer(j);

            if (isTextLayer(layer) && getFontFamily(layer) === fontFamily) {

                layersThatMatchFontFamily.push(layer);

            }

        }

    }

    // Done.

    var message = "Font \"" + fontFamily + "\" has been used " + layersThatMatchFontFamily.length + " times.\n";

    message += buildLocation(layersThatMatchFontFamily).join("\n");

    alert(message);

    function isTextLayer(layer) {

        return layer instanceof TextLayer;

    }

    function isComposition(item) {

        return item instanceof CompItem;

    }

    function getFontFamily(textLayer) {

        var textDocument, textValue, fontFamily;

        textDocument = textLayer.property("ADBE Text Properties").property("ADBE Text Document");

        textValue = textDocument.value;

        fontFamily = textValue.fontFamily;

        return fontFamily;

    }

    function getAllCompositions() {

        var composition, compositions;

        compositions = [];

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

            composition = app.project.item(i);

            if (isComposition(composition)) {

                compositions.push(composition);

            }

        }

        return compositions;

    }

    function buildLocation(layers) {

        var layer, locations;

        locations = [];

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

            layer = layers;

            locations.push(layer.containingComp.name + " > " + layer.name);

        }

        return locations;

    }

})();

1 reply

Tomas Sinkunas
Legend
March 7, 2018

Do you need something custom, that you would use in your script?

Or are you asking in general? If so, have you looked at pt_TextEdit 2 - aescripts.com  witch sounds to be related to your question.

Inspiring
March 7, 2018

i preferred my own version, im building it as part of a larger panel.

Tomas Sinkunas
Tomas SinkunasCorrect answer
Legend
March 8, 2018

This snippet gets the fontFamily of selected text layer. Then loops through all the compositions in the project and collects all layers that matche fontFamily.

I hope this is something you were looking for.

(function() {

    // Get active composition

    var composition = app.project.activeItem;

    if (!composition || !isComposition(composition))

        return alert("Please select composition first");

    // Get selected layer and make sure it's a Text Layer

    var layer = composition.selectedLayers[0];

    if (!layer || !isTextLayer(layer)) {

        return alert("Please select a text layer.");

    }

    // Get font family

    var fontFamily = getFontFamily(layer);

    var layersThatMatchFontFamily = [];

    // Loop through all the comps and collect all text layers

    // witch matches fontFamily;

    var allCompositions = getAllCompositions();

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

        composition = allCompositions;

        for (var j = 1, jl = composition.numLayers; j <= jl; j++) {

            layer = composition.layer(j);

            if (isTextLayer(layer) && getFontFamily(layer) === fontFamily) {

                layersThatMatchFontFamily.push(layer);

            }

        }

    }

    // Done.

    var message = "Font \"" + fontFamily + "\" has been used " + layersThatMatchFontFamily.length + " times.\n";

    message += buildLocation(layersThatMatchFontFamily).join("\n");

    alert(message);

    function isTextLayer(layer) {

        return layer instanceof TextLayer;

    }

    function isComposition(item) {

        return item instanceof CompItem;

    }

    function getFontFamily(textLayer) {

        var textDocument, textValue, fontFamily;

        textDocument = textLayer.property("ADBE Text Properties").property("ADBE Text Document");

        textValue = textDocument.value;

        fontFamily = textValue.fontFamily;

        return fontFamily;

    }

    function getAllCompositions() {

        var composition, compositions;

        compositions = [];

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

            composition = app.project.item(i);

            if (isComposition(composition)) {

                compositions.push(composition);

            }

        }

        return compositions;

    }

    function buildLocation(layers) {

        var layer, locations;

        locations = [];

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

            layer = layers;

            locations.push(layer.containingComp.name + " > " + layer.name);

        }

        return locations;

    }

})();