creating layer markers with a script.

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
maxdido
Posts: 3
Joined: November 26th, 2006, 5:54 am

hi,

can someone help me writing a script with the following conditions:

I have a composition with 90 layers and on the beginning of every layer I need a marker with the chapter field, filled in, like: 01,02,03,04,etc.

I made a slideshow (for dvd) but I need to be able to go through them forward or backward. That's why I need markers, for adobe encore.
now I've done it manually (hell of a job) but I have 3 other compositions that I have to go through, so it would be nice if I could do this with a script.

thanks,
max.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Give this script a try. It numbers the chapters from top layer to bottom.

Paul T

Code: Select all

{
	var myMarker, currentLayer, chapterString;
	var activeItem = app.project.activeItem;

	if ( activeItem == null || ! activeItem instanceof CompItem) alert("You need to select a comp first.");
	else
	{
		app.beginUndoGroup("Add Chapter Markers");
		for ( var x = 1; x <= activeItem.layers.length; ++x)
		{
			currentLayer = activeItem.layer(x)
			chapterString = x.toString();
			if (chapterString.length == 1) chapterString = "0" + chapterString;
			myMarker = new MarkerValue("", chapterString);
			currentLayer.Marker.setValueAtTime(currentLayer.inPoint,myMarker)
		}	
		app.endUndoGroup();	
	}
}
maxdido
Posts: 3
Joined: November 26th, 2006, 5:54 am

cool man.
so simple and then I wonder why adobe didin't put this in after effects as a standard function?

Could you explain how this script is build. what lines or words do ....
I never used scripting before.
or am I asking to much.

thanks.
max.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

It'd be impossible to build in every possible function a user might need. Far better to provide the tools needed to create whatever functionality you want.

Here's a version of that script with comments:

Code: Select all

{
	// define variables;
	var myMarker, currentLayer, chapterString;

	// assign currently selected item to a variable;
	var activeItem = app.project.activeItem;

	// if nothing is selected, or it isn't a comp, post an alert;
	if ( activeItem == null || ! activeItem instanceof CompItem) alert("You need to select a comp first.");

	// otherwise...;
	else
	{
		// everything that happens next will be grouped into one undo;
		app.beginUndoGroup("Add Chapter Markers");

		// loop through the layers in the comp;
		for ( var x = 1; x <= activeItem.layers.length; ++x)
		{
			// assign current layer to a variable;
			currentLayer = activeItem.layer(x);

			// convert the layer number to a character string;
			chapterString = x.toString();

			// if there is only one character, put a zero in front of it;
			if (chapterString.length == 1) chapterString = "0" + chapterString;

			// create a new marker object;
			myMarker = new MarkerValue("", chapterString);

			// add that marker to the current layer's in point;
			currentLayer.Marker.setValueAtTime(currentLayer.inPoint,myMarker);
		}	
		app.endUndoGroup();	
	}
}

As for learning scripting yourself, there's some useful information in this post: viewtopic.php?t=240

On top of that my advice would be, if you haven't already, get comfortable using expressions first (both expressions and scripting are based on javascript), then start checking out other people's scripts, the included demo scripts, the AE scripting guide (on the AE CD-ROM) and generally be prepared to put in plenty of time.

Paul T
maxdido
Posts: 3
Joined: November 26th, 2006, 5:54 am

thanks very much.
I will follow your advise.

max.
Post Reply