Skip to content

Commit 315c72a

Browse files
committed
change fonts script
1 parent 78027c8 commit 315c72a

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

changeAllFonts.jsx

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
var changeAllFontsScript={
2+
fontName:"Kankin"
3+
};
4+
changeAllFontsScript.go = function(){
5+
6+
FolderItem.prototype.getSelected = function(allItems)//all Items is a boolean. if true, will take all contained folders and items. else take only selected items
7+
{
8+
var arr=[];
9+
if (this.selected)//if folder is selected, we will take all contained items
10+
allItems=true;
11+
for (var i=1;i<=this.numItems;i++)
12+
{
13+
var curItem=this.item(i);
14+
if (curItem instanceof FolderItem)
15+
{
16+
var inner=curItem.getSelected(allItems);
17+
arr=arr.concat(inner);
18+
}
19+
if ((allItems === true || curItem.selected) && curItem instanceof CompItem)
20+
{
21+
arr.push(curItem);
22+
}
23+
}
24+
return arr;
25+
}
26+
27+
Project.prototype.getSelectedItems = function()
28+
{
29+
//there is no method to take all selected items in project window. i wrote my own
30+
return this.rootFolder.getSelected(false);//get all selected items in project
31+
}
32+
33+
TextLayer.prototype.changeFont=function(fontName)
34+
{
35+
var prop=this.property("Source Text");
36+
if (prop.numKeys>0)//if textLayer has animation
37+
for (var i=1;i<=prop.numKeys;i++)
38+
{
39+
var curTime=prop.keyTime(i);//get time if key i
40+
var textDocument=prop.valueAtTime(curTime,false);//get value in key i
41+
textDocument.font=fontName;//change font
42+
prop.setValueAtTime(curTime,textDocument)//set value with new font to key i
43+
}
44+
else//if no animation or expression only
45+
{
46+
var textDocument=prop.value;//get value
47+
textDocument.font=fontName;//change font
48+
prop.setValue(textDocument);//set new font
49+
}
50+
}
51+
52+
CompItem.prototype.changeFonts=function()
53+
{
54+
for (var i=1;i<=this.numLayers;i++)
55+
{
56+
var curLayer=this.layer(i);
57+
if (curLayer instanceof TextLayer)
58+
try
59+
{
60+
//alert("trying to change font of layer: "+curLayer.name);
61+
curLayer.changeFont(changeAllFontsScript.fontName);
62+
}
63+
catch(e)
64+
{
65+
return null;
66+
}
67+
}
68+
return 0;
69+
}
70+
71+
app.beginUndoGroup("Change All Fonts");
72+
73+
var selItems=app.project.getSelectedItems();
74+
//alert("number of selected comps:"+selItems.length);
75+
76+
for (var i=0;i<selItems.length;i++)
77+
{
78+
var func=selItems[i].changeFonts();//function returns null if caugth exeption
79+
if (func === null)
80+
{
81+
alert("Unknown font name");
82+
return 0;//end script
83+
}
84+
}
85+
86+
alert("Done!");
87+
app.endUndoGroup();
88+
89+
}
90+
91+
changeAllFontsScript.go();

0 commit comments

Comments
 (0)