-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEF_ShowLayerSizeAndPosition.jsx
74 lines (60 loc) · 2.85 KB
/
EF_ShowLayerSizeAndPosition.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**========================================================================
* ? EF_ShowLayerSizeAndPosition.jsx
* @author : Eveline Falcão (https://evelinefalcao.com)
* @email : [email protected]
* @version : 1.0.0
* @createdFor : Adobe After Effects CC 2024 (Version 24.1.0 Build 78)
* @description : Shows layer size and position in the Info Panel. The position shown is relative to parent and the position in the comp.
*========================================================================**/
(function showLayerSizeAndPosition(){
function getBoundingBox(layer, currentTime){
var layerObj = {};
var sourceRect = layer.sourceRectAtTime(currentTime, true);
layerObj.top = sourceRect.top;
layerObj.left = sourceRect.left;
layerObj.width = sourceRect.width;
layerObj.height = sourceRect.height;
return layerObj;
}
function fixPositionDecimals(propertyValue, digits){
var posObj = {};
posObj.x = propertyValue[0].toFixed(digits);
posObj.y = propertyValue[1].toFixed(digits);
posObj.z = propertyValue[2].toFixed(digits);
return posObj;
}
var comp = app.project.activeItem;
var layers = comp.selectedLayers;
if(layers.length > 0){
var currentLayer = layers[0];
var currentTime = comp.time;
var boundingBox = getBoundingBox(currentLayer, currentTime);
var positionProp = currentLayer.property("ADBE Transform Group").property("ADBE Position");
var position = currentLayer.property("ADBE Transform Group").property("ADBE Position").value;
var anchorProp = currentLayer.property("ADBE Transform Group").property("ADBE Anchor Point");
var width = boundingBox.width.toFixed(1);
var height = boundingBox.height.toFixed(1);
var posFixed = fixPositionDecimals(position, 1);
positionProp.expression = "";
positionProp.expression =
"l = thisLayer;\rtry {\r" +
" l.toComp(l.anchorPoint);\r" +
"}\r" +
"catch(e) {\r" +
" l.toComp(l.anchorPoint);\r" +
"}";
positionProp.expressionEnabled = false;
positionProp.expressionEnabled = true;
var newPositionValue = positionProp.valueAtTime(currentTime, false);
var newPosFixed = fixPositionDecimals(newPositionValue, 1);
positionProp.expression = "";
writeLn(currentLayer.name);
writeLn("Size: " + "[" + width + ", " + height + "]");
writeLn("Position: [" + posFixed.x + ", " + posFixed.y + ", " + posFixed.z + "]");
if(currentLayer.parent) {
writeLn("Comp Pos: [" + newPosFixed.x + ", " + newPosFixed.y + ", " + newPosFixed.z + "]");
}
} else {
alert("Select one layer to continue.")
}
})();