-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathdynamic_bbox.jsx
103 lines (90 loc) · 4.99 KB
/
dynamic_bbox.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//Script draws dynamic rectangle shape around text or any object
//Only for AE 13.2 and higher
//Alex Kravchenko, 2015
CompItem.prototype.dd_dynamicBbox_createBbox = function(_layer)
{
bboxProps = {"fill":{"color":[0.5,0.5,0.5,1]},
"stroke":{"width":20,"color":[0.3,0.3,0.3,1]},
"addSpace":50};
//shape match names:
var contentsName = "ADBE Root Vectors Group";
var vectorGroupName = "ADBE Vector Group";//a shape group
var rectPathName = "ADBE Vector Shape - Rect";//rectangle group
var rectPathSizeName = "ADBE Vector Rect Size";//rectangle size
var strokeGroupName = "ADBE Vector Graphic - Stroke";//stroke
var strokeWidthName = "ADBE Vector Stroke Width";//stroke width
var strokeColorName = "ADBE Vector Stroke Color";//stroke color
var fillGroupName = "ADBE Vector Graphic - Fill";//fill
var fillColorName = "ADBE Vector Fill Color";////fill color
//effect match names:
var effectsName = "ADBE Effect Parade";
var layerControlName = "ADBE Layer Control";
var sliderControlName = "ADBE Slider Control";
var cbControlName = "ADBE Checkbox Control";
//expressions:
var shapeSizeExpression = "textLayer = effect(\"Target Layer\")(\"Layer\");\nvar strokes = effect(\"Accept Strokes\")(\"Checkbox\");\nvar add = effect(\"Padding\")(\"Slider\");\nbbox = textLayer.sourceRectAtTime(time,strokes);//bounding box вокруг текста\n[bbox.width*textLayer.scale[0]/100,bbox.height*textLayer.scale[1]/100]+[add,add]//ширина bbox'а плюс немного отступа по краям";
var textSizeExpression = "textLayer = effect(\"Target Layer\")(\"Layer\");\nvar add = effect(\"Padding\")(\"Slider\");\nbbox = textLayer.sourceRectAtTime(time,false);//bounding box вокруг текста\n[bbox.width*textLayer.scale[0]/100,bbox.height*textLayer.scale[1]/100]+[add,add]//ширина bbox'а плюс немного отступа по краям";
var shapePosExpression = "textLayer = effect(\"Target Layer\")(\"Layer\");\nvar strokes = effect(\"Accept Strokes\")(\"Checkbox\");\nbbox = textLayer.sourceRectAtTime(time,strokes);\ntextLayer.position-textLayer.anchorPoint+\n [bbox.left*textLayer.scale[0]/100,bbox.top*textLayer.scale[1]/100]+\n [bbox.width*textLayer.scale[0]/100,bbox.height*textLayer.scale[1]/100]/2;";
var textPosExpression = "textLayer = effect(\"Target Layer\")(\"Layer\");\nbbox = textLayer.sourceRectAtTime(time,false);\ntextLayer.position-textLayer.anchorPoint+\n [bbox.left*textLayer.scale[0]/100,bbox.top*textLayer.scale[1]/100]+\n [bbox.width*textLayer.scale[0]/100,bbox.height*textLayer.scale[1]/100]/2;";
//creating shape layer
var newShape = this.layers.addShape();
newShape.name = _layer.name+"_bbox";
newShape.moveAfter(_layer);
//creating all controls
var layerControl = newShape.property(effectsName).addProperty(layerControlName);
layerControl.name = "Target Layer";
layerControl.property(layerControlName+"-0001").setValue(_layer.index);
var sliderControl = newShape.property(effectsName).addProperty(sliderControlName);
sliderControl.name = "Padding";
sliderControl.property(sliderControlName+"-0001").setValue(bboxProps.addSpace);
if(_layer instanceof ShapeLayer)
{
var checkboxControl = newShape.property(effectsName).addProperty(cbControlName);
checkboxControl.name = "Accept Strokes";
checkboxControl.property(cbControlName+"-0001").setValue(true);
}
if(_layer instanceof ShapeLayer)
newShape.position.expression = shapePosExpression;
else
newShape.position.expression = textPosExpression;
var rectGroup = newShape.property(contentsName).addProperty(rectPathName);
var rectSize = rectGroup.property(rectPathSizeName);
if(_layer instanceof ShapeLayer)
rectSize.expression = shapeSizeExpression;
else
rectSize.expression = textSizeExpression;
var fillGroup = newShape.property(contentsName).addProperty(fillGroupName);
fillGroup.property(fillColorName).setValue(bboxProps.fill.color);
var strokeGroup = newShape.property(contentsName).addProperty(strokeGroupName);
strokeGroup.property(strokeColorName).setValue(bboxProps.stroke.color);
strokeGroup.property(strokeWidthName).setValue(bboxProps.stroke.width);
}
function dd_dynamicBbox()
{
vers = parseFloat(app.version);
if(vers<13.2)
{
alert("Update to After Effects CC2014 or later to use this script");
return 0;
}
var myComp = app.project.activeItem;
if(!myComp || !(myComp instanceof CompItem) || myComp.selectedLayers.length==0)
{
alert("Choose at least one layer");
return 0;
}
var arr = []//layers array (only text and/or shape layers)
for(var i=0;i<myComp.selectedLayers.length;i++)
if(myComp.selectedLayers[i] instanceof TextLayer || myComp.selectedLayers[i] instanceof ShapeLayer)
arr.push(myComp.selectedLayers[i]);
if(arr.length == 0)
{
alert("Select Shape or Text layer");
return 0;
}
for(var i=0;i<arr.length;i++)
myComp.dd_dynamicBbox_createBbox(arr[i]);
}
app.beginUndoGroup("Dynamic Bbox");
dd_dynamicBbox();
app.endUndoGroup();