December 04th 2015 08:00:40am
Welcome to to this weeks Free Function Friday episode. As we dive deeper into different parts of ExtendScript for After Effects, you will begin to find various limitations that you might not have thought about beforehand. A lot of things sound like they would be obvious or straight forward, but that isn’t always the case when dealing with ExtendScript.
This week we learn how to retrieve the fonts used in a project file, which is a very useful bit of data for anyone tracking fonts between projects or for hand off to another artist. We will also run into one of those unknown ExtendScript limitations that will be very aggravating. So prepare yourself to be a bit annoyed.
A lot of Technical Directors, artists, and developers have had a need to access fonts at one point or another in their project file, whether it was to list out what fonts were used, trying to change various properties of the fonts, or just verifying that the correct font was properly implemented in the project file. A lot of text layer data is accessible though ExtendScript, but not all of it unfortunately.
One of the greatest issues right now, is that text layer source attributes that are accessible currently are only based on the first character of the text. In reality, we have control over changing the font, size, color, kerning, styles, and so much more within a single line of text as a user, which makes getting all that data virtually impossible with the current setup of ExtendScript.
ExtendScript is making the assumption that the first character represents the settings of every single character of the text layer, which isn’t always true. Personally I feel that the ball was dropped majorly here, but like many things in life there are variables and politics at play that we are unaware of behind-the-scenes that can effect the course of something.
Be that as it may, it is that much more important that we as After Effects users file a feature request to correct things like this. That is the only way for issues to be corrected really. The big down side to this, is that we will never see this fix for any After Effects versions prior to the day it finally gets implemented. Whenever that will be, so help out and make the request by filling out the feature request form here: UserVoice forums where Adobe After Effects Feature Requests and Bug Reports are made. It may sound trivial, but it is important to a lot of developers to have the freedom to access as much of an application as possible in order to design the powerful tools that help you get the job done.
I’ll even do the heavy lifting for you. Below you can copy and paste the text into the entry boxes.
ExtendScript per character access
General
How the feature would work…
I would like to be able to have read and write access to all attributes like font, size, color, kerning, style, etc… within a text layer’s source document object for each and EVERY single character. Accessing it by looping through each character would be helpful, or an object containing a collection of the data.Why is this feature important?
Currently the restriction of getting the source values from only the first character is an inaccurate representation of the whole text layer’s source text. This prevents a developer from retrieving accurate font data that a project may hold. When handing off a project to another company or individual, knowing all of the required media involved, especially fonts, is vital. It also prevents any possibilities of building and/or replicating a custom text layer build that may involve mixed text attribute combinations.
Of course feel free to word it how you like.
Source Code:
alert(collectFontsUsed());
/* TESTING ABOVE */
function collectFontsUsed(){
try{
var proj, itemCount, curItem, layerCount, curLayer, fonts, curFont;
fonts = new Array();
proj = app.project;
itemCount = proj.numItems;
for(var i=1; i<=itemCount; i++){
curItem = proj.item(i);
if(curItem instanceof CompItem){
layerCount = curItem.numLayers;
for(var l = 1; l<=layerCount; l++){
curLayer = curItem.layer(l);
if(curLayer.property("Source Text") != null){
curFont = curLayer.property("ADBE Text Properties").property("ADBE Text Document").value.font;
if(fonts.toString().indexOf(curFont) == (-1)){
fonts[fonts.length] = curFont;
}
}
}
}
}
return fonts.sort();
}catch(err){alert(err.line.toString() + "\r" + err.toString());}
}