forked from zlovatt/zl_Scriptlets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Write Item Uses To Comment.jsx
51 lines (41 loc) · 1.18 KB
/
Write Item Uses To Comment.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* Counts the # of times a project item is used, and writes it to the item comment field
*
* @author Zack Lovatt <[email protected]>
* @version 0.1.0
*/
(function writeItemUsesToComment() {
/**
* Gets the all layers where the given Item object is used as a source.
*
* Pulled from aequery.
*
* @param {Item} item The item to find in comps
* @return {AVLayer[]} Array of Layer objects
*/
function getItemInComps(item) {
var layers = [];
for (var ii = 0, il = item.usedIn.length; ii < il; ii++) {
var usedInComp = item.usedIn[ii];
for (var jj = 1, jl = usedInComp.numLayers; jj <= jl; jj++) {
var compLayer = usedInComp.layer(jj);
if (compLayer.source === item) {
layers.push(compLayer);
}
}
}
return layers;
}
app.beginUndoGroup("Write Item Uses To Comment");
var items = app.project.items;
for (var ii = 1, il = items.length; ii <= il; ii++) {
var item = items[ii];
if (item instanceof FolderItem) {
continue;
}
var itemLayers = getItemInComps(item);
var comment = "Used " + itemLayers.length + " times";
item.comment = comment;
}
app.endUndoGroup();
})();