2016-03-19 2 views
0

J'utilise avec succès le script extend suivant (avec json2.js) pour lire un fichier JSON local et modifier un calque de texte dans mon projet. Comment est-ce que je pourrais modifier ce script de sorte que, quand couru, il surveille continuellement de nouveaux fichiers JSON qui sont ajoutés au répertoire, et exécute le reste du manuscrit?Comment puis-je définir un dossier pour After Effects pour surveiller les fichiers JSON/texte?

#include "json2.js" // jshint ignore:line 
var script_file = File($.fileName); // get the location of the script file 
var script_file_path = script_file.path; // get the path 

var file_to_read = File(script_file_path + "/unique-job-id.json"); 
var my_JSON_object = null; // create an empty variable 
var content; // this will hold the String content from the file 
    if(file_to_read !== false){// if it is really there 
    file_to_read.open('r'); // open it 
    content = file_to_read.read(); // read it 
    my_JSON_object = JSON.parse(content);// now evaluate the string from the file 
    //alert(my_JSON_object.arr[1]); // if it all went fine we have now a JSON Object instead of a string call length 
    var theComposition = app.project.item(1); 
    var theTextLayer = theComposition.layers[1]; 
    theTextLayer.property("Source Text").setValue(my_JSON_object.arr[2]); 
    file_to_read.close(); // always close files after reading 
    }else{ 
    alert("Error reading JSON"); // if something went wrong 
    } 
+0

Je pense qu'il est impossible d'avoir un script exécuté en permanence en arrière-plan. Le script bloque le thread d'interface utilisateur en cours d'exécution. Vous pouvez jeter un oeil sur le développement de plugins pour After Effects. [adobe.com/devnet/aftereffects](http://www.adobe.com/devnet/aftereffects.html)] – fabianmoronzirfas

Répondre

0

Regardez le modèle de l'objet: application scheduleTask() méthode app.scheduleTask (stringToE xecute, retard, répétition) Description: Planifie l'exécution JavaScript spécifié pour retard.

Ainsi app.scheduleTask (string, retard, true) est exactement ce que vous cherchez for.Like ceci:

app.schduleTask('taskToWatchFile()',1000,true); 

function taskToWatchFile(){ 
/* 
*Add your code here 
*/ 
}