FORUMS: list search recent posts

Read from file and add corresponding layer.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Cyril Pachoov
Read from file and add corresponding layer.
on Oct 7, 2014 at 11:36:10 am

Hello again.
Recently I created a post where I was asking for some help.
The post was about adding layers to previously created comps (Post link HERE)
That problem was solved.
Now what I want to do is how to import a corresponding layer from reading a line in a text file. I will provide a code with which I tried to pull it off, but somehow the "Switch" statement is broken. Can someone tell me where I'm wrong, and what to do to make it work?

var c, compName, curLine, line1, line2, line3, line4, pl;
var theComps = [];
var myFilesImp = [];
var aryLength = content.length;
var activeComp = app.project.activeItem;
var imgDir = ("e:\\Afterefect Projects 2014 Payed\\Kikac\\");
var newAmt = 9;
function processFolder(theFolder){
for ( var i = 1; i <= newAmt; i++){
var importOpts = new ImportOptions( new File(theFolder + "w"+ i + ".mov"));
var importFiles = app.project.importFile (importOpts);
myFilesImp.push(importFiles);
}
}
processFolder(imgDir);

var weather = 9;
switch (weather){
case 1: line4 = "oblacno" ;
wState = 0;
break;
case 2: line4 = "dozd i grmezi";
wState = 1;
break;
case 3: line4 = "dozd";
wState = 2;
break;
case 4: line4 = "sneg";
wState = 3;
break;
case 5: line4 = "sneg i dozd";
wState = 4;
break;
case 6: line4 = "bura";
wState = 5;
break;
case 7: line4 = "soncevo";
wState = 6;
break;
case 8: line4 = "pretezno soncevo";
wState = 7;
break;
case 9: line4 = "soncevo so dozd";
wState = 8;
break;
default: alert("Weather state not entered correctly. ");
break;
}

for (var i = 0; i < aryLength; i++){
curLine = content [i];
pl = parse(curLine); //
line1 = pl.date;
line2 = pl.minTemp;
line3 = pl.maxTemp;
line4 = pl.weatherState;
compName = pl.date;
if (curLine != ""){
c = app.project.items.addComp(compName, 185, 605, 1.0, 10, 25); // (compname, width, height, pixel aspect ratio, duration in seconds, fps)
createDateLayers(c, line1);
createMinTempLayers(c, line2);
createMaxTempLayers(c, line3);
activeComp.layers.add(c);
theComps.push(c);
}
}
for (var j = 0; j <theComps.length; j++) {
if (weather = 1) {
var myFile = theComps[j].layers.add(myFilesImp[wState], );
} else if (weather = 2) {
var myFile = theComps[j].layers.add(myFilesImp[wState], );
} else if (weather = 3) {
var myFile = theComps[j].layers.add(myFilesImp[wState], );
} else if (weather = 4) {
var myFile = theComps[j].layers.add(myFilesImp[wState], );
} else if (weather = 5) {
var myFile = theComps[j].layers.add(myFilesImp[wState], );
} else if (weather = 6) {
var myFile = theComps[j].layers.add(myFilesImp[wState], );
} else if (weather = 7) {
var myFile = theComps[j].layers.add(myFilesImp[wState], );
} else if (weather = 8) {
var myFile = theComps[j].layers.add(myFilesImp[wState], );
} else if (weather = 9) {
var myFile = theComps[j].layers.add(myFilesImp[wState], );
}
var s = (theComps[j].width*theComps[j].pixelAspect)/(myFile.width*myFile.source.pixelAspect)*90;
myFile.property("Scale").setValue([s,s]);
myFile.property("ADBE Transform Group").property("ADBE Position").setValue([(theComps[j].width - s)*0.55, ((theComps[j].height - s)*0.50)]);
}


Any help will be much appreciated.

Thanks in advance.


Return to posts index


Cyril Pachoov
Re: Read from file and add corresponding layer.
on Oct 9, 2014 at 2:10:44 pm
Last Edited By Cyril Pachoov on Oct 9, 2014 at 2:11:44 pm

Solved it. This the final code:

var c, compName, curLine, line1, line2, line3, line4, pl;
var myFilesImp = [];
var aryLength = content.length;
var activeComp = app.project.activeItem;
var imgDir = ("e:\\Afterefect Projects 2014 Payed\\Kikac\\");
var newAmt = 9;
function processFolder(theFolder){
for ( var i = 1; i <= newAmt; i++){
var importOpts = new ImportOptions( new File(theFolder + "w"+ i + ".mov"));
var importFiles = app.project.importFile (importOpts);
myFilesImp.push(importFiles);
}
}
processFolder(imgDir);

for (var i = 0; i < aryLength; i++){
curLine = content [i];
pl = parse(curLine); //
line1 = pl.date;
line2 = pl.minTemp;
line3 = pl.maxTemp;
line4 = pl.weatherState;
compName = pl.date;
if (curLine != ""){
c = app.project.items.addComp(compName, 185, 605, 1.0, 10, 25); // (compname, width, height, pixel aspect ratio, duration in seconds, fps)
createDateLayers(c, line1);
createMinTempLayers(c, line2);
createMaxTempLayers(c, line3);
activeComp.layers.add(c);
theComps.push(c);

if (line4 == "oblacno"){
var myFile = c.layers.add(myFilesImp[0], );
} else if (line4 == "dozd i grmezi"){
var myFile = c.layers.add(myFilesImp[1], );
} else if (line4 == "dozd"){
var myFile = c.layers.add(myFilesImp[2], );
} else if (line4 == "sneg"){
var myFile = c.layers.add(myFilesImp[3], );
} else if (line4 == "sneg i dozd"){
var myFile = c.layers.add(myFilesImp[4], );
} else if (line4 == "bura"){
var myFile = c.layers.add(myFilesImp[5], );
} else if (line4 == "soncevo"){
var myFile = c.layers.add(myFilesImp[6], );
} else if (line4 == "pretezno soncevo"){
var myFile = c.layers.add(myFilesImp[7], );
} else if (line4 == "soncevo so dozd"){
var myFile = c.layers.add(myFilesImp[8], );
}
var s = (c.width*c.pixelAspect)/(myFile.width*myFile.source.pixelAspect)*90;
myFile.property("Scale").setValue([s,s]);
myFile.property("ADBE Transform Group").property("ADBE Position").setValue([(c.width - s)*0.55, ((c.height - s)*0.50)]);
}
}


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]