📝エフェクトを追加する方法

簡単なことなのに毎回ググってる気がする。addPropertyでエフェクトのmatchNameを入れてあげれば良い。matchNameはスクリプトで洗い出す。

例えばスライダー制御ならこんな感じ。

var slider = layer.effect.addProperty("ADBE Slider Control")

addPropertyするとプロパティオブジェクトが返ってくるから、それを操作して名前を変えたり値を変えたりしていく。

📝Object.keys()が使えない

こんな関数を用意してやる。

var getKeys = function(associativeArrayObject) {
var arrayWithKeys=[], associativeArrayObject;
for (key in associativeArrayObject) {
// Avoid returning these keys from the Associative Array that are stored in it for some reason
if (key !== undefined && key !== "toJSONString" && key !== "parseJSON" ) {
arrayWithKeys.push(key);
}
}
return arrayWithKeys;
}

使い方

getKeys(Object)

📝ファイル操作スニペット

ファイルの存在を確認。ファイルの保存・読み込み。ファイル扱うスクリプトは毎回頭にこれ書けばいいかも。

var dataPath = Folder.decode(Folder.userData) + '/Aescripts/YourScriptName';
var f = new Folder(dataPath);
if (!f.exists) f.create();
function fileExist(filename) {
var file = new File(dataPath + "/" + filename + ".json");
return file.exists
}
function writeFile(object, filename) {
var myFile = new File(dataPath + "/" + filename + ".json");
myFile.open("w");
myFile.encoding = "UTF-8";
myFile.write(JSON.stringify(object).replace(/\r?\n/g, ''));
myFile.close();
}
function readFile(filename) {
var file = new File(dataPath + "/" + filename + ".json");
file.open('r');
file.encoding = 'UTF-8';
return JSON.parse(file.readln());
}
var settings;
function makeSettings() {
settings = {}
writeFile(settings, 'settings')
}
if (!fileExist('settings')) {
makeSettings()
} else {
try {
settings = readFile('settings')
} catch (e) {
makeSettings()
}
}

更新記録

  • 2024/12/20(金)
    • writeFile関数に改行をなくす処理を追加
  • 2024/12/21(土)
    • 拡張子をtxtからjsonに

📝レイヤーと関連付けられていないため、値を設定できません

スクリプトからSourceTextのスタイルをいじろうとした時に出たエラー。TypeAnimeJP開発中に追加テキストを左揃え固定にしようとしたときに遭遇。

// 左揃えに
var tmpTextDocument = tmpTextLayer.property("Source Text").value
tmpTextDocument.justification = ParagraphJustification.LEFT_JUSTIFY
tmpTextLayer.property("Source Text").setValue(tmpTextDocument)

こんな感じにしたらいけた。一回valueで取得して値をいじって再度setValue。フォントを指定するときと同じ流れ。