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 ?
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';
}
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 !
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.)
Expression methods:
var myData = eval(footage("sample.json").sourceText);myData.sampleValue;Type:String, the contents of the .JSON file; read-only.
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.
Copy link to clipboard
Copied
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