Could somebody help out with a modified script?

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
MKonings
Posts: 3
Joined: January 13th, 2017, 3:33 am
Contact:

Hello community!

I am quite new to the whole java script language.
But like very much all the possibilities. And so I like to improve this newly found, creative asset.

I am creating a script for an automated animation production that I am setting up.
And use an existing script that I modified. But I ran into trouble when changing some names.
I cannot see the error I made due to my lack of knowledge in this language.

Could you please help out?

Code: Select all

/* TEMPLATE test COMPOSITING MK */
// version  130117-001
var currentFootageItem;
var maDate=new Date();
var myfps=25;
var mySearch=/EP00_SC000/;
var nom=prompt("Numéros de séquence et de plan :","EP00_SC000","MK AE");
var myDuree=prompt("Durée du plan : ","480","MK AE")/25;
var z,z1=false;
var a = app.project.items;
var q = app.project.renderQueue.items
for (i=app.project.numItems; i>=1; i--){if(mySearch.test(a[i].name)){a[i].name=a[i].name.replace(mySearch,nom);a[i].duration=myDuree;z=true; if(a[i].name==(nom+"_NOMENCLATURE")){for(j=1;j<=a[i].numLayers;j++){if(mySearch.test(a[i].layer(j).name)){a[i].layer(j).sourceText.setValue(nom);a[i].layer(j).name=nom;z1=true;}}}}}
if(z&&z1){
    a.addFolder("REFS_OTHER");
    var b = a.addFolder(nom);
    var c =  a.addFolder("NOMEMCLATURE");
    a.addFolder("01_ANIM").parentFolder=b;    
    a.addFolder("02_BG").parentFolder=b;
    a.addFolder("03_FX").parentFolder=b;
    c.parentFolder=b;
    for (i=a.length; i>=1; i--){
        if(a[i].name==nom+"_NOMENCLATURE"){a[i].parentFolder=c;}
        if(a[i].name==nom+"_CONFO"){a[i].parentFolder=b;}
        if(a[i].name==nom+"_720PNG"){a[i].parentFolder=b;}    
        if(a[i].name==nom&&!(a[i] instanceof FolderItem)){a[i].parentFolder=b;a[i].selected=true;currentFootageItem=a[i]}
        a[i].selected=false
    }
    function aff_Date(x){if(x>9){return x;}else{return "0"+x;}}
    var d=app.project.saveWithDialog();
    var e=app.project.file.path;    
    var f=app.project.file.fsName;
    var h = e.toString().split("/");
    h.pop();
    var g="";
    for (i=0;i<h.length;i++){g=g+h[i]+"/";}
    g=g+ "OUTPUT_"+nom+"/" + nom + "_720PNG_"+maDate.getFullYear().toString().substring (2,4)+aff_Date(maDate.getMonth())+aff_Date(maDate.getDay());
    var curItemQ = q[1];
    var curItemQOut = curItemQ.outputModule(1);
    var oldLocation = curItemQOut.file;
    curItemQOut.file = new File(g);
}else{
    alert ("Arrêt du script : le projet AE en cours ne semble pas être une copie du template EP00_SC000.aet" , "MK AE", true)
}


here is an image of the the template file as well:

Image

Cheers (in advanced),

Marc
runegan
Posts: 22
Joined: November 4th, 2016, 3:18 pm
Contact:

Hi Marc! Welcome!
When I run this script, I first get an error when trying to access the renderqueue, because there is nothing added to the renderqueue, somewhere in you should add a comp to the renderqueue using 

Code: Select all

app.project.renderQueue.items.add( yourCompItemVariable );
// In your code that could be written as
q.add( yourCompItemVariable );
Some tips:
  • If you are looking for more knowledge about javascript, there are a lot of resources online, I recommend the courses on https://www.codecademy.com.
  • It's a good a idea to give your variables meaningful names describing what it contains, e.g "a" does not make much sense when reading the code, but "projectItems" does.
  • You have a couple a lines of code squashed into one line, it makes the code harder to read. Try running it through http://jsbeautifier.org to see how to properly format your code.
  • You could use h.join("/"); instead of

    Code: Select all

    for (i=0;i<h.length;i++){g=g+h[i]+"/";}
  • If they folder you are rendering to does not exist you may get an error when starting the render (I did), so you can create the folder using

    Code: Select all

    var outputFile = new File( g );
    var outputFolder = outputFile.parent
    if (!outputFolder.exists) {
    	outputFolder.create();
    }
  • getMonth() returns January as 0, and December as 11, so you need to use getMonth() + 1 to get the correct month
  • getDay() returns the number for the day of the week, you probably want getDate()
  • When doing automation in After Effects, it's a good idea to create undo groups using app.beginUndoGroup("undogroupname") and app.endUndoGroup().
  • It's good practice to wrap your code inside a function like this:

    Code: Select all

    function myScript() {
    	// Your code
    }
    myScript();
    
Good luck with your project, hope you find this helpful!
Rune
MKonings
Posts: 3
Joined: January 13th, 2017, 3:33 am
Contact:

Thank you for the info Rune,

It's quite something to take in, but your additional links and info are helpful.
I am new to this language, and I used a pre-made script from another production and try to apply it to my new production.


I checked, and in the AE template file I have two compositions in the render queue waiting...weirdly I just changed the names of:

Code: Select all

/* TEMPLATE ARBORESCENCE LES HIRONDELLES DE KABOUL COMPOSITING */
// version  20110705-1500

var currentFootageItem;
var maDate=new Date();
var myfps=24;
var mySearch=/S000_P00/;
var nom=prompt("Numéros de séquence et de plan :","S000_P00","Les Hirondelles de Kaboul AE");
var myDuree=prompt("Durée du plan : ","480","Les Hirondelles de Kaboul AE")/24;
var z,z1=false;
var a = app.project.items;
var q = app.project.renderQueue.items
for (i=app.project.numItems; i>=1; i--){if(mySearch.test(a[i].name)){a[i].name=a[i].name.replace(mySearch,nom);a[i].duration=myDuree;z=true; if(a[i].name==(nom+"_NOMENCLATURE")){for(j=1;j<=a[i].numLayers;j++){if(mySearch.test(a[i].layer(j).name)){a[i].layer(j).sourceText.setValue(nom);a[i].layer(j).name=nom;z1=true;}}}}}
if(z&&z1){
    a.addFolder("REFS_OTHER");
    var b = a.addFolder(nom);
    var c =  a.addFolder("NOMEMCLATURE");
    a.addFolder("01_ANIM").parentFolder=b;    
    a.addFolder("02_BG").parentFolder=b;
    a.addFolder("03_FX").parentFolder=b;
    c.parentFolder=b;
    for (i=a.length; i>=1; i--){
        if(a[i].name==nom+"_NOMENCLATURE"){a[i].parentFolder=c;}
        if(a[i].name==nom+"_CONFO"){a[i].parentFolder=b;}
        if(a[i].name==nom+"_720PNG"){a[i].parentFolder=b;}    
        if(a[i].name==nom&&!(a[i] instanceof FolderItem)){a[i].parentFolder=b;a[i].selected=true;currentFootageItem=a[i]}
        a[i].selected=false
    }
    function aff_Date(x){if(x>9){return x;}else{return "0"+x;}}
    var d=app.project.saveWithDialog();
    var e=app.project.file.path;    
    var f=app.project.file.fsName;
    var h = e.toString().split("/");
    h.pop();
    var g="";
    for (i=0;i<h.length;i++){g=g+h[i]+"/";}
    g=g+ "OUTPUT_"+nom+"/" + nom + "_720PNG_"+maDate.getFullYear().toString().substring (2,4)+aff_Date(maDate.getMonth())+aff_Date(maDate.getDay());
    var curItemQ = q[1];
    var curItemQOut = curItemQ.outputModule(1);
    var oldLocation = curItemQOut.file;
    curItemQOut.file = new File(g);
}else{
    alert ("Arrêt du script : le projet AE en cours ne semble pas être une copie du template P000_S00.aet" , "Les Hirondelles de Kaboul AE", true)
}
into:

Code: Select all

/* TEMPLATE ARBORESCENCE Max & Maestro AE COMPOSITING */
// version  13012017-001

var currentFootageItem;
var maDate=new Date();
var myfps=25;
var mySearch=/EP000_SC000/;
var nom=prompt("Episode and Scene number :","EP000_SC000","Max & Maestro AE");
var myDuree=prompt("Frames : ","480","Max & Maestro AE")/25;
var z,z1=false;
var a = app.project.items;
var q = app.project.renderQueue.items
for (i=app.project.numItems; i>=1; i--){if(mySearch.test(a[i].name)){a[i].name=a[i].name.replace(mySearch,nom);a[i].duration=myDuree;z=true; if(a[i].name==(nom+"_NOMENCLATURE")){for(j=1;j<=a[i].numLayers;j++){if(mySearch.test(a[i].layer(j).name)){a[i].layer(j).sourceText.setValue(nom);a[i].layer(j).name=nom;z1=true;}}}}}
if(z&&z1){
    a.addFolder("REFS_OTHER");
    var b = a.addFolder(nom);
    var c =  a.addFolder("NOMEMCLATURE");
    a.addFolder("01_ANIM").parentFolder=b;    
    a.addFolder("02_BG").parentFolder=b;
    a.addFolder("03_FX").parentFolder=b;
    c.parentFolder=b;
    for (i=a.length; i>=1; i--){
        if(a[i].name==nom+"_NOMENCLATURE"){a[i].parentFolder=c;}
        if(a[i].name==nom+"_CONFO"){a[i].parentFolder=b;}
        if(a[i].name==nom+"_720PNG"){a[i].parentFolder=b;}    
        if(a[i].name==nom&&!(a[i] instanceof FolderItem)){a[i].parentFolder=b;a[i].selected=true;currentFootageItem=a[i]}
        a[i].selected=false
    }
    function aff_Date(x){if(x>9){return x;}else{return "0"+x;}}
    var d=app.project.saveWithDialog();
    var e=app.project.file.path;    
    var f=app.project.file.fsName;
    var h = e.toString().split("/");
    h.pop();
    var g="";
    for (i=0;i<h.length;i++){g=g+h[i]+"/";}
    g=g+ "OUTPUT_"+nom+"/" + nom + "_720PNG_"+maDate.getFullYear().toString().substring (2,4)+aff_Date(maDate.getMonth())+aff_Date(maDate.getDay());
    var curItemQ = q[1];
    var curItemQOut = curItemQ.outputModule(1);
    var oldLocation = curItemQOut.file;
    curItemQOut.file = new File(g);
}else{
    alert ("Arrêt du script : le projet AE en cours ne semble pas être une copie du template EP000_SC000.aet" , "Max & Maestro AE", true)
}

And the first one works with the template, and my new template, with the name EP000_SC000 doesn't work.


Anyway, I have to take another look at it, when I am less tired of this filled week.

Thanks for all the info though!

Marc
runegan
Posts: 22
Joined: November 4th, 2016, 3:18 pm
Contact:

Hmm, when I try to run the script, and there is already a comp in the renderqueue, the script works just fine. What is not working for you?
MKonings
Posts: 3
Joined: January 13th, 2017, 3:33 am
Contact:

Hello again Rune,

I found yesterday night out that the AE template was buggy here, and after creating a new template it worked as well.

I thank you for the replies and the info you provided!
I am going to take a (slow) study in the sites you gave as a link :)

Marc
Post Reply