-
Notifications
You must be signed in to change notification settings - Fork 56
/
changeAllFonts.jsx
91 lines (80 loc) · 1.91 KB
/
changeAllFonts.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
var changeAllFontsScript={
fontName:"Kankin"
};
changeAllFontsScript.go = function(){
FolderItem.prototype.getSelected = function(allItems)//boolean
{
var arr=[];
if (this.selected)
allItems=true;
for (var i=1;i<=this.numItems;i++)
{
var curItem=this.item(i);
if (curItem instanceof FolderItem)
{
var inner=curItem.getSelected(allItems);
arr=arr.concat(inner);
}
if ((allItems === true || curItem.selected) && curItem instanceof CompItem)
{
arr.push(curItem);
}
}
return arr;
}
Project.prototype.getSelectedItems = function()
{
return this.rootFolder.getSelected(false);
}
TextLayer.prototype.changeFont=function(fontName)
{
var prop=this.property("Source Text");
if (prop.numKeys>0)
for (var i=1;i<=prop.numKeys;i++)
{
var curTime=prop.keyTime(i);
var textDocument=prop.valueAtTime(curTime,false);
textDocument.font=fontName;
prop.setValueAtTime(curTime,textDocument)
}
else
{
var textDocument=prop.value;
textDocument.font=fontName;
prop.setValue(textDocument);
}
}
CompItem.prototype.changeFonts=function()
{
for (var i=1;i<=this.numLayers;i++)
{
var curLayer=this.layer(i);
if (curLayer instanceof TextLayer)
try
{
//alert("trying to change font of layer: "+curLayer.name);
curLayer.changeFont(changeAllFontsScript.fontName);
}
catch(e)
{
return null;
}
}
return 0;
}
app.beginUndoGroup("Change All Fonts");
var selItems=app.project.getSelectedItems();
//alert("number of selected comps:"+selItems.length);
for (var i=0;i<selItems.length;i++)
{
var func=selItems[i].changeFonts();//function returns null if caugth exeption
if (func === null)
{
alert("Unknown font name");
return 0;//end script
}
}
alert("Done!");
app.endUndoGroup();
}
changeAllFontsScript.go();