Copy link to clipboard
Copied
Hello,
i am trying to automate some of the more repetitious tasks in our workplace,
i have put together this script that changes all the fonts in an after effects project
the script does work and succesfully changes the font, only problems is that when there is > 20 text layers the script crashes after effetcs.
the crash log states "EXCEPTION_ACCESS_VIOLATION"
and i have got an error message in after effects stating that it take to much ram to draw that frame,
is this a limit in after effetcs I wont be able to get around or is there a way to better optimise the code
Please see script below
var scriptName = "SBS replace font";
var NumOccurance = 0;
var layer;
var textLayer;
var ChosenFont;
function OnArabic()
{
ChosenFont = "Dubai"
}
function onMandarin()
{
ChosenFont = "Noto Sans"
}
function onEnglish()
{
ChosenFont = "Ubuntu"
}
function ReplaceFont()
{
NumOccurance = 0;
app.beginUndoGroup("textToArabic");
for (var i = 1; i <= app.project.numItems; i++)
{
if (app.project.item(i) instanceof CompItem)
{
for (var x = 1; x <= app.project.item(i).numLayers;x++)
{
if(app.project.item(i).layer(x).sourceText != null)
{
layer = app.project.item(i).layer(x);
NumOccurance ++
textLayer = layer;
var textDoc = new TextDocument("New text");
var textProp = layer.property("Source Text");
textDoc = textProp.value;
textDoc.font = ChosenFont;
textProp.setValue(textDoc);
}
//app.project.item(i).layer(x).property("Source Text").setValue(textDoc.font);
}
}
}
app.endUndoGroup();
alert("script has completed, " + NumOccurance + " text objects updated");
}
function RunScript(thisObj)
{
function BuildAndShowUI(thisObj)
{
// Create and show a floating palette.
var my_palette = (thisObj instanceof Panel) ? thisObj : new Window("palette", scriptName, undefined, {resizeable:true});
if (my_palette != null)
{
var res =
"group { \
orientation:'column', alignment:['fill','top'], alignChildren:['left','top'], spacing:5, margins:[0,0,0,0], \
introStr: StaticText { text:'Change font to:', alignment:['left','center'] }, \
optsRow: Group { \
orientation:'column', alignment:['fill','top'], \
Arabic: RadioButton { text:'Arabic', alignment:['fill','top'], value:'true' }, \
Mandarin: RadioButton { text:'Mandarin', alignment:['fill','top'] }, \
English: RadioButton { text:'English', alignment:['fill','top'] }, \
}, \
cmds: Group { \
alignment:['fill','top'], \
okButton: Button { text:'Replace font', alignment:['fill','center'] }, \
}, \
}";
my_palette.margins = [20,20,20,20];
my_palette.grp = my_palette.add(res);
// Workaround to ensure the edittext text color is black, even at darker UI brightness levels.
var winGfx = my_palette.graphics;
var darkColorBrush = winGfx.newPen(winGfx.BrushType.SOLID_COLOR, [0,0,0], 1);
//my_palette.grp.optsRow.text_input.graphics.foregroundColor = darkColorBrush;
my_palette.grp.optsRow.Arabic.onClick = OnArabic;
my_palette.grp.optsRow.Mandarin.onClick = onMandarin;
my_palette.grp.optsRow.English.onClick = onEnglish;
my_palette.grp.cmds.okButton.onClick = ReplaceFont;
//my_palette.onResizing = my_palette.onResize = function () {this.layout.resize();}
}
return my_palette;
}
var my_palette = BuildAndShowUI(thisObj);
if (my_palette != null)
{
if (my_palette instanceof Window)
{
my_palette.center();
my_palette.show();
}
else
{
my_palette.layout.layout(true);
my_palette.layout.resize();
}
}
else
{
alert("Could not open the user interface.", scriptName);
}
}
RunScript(this);
Copy link to clipboard
Copied
Probably completely unrelated to the script itself, but rather the usual issues with GPU acceleration and font handling. Chances are AE is simply trying to change stuff all at once and attempting to redraw, in turn crashing the graphics driver or its own UI code. You may be able to work around that by changing how it iterates through the layers and updating each layer separately or something like that, but start by checking your hardware acceleration settings and your system's graphics driver. Also if the texts are very long or complex it may help to limit the iterations based on string lengths and such.
Mylenium
Copy link to clipboard
Copied
Many thanks for the reply, i will look into your advice
Find more inspiration, events, and resources on the new Adobe Community
Explore Now