Retrieve project name and put on slate

What type of scripts do you need?

Moderator: byronnash

scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

I've edited the script a little. Here's what I've done:

Code: Select all

/////////////////////////////////////  Begin new script for slates

//"Update Project Name Text" script, version 1.3. 
//This script was created by Christopher R. Green on 5-8-2005 
//  (modified 5-9-2005) 
//  using Tex-Edit Plus and jEdit. 
//This script will look for all text layers named "projectname" (or whatever 
//  the variable below is set to) and set the source text of those layers to the project name. 

//If you have questions, you can make a post or 
//  send an email via creativecow.net (After Effects forum) 
//  or aenhancers.com (I am 'zold' there) 
//You are free to use this script however you please. 
//If you make changes to it, please tell me (CRG) about it. 

//put inside undo block: 
app.beginUndoGroup("Update Project Name Text"); 
var p=app.project; 
var projTLayersFound=[]; 
var projTextName = "projectname"; 
//get project name: 
var projName = p.file.name.replace(/%20/g, "_").replace(/\.(.{3,4}$)/, "");
var didNotFindOne = true; 

//loop through comps and layers: 
for (i = 1; i <= app.project.numItems; ++i) { //for/next loop goes through all project items 
   var currentComp = p.item(i); 
    
   if (currentComp instanceof CompItem) { //test if current item is a composition 
    
      //if it is a comp item, look for the "projectname" text layer 
       
      var theseLayers=currentComp.layers; 
       
      for (o = 1; o <= theseLayers.length; ++o) { //this loop goes through all layers 
       
      var currentLayer = theseLayers[o]; 
       
      //make sure it's a text layer, and that its name is correct 
      //(ignore if it's not a text layer or it's a text layer with wrong name) 
       
      if ( (currentLayer.property("sourceText") != null) && (currentLayer.name == projTextName) ) { 
               didNotFindOne = false; 
      //set its value:       
         currentLayer.sourceText.setValue(projName); 
      } 
       
   }//inner for 
}//if compItem 
}//outer for 
if (didNotFindOne) { alert("No \"projectname\" text layer found in this project!"); } 
app.endUndoGroup(); 
//End update slates named "projectname"

/////////////////////////////
////////////////////////////
////////////////////////////

//Begin update of main slate version number only text

//"Update Project Name Text" script, version 1.3. 
//This script was created by Christopher R. Green on 5-8-2005 
//  (modified 5-9-2005) 
//  using Tex-Edit Plus and jEdit. 
//This script will look for all text layers named "version" (or whatever the variable below is set to) and set the source text of those layers to the project name. 

//If you have questions, you can make a post or 
//  send an email via creativecow.net (After Effects forum) 
//  or aenhancers.com (I am 'zold' there) 
//You are free to use this script however you please. 
//If you make changes to it, please tell me (CRG) about it. 

//put inside undo block: 
app.beginUndoGroup("Update Project Slate Text"); 
var p=app.project; 
var projTLayersFound=[]; 
var projTextName = "version"; 
//get project name: 
var projName = (  p.file.name.replace(/%20/g, "_").replace(/\.(.{3,4}$)/, "").replace(/(^.{1,}?)\_/, "")  );var didNotFindOne = true; 

//loop through comps and layers: 
for (i = 1; i <= app.project.numItems; ++i) { //for/next loop goes through all project items 
   var currentComp = p.item(i); 
    
   if (currentComp instanceof CompItem) { //test if current item is a composition 
    
      //if it is a comp item, look for the "version" text layer 
       
      var theseLayers=currentComp.layers; 
       
      for (o = 1; o <= theseLayers.length; ++o) { //this loop goes through all layers 
       
      var currentLayer = theseLayers[o]; 
       
      //make sure it's a text layer, and that its name is correct 
      //(ignore if it's not a text layer or it's a text layer with wrong name) 
       
      if ( (currentLayer.property("sourceText") != null) && (currentLayer.name == projTextName) ) { 
               didNotFindOne = false; 
      //set its value:       
         currentLayer.sourceText.setValue(projName); 
      } 
       
   }//inner for 
}//if compItem 
}//outer for 
if (didNotFindOne) { alert("No \"version\" text layer found in this project!"); } 
app.endUndoGroup(); 
Thanks a lot for your help.
zold

Hi scrib.
I have to say that looking at this code is a little painful because it is ... gulp ... inefficient!
I might crunch it down to a small efficient version if I get the chance later today.

-cg
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

Yea, a bit long and probably clumsy... but you get it ... one to write the slate text which is just the version number then the other to put the enire, well almost, filename onto the burnin text.

It works well though. The only thing is that I can't seem to write a script that creates these text layers and places them where I want. I guess I can do some things manually.

Thanks again! You do rock!

In the future watch for a movie called "Running Scared" I'm working on it now and it looks insane and intense!
zold

scribling wrote:The only thing is that I can't seem to write a script that creates these text layers and places them where I want
Why not create a sort of 'template' project that is just slate stuff that you import into new projects. In other words, why would you need to script the creation and placement of text layers?

cg
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

I made the template a while ago... but I've got a lot of shots that have the old slates still in them... when I revisit the shot I update everything. From now on the template will work the best.

These scripts are really sweet. Now I just hit my Render locations script containing the slate updates which also sets my project to 16 bit which I always forget and I'm good to go - the first time - every time!

Thanks again.
zold

scribling wrote:I made the template a while ago... but I've got a lot of shots that have the old slates still in them... when I revisit the shot I update everything. From now on the template will work the best.

Thanks again.
Well, I'm sure it's possible to automate the process of updating those projects. It would take a little doing, though.

As for the next version of the script. It is below. It always reports ("alert"s) how many of each text layer it finds and changes. You can comment that line out if it bugs you. Actually, I don't know what platform you're on, but if you're on a windows machine, I'd be really curious to know how what that alert looks like on your machine.
Anyway, enjoy

CG

Code: Select all

////////////////////////////////////////
//"Update Project Name Text" script, version 1.6.
//This script was created by Christopher R. Green on 5-8-2005
//  (modified 5-15-2005)
//  using Tex-Edit Plus and jEdit.
//This script will look for all text layers named "projectname" and "version" (or whatever
//  the variables below are set to) and set the source text of those layers.

//If you have questions, you can make a post or
//  send an email via creativecow.net (After Effects forum)
//  or aenhancers.com (I am 'zold' there)
//You are free to use this script however you please.
//If you make changes to it, please tell me (CRG) about it.

//put inside undo block:
app.beginUndoGroup("Update Project Name Text");
var p=app.project;
var projTLayersFound=[];

var projTextName = "projectname";
var slateVersName = "version";

//get project name:
//this assumes a project name of the format <foo_v##_##.???> or <foo_v##_##.????> where ??? and ???? are 3 and 4 character file extensions
//the first line here strips the extension, the 2nd line strips the extension and the first part of the base name before the underscore
var projName = p.file.name.replace(/%20/g, "_").replace(/\.(.{3,4}$)/, "");
var versText = (  p.file.name.replace(/%20/g, "_").replace(/\.(.{3,4}$)/, "").replace(/(^.{1,}?)\_/, "")  );
var projTLayersFound = 0;
var versTLayersFound = 0;

//loop through comps and layers:
for (i = 1; i <= app.project.numItems; ++i) { //for/next loop goes through all project items
   var currentComp = p.item(i);
   
   if (currentComp instanceof CompItem) { //test if current item is a composition
   
      //if it is a comp item, look for the "projectname" text layer
      //  and look for the "version" text layer
      
      var theseLayers=currentComp.layers;
       
      for (o = 1; o <= theseLayers.length; ++o) { //this loop goes through all layers
       
         var currentLayer = theseLayers[o];
       
         //make sure it's a text layer, and that its name is correct
         //(ignore if it's not a text layer or it's a text layer with wrong name)
       
         if ( currentLayer.property("sourceText") != null) {
         
            if (currentLayer.name == projTextName ) {
               projTLayersFound = (projTLayersFound + 1);
              //set its value:
               currentLayer.sourceText.setValue(projName);
            } else if (currentLayer.name == slateVersName ) {
               versTLayersFound = (versTLayersFound + 1);
              //set its value:       
               currentLayer.sourceText.setValue(versText);
            }
           }
   }//inner for
}//if compItem
}//outer for

alert("\n" + """ + projTextName + "" text layers found: " + projTLayersFound + "\n" + """ + slateVersName + "" text layers found: " + versTLayersFound);

app.endUndoGroup();
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

That script is sweet. I'm at a new job now so I may have to change it a bit again.

Can you tell me what the code is for setting the project to 16 bit? I forgot.

Thanks
zold

scribling wrote:
Can you tell me what the code is for setting the project to 16 bit? I forgot.
You can find that information in the "Scripting Guide.pdf" document which is on the After Effects install CD.

It's something like

app.project.bitsPerChannel
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

I don't have the install CD. This box was set up for me before I got here. I'll see if I can get someone to find it, but in the meantime you think it's
"app.project.16"
zold

scribling wrote:I don't have the install CD. This box was set up for me before I got here. I'll see if I can get someone to find it, but in the meantime you think it's
"app.project.16"
If you're using scripting like this, you should consider that using that basic documentation is essential, and your current employer should know that (i.e. should be advised toward that direction). You should also look up some basic JavaScript tutorials, which are all over the place. You can do a search for "ECMAScript Language Specification" and you'll find the basic specifications upon which all this is based.

You might even be able to find the After Effects Scripting guide online, if you're really clever :-)

If you want to change the project to 16 bit, the syntax is probably:

Code: Select all

app.project.bitsPerChannel = 16;
finding out what value the current project could be done thusly:

Code: Select all

bpc = app.project.bitsPerChannel;
alert("This project is " + bpc + " bits per channel!");
Now if I can get on a Windows box for more than two seconds and find out why the 'slate' script I wrote for you doesn't work on AE for Windows ....
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

Thanks again for the code. I'll see if I can find that scripting guide.

I'm using the scrips on a windoze box and they work fine. I've also used them on X and they work fine there too.

Thanks
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

I can't get this to work: A text layer with the expression in the source text that will auto insert the name of that comp.

I've tried:

Comp.thisComp
thisComp
Comp(thisComp)

What am I missing?
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

thisProperty = thisComp.name

I was just about to bash in my computer screen when I tried this and it worked.

Whoever wrote the scripting guide and the AE help file on this should be taken out back and scrubbed with a wire brush!

The examples they wrote don't even work.
kennethbonde
Posts: 7
Joined: March 17th, 2008, 3:25 pm

Nice script but would it possible to change it to an expression?

I need a slate where the date is the render date, not to date the script was run.

>kenneth
Post Reply