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

Can anyone help out with a script or expression that can place a project's name on a slate? I always forget to update this f'n text and I get bitched at.

For some reason the render queue can call this info for the file name, but I can't figure a way to get it into a text layer or text option.

Can anyone help?

Thanks!
zold

scribling wrote:Can anyone help out with a script or expression that can place a project's name on a slate? I always forget to update this f'n text and I get bitched at.

For some reason the render queue can call this info for the file name, but I can't figure a way to get it into a text layer or text option.

Can anyone help?

Thanks!
Yes, this can be done - the question is: how do you want to implement it? Do you need the script to find specific comps and specific layers?

the project name is acquired by this kind of line:

Code: Select all

projName=app.project.file.name;
I would assume you have a comp that is the slate comp, with various art layers and text layers, and that one of the text layers would be the project name. If this is so, let's say the text layer in question is found and put into the variable "tLayer". This would do the final step:

Code: Select all

tLayer.sourceText.setValue(projName);
If you need a full script, post more details and I might be able to get to it tomorrow (it's time for me to go home and to bed now)

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

Thanks for the reply.

The slate is just an art layer with a bunch of expressions on "number" that retrieves frame numbers and the date ...

If I have to add another separate text layer that's fine. I hate having to go through each comp and change this every time I save a new version.

Oh, yea I do need a complete script. I'm horrible at java. VB I know, Java no.

If you are able to put together a script for me be sure and put your name on it. It'll be seen by a lot of people where I work.

Thanks!
zold

scribling wrote:I'm horrible at java. VB I know, Java no.
Just to be pedantic, Java has nothing to do with JavaScript, upon which AE's scripting language is based. It's actually an important distinction.

Hopefully the job I'm working on will end early-ish today (oh - now I've jinxed myself) and I can bang it out. If you don't mind, I will make it work with a separate text layer for the project name.

to be continued ...

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

You rock!
zold

scribling wrote:You rock!
Well, it turned into a long night, so I don't rock quite yet ...
zold

Okay, scribling.
Here it is. As the comments show, this script is meant to be run with the following criteria met:
1) There should be a text layer in your project which is meant to be used as the project name. The text of this text layer can be anything, but it MUST be named "this project" (by selecting it, hitting return key and typing in that phrase).
2) There should be ONLY ONE "this project" text layer.

I hope this is at least a good start. Let me know how it works for you.

Code: Select all

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

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

//YOU MUST SET THE NAME OF THE APPROPRIATE LAYER TO "this project" by
//  selecting the text layer and naming it with the return key, otherwise this script
//  will not be repeatable! In other words, do not use the source text of the layer
//  as the layer name. (Once you name it correctly, this script should work repeatedly.)

//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.

var p=app.project;
var projTLayersFound=[];
var projTextName = "this project";

//first, look for text layer called "this project"
//by looping 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 "this project" 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) ) {
			projTLayersFound[projTLayersFound.length] = currentLayer;
		}
		
	}//inner for
}//if compItem
}//outer for

if ( (projTLayersFound.length == 0) || (projTLayersFound.length > 1) ) {
	
	//this script is for a project with only one 'this project' slate text layer.:
	//if more than one are found, or if none is found, nothing happens and user is alerted
	
	alert( "Error: " + projTLayersFound.length + " Text Layers called \"this project\".");
	}
	else
	{
		//put inside undo block:
		app.beginUndoGroup("Update Project Name Text");
		//get project name:
		projName=p.file.name;
		//array of one layer is made into just layer:
		theOneTextLayer = projTLayersFound[0];
		//and its value is set:
		theOneTextLayer.sourceText.setValue(projName);
		//and we're done!
		app.endUndoGroup();
		
}
zold

OK, here's a bugfix. If there are spaces in your project name, the text of the "this project" text layer will include a "%20" instead of a space. A little awkward. Okay, very awkward. I'm sure other, less usual (like high-ascii) characters will yield equally annoying results. For now, here's a way to deal with the problem (apart from never using spaces in file names - I never do). The alteration of one line of code will take care of it.
I should also say that there isn't a heck of a lot of error correction here. For example, I didn't account for a project that has never been saved. Anyway, just to waste bytes, here's a new version of the script (you can play "find the changed line"!). Oh, and this assumes you'll never actually name a project with "%20" in the name :-):

Code: Select all

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

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

//YOU MUST SET THE NAME OF THE APPROPRIATE LAYER TO "this project" by
//  selecting the text layer and naming it with the return key, otherwise this script
//  will not be repeatable! In other words, do not use the source text of the layer
//  as the layer name. (Once you name it correctly, this script should work repeatedly.)

//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.

var p=app.project;
var projTLayersFound=[];
var projTextName = "this project";

//first, look for text layer called "this project"
//by looping 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 "this project" 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) ) {
			projTLayersFound[projTLayersFound.length] = currentLayer;
		}
		
	}//inner for
}//if compItem
}//outer for

if ( (projTLayersFound.length == 0) || (projTLayersFound.length > 1) ) {
	
	//this script is for a project with only one 'this project' slate text layer.:
	//if more than one are found, or if none is found, nothing happens and user is alerted
	
	alert( "Error: " + projTLayersFound.length + " Text Layers called \"this project\".");
	}
	else
	{
		//put inside undo block:
		app.beginUndoGroup("Update Project Name Text");
		//get project name:
		projName = p.file.name.replace(/%20/g, "_");
		//array of one layer is made into just layer:
		theOneTextLayer = projTLayersFound[0];
		//and its value is set:
		theOneTextLayer.sourceText.setValue(projName);
		//and we're done!
		app.endUndoGroup();
		
}
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

Thanks they both seem to work fine. We never have spaces in filenames so don't think that'd be a problem.

Thank you very much for taking the time to do this for me.

I have one question. Is there any way to do this same thing in an expression, so that it updates automatically?

I'm going to add this script to my pre-flight render script.

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

I'm almost always going to have multiple comps (different res) that need to be updated ... those are the ones I always forget.

How can I have this script update any text layer named "this project" in the entire project?

Thanks again.
zold

Hi again!

Re: expression:

I don't think this is possible. Expressions do not recognize the application or projects. It is possible to have a preflight script name a comp or layer and have an expression point to that name, but that is, as far as I know, the only way to do this.

Re: multiple 'this project' layers:

New version time!
I've moved things around a bit, and it's shorter. If it doesn't find any layers, it tells you so.

Code: Select all

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

//"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 "this project" (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 = "this project";
//get project name:
var projName = p.file.name.replace(/%20/g, "_");
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 "this project" 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 \"this project\" text layer found in this project!"); }
app.endUndoGroup();
scribling
Posts: 143
Joined: May 1st, 2005, 1:52 pm

Ok, what I did was add your code to the bottom of the "Save and Increment" Script. I had to write expressions to the one layer that it was working on but other than that it worked great. Although, I didn't think about this at the time ... it adds the entire file name including the ".aep" So, I had to mask that out. Other than that it was really cool to see the changes of save and increment on the slates.

Thanks!

I'll test the new one tomorrow. I'm really surprised this isn't a feature built in to AE.

Say, you wouldn't know how I can alter the script that appears in the file menu "Save and Increment" would you?
zold

scribling wrote:... it adds the entire file name including the ".aep"
Arrrrgh.
It's fairly trivial to add a little code to remove the '.aep'. I'll give you a line to replace. Use this:

Code: Select all

var projName = p.file.name.replace(/%20/g, "_").replace(/\.(.{3,4}$)/, "");
instead of the earlier version's "var projName" line.
This is slightly tricky use of regular expressions, which we won't get into right now, but what it should do is remove any three or four character extensions at the end of the string, so that "myproject.aep" or "myproject.proj" would become "myproject" (but files with no dot extensions would stay the same).
Say, you wouldn't know how I can alter the script that appears in the file menu "Save and Increment" would you?
I'm afraid you'd have to be part of Adobe's After Effects Development Team. That's not script-driven; it's hard-coded into the application.

hope this helps

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

I tried out the new script yesterday and it worked great. All slates were updated.

If I wanted to clip a few characters off the front of a filename how would I do that? I think that piece of code is a sinch for you.

As it turns out on the main slate they only want the version number rather than the whole name. I figured I'd name that one differently and duplicate the code to run on that one layer of text.
I need to turn "ADB02_v01_001.aep" into "v01_001"

Thanks again
zold

As I'm sure you anticipated, you'll need to change the "var projName" line again, this time to:

Code: Select all

var projName = (  p.file.name.replace(/%20/g, "_").replace(/\.(.{3,4}$)/, "").replace(/(^.{1,}?)\_/, "")  );
and that should do what you want.

I hope it works for you.

CG
Post Reply