• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Recognize a data footage item

Advocate ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

How would i go to recognize a FootageItem that corresponds to a data file ?

I have one way, check its associated mainSource.file extension (.json etc), but is there another ?

(That way could become invalid if new extensions are accepted in the future).

Likewise, the data layers are AV Layer much similar to nulls, but they have nullLayer=false.

Is there a quick way to recognize them ?

TOPICS
Scripting

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

I have this function that establishes a fake enum-style type-- right now doesn't account for json, but would be easy to integrate. If I were working in another format I'd declare the enum properly (as opposed to strings), but this idea works!

  /**

   * Analyzes project item and returns a fake enum of item type

   *

   * @param {Item} item Project item to check

   * @returns {string}  Fake enum of item type

   */

  function getItemType(item) {

    /**

     * Checks whether an item is C4D Footage

     *

     * @param {FootageSource} footageSource Footage source to check

     * @returns {boolean}                   Whether item is c4d footage

     */

    function isC4DFootage(footageSource) {

      var extension = aeq.file.getExtension(footageSource.file);

      return extension.toLowerCase() === 'c4d';

    }

    /**

     * Checks whether an item is still footage

     *

     * @param {FootageSource} footageSource Footage source to check

     * @returns {boolean}                   Whether item is still footage

     */

    function isStillFootage(footageSource) {

      var importedItem = aeq.importFile(footageSource.file);

      var importIsImage = importedItem.isStill;

      importedItem.remove();

      return importIsImage;

    }

    if (item instanceof CompItem) {

      return 'ItemType.Comp';

    }

    if (item instanceof FolderItem) {

      return 'ItemType.Folder';

    }

    if (!(item instanceof FootageItem)) {

      return 'ItemType.UNDEFINED';

    }

    var footageSource = item.mainSource;

    if (footageSource instanceof SolidSource) {

      return 'ItemType.Solid';

    }

    if (footageSource instanceof PlaceholderSource) {

      return 'ItemType.Placeholder';

    }

    if (isC4DFootage(footageSource)) {

      return 'ItemType.C4D';

    }

    if (item.hasVideo) {

      if (footageSource.isStill) {

        return 'ItemType.Image';

      }

      if (item.hasAudio) {

        return 'ItemType.VideoWithAudio';

      }

      if (isStillFootage(footageSource)) {

        return 'ItemType.ImageSequence';

      }

      return 'ItemType.Video';

    }

    if (item.hasAudio) {

      return 'ItemType.Audio';

    }

    return 'ItemType.UNDEFINED';

  }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

I havent tried due the aeq thing, but i think your function would return 'ItemType.Image'.

And to make it return something correct, one would have to write a function similar to your isC4DFootage(), that inspects file extension.

This is what i would like to avoid !

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

I am on an earlier version of AE, but what about the data driven expressions, ie. creating a dummy expression for (.sourceData) and testing if it throws an error ?  Not sure if .sourceData is implemented in the object model or just available in expressions (as not on that version of AE yet.)

Data-driven animation (expression reference)

Expression methods:

  • Footage sourceText attribute {footageItem}.sourceText Returns the contents of a .JSON file as a string. The eval() method can be used to convert the string to an array of sourceData objects, identical to the results of the sourceData attribute, from which the individual data streams can be referenced as hierarchal attributes of the data. For example:

var myData = eval(footage("sample.json").sourceText);myData.sampleValue;Type:String, the contents of the .JSON file; read-only.

  • Footage sourceData attribute {footageItem}.sourceData Returns the data of a .JSON file as an array of sourceData objects. The structure of the .JSON file will determine the size and complexity of the array. Individual data streams can be referenced as hierarchal attributes of the data. For example, given a data stream named Color, the following will return the value of Color from the first data object: footage("sample.json").sourceData[0].Color

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

Modifying a layer or property to guess what it is... Not great.

If ever you need it, the matchName of the data group is "ADBE Data Group".

So :

myLayer.data;

or :

myLayer.property("ADBE Data Group");

It is an indexed group, and all of its nested properties have auto-generated matchNames.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

LATEST

ok, so, if someones needs it, here is a way:

The list of allowed file types can be found there: https://helpx.adobe.com/after-effects/using/data-driven-animations.html

const re_datafileAllowedExtensions = /\.(json|mgjson|csv|tsv|txt|jsx)$/i;

function isDataItem(item){

    return (item instanceof FootageItem) && (item.file instanceof File) && (re_datafileAllowedExtensions.test(item.file.displayName));

    };

function isDataLayer(layer){

    return isDataItem(layer.source);

    };

For layers, the test (layer instanceof AVLayer) && (layer.data.numProperties>0) would work most of the time, except if the associated data file is empty or carries an empty json object ({});

Edit : forgot .jsx in the list. A .jsx footage can be added as a layer, but whatever it contains the layer data group remains empty.

Xavier

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines