Skip to content

Instantly share code, notes, and snippets.

@zlovatt
Last active May 29, 2024 04:48
Show Gist options
  • Save zlovatt/bbb10f88d23c1500754caf9388abdf6c to your computer and use it in GitHub Desktop.
Save zlovatt/bbb10f88d23c1500754caf9388abdf6c to your computer and use it in GitHub Desktop.
ExtendScript: Get AE Layer Type
(function getSelectedLayerType() {
/**
* Gets the type of a given layer
*
* @param {Layer} layer Layer to check
* @return {string} Layer type
*/
function getLayerType(layer) {
switch (layer.matchName) {
case "ADBE Vector Layer":
return layer.matchName;
case "ADBE Text Layer":
return layer.matchName;
case "ADBE Camera Layer":
return layer.matchName;
case "ADBE Light Layer":
return layer.matchName;
case "ADBE AV Layer":
if (layer.nullLayer === true) {
return "Null";
} else if (layer.adjustmentLayer === true) {
return "Adjustment";
} else if (layer.guideLayer === true) {
return "Guide";
} else if (layer.source instanceof CompItem) {
return "Precomp";
} else if (layer.source.mainSource instanceof SolidSource) {
return "Solid";
} else if (layer.source.mainSource instanceof PlaceholderSource) {
return "Placeholder";
} else if (layer.source.mainSource instanceof FileSource) {
if (layer.source.footageMissing == true) {
return "Missing Footage";
}
var priorLayerState = layer.enabled;
layer.enabled = true;
var importIsData = layer.enabled == false;
layer.enabled = priorLayerState;
if (importIsData) {
return "Data";
}
if (!layer.source.hasVideo && layer.source.hasAudio) {
return "Audio";
}
return "Image";
}
return "Invalid";
}
}
var comp = app.project.activeItem;
var layer = comp.selectedLayers[0];
$.writeln(getLayerType(layer));
})();
@cyrillsemenov
Copy link

This is superuseful, thanks!
I suggest this improvement:

if (layer.source.mainSource instanceof FileSource) {
  ... // Implementation as above
  if (layer.source.mainSource.isStill) { return "Image"; } // Check If source file is a still Image
  return "Video";
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment