Motion Tracking script

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Q
Posts: 2
Joined: September 23rd, 2004, 2:35 pm

I'm relatively new to After Effects and I'm trying to write a script that will output the results (in this case, the feature center time history of each track point) of motion tracking to a file. However, I'm not sure how to access this data through a script. Currently, I can highlight the feature center label for each track point in the timeline and then copy and paste the data from After Effects into Excel or a text file, etc. Does anyone know how I can access the feature center time history using a script? I've been through the scripting guide and haven't been able to figure it out thus far. Thanks.

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

Hopefully this will help. I've included two techniques in this script. If you don't mind selecting the Feature Centre property before running your script, you can just use the bit near the start to access any currently selected property.

The main bulk of the script is set up to search through all selected layers for any Feature Centre properties. As you'll see, there are lots of sub levels of properties you need to go through to get to the Feature Center. i.e Motion Trackers > Tracker 1 > Track Point 1 > Feature Center.

Paul T

Code: Select all

{
	// make sure a comp is selected
	var activeItem = app.project.activeItem;
	if (activeItem == null || !(activeItem instanceof CompItem)){
		alert("You need to select a layer first.");

	} else {

		// this bit gives access to the first of any currently select properties
		if (activeItem.selectedProperties.length > 0) {
			alert(activeItem.selectedProperties[0].name + " is first select property");
		}

		// make sure at least one layer is selected
		var selectedLayers = activeItem.selectedLayers;
		if (activeItem.selectedLayers.length == 0 ) {
			alert("You need to select a layer first.");

		} else {

			// search through selected layers
			for (var i = 0; i < selectedLayers.length; ++i) {
				currentLayer = selectedLayers[i];
				alert("Searching " + currentLayer.name + " for top level properties");

				// search top level properties
				for (var g = 1; g <= currentLayer.numProperties; ++g) {
					currentProperty = currentLayer.property(g);
					alert("Found " + currentProperty.name);

					if (currentProperty.name == "Motion Trackers") {

						// search for each tracker
						for (var h = 1; h <= currentProperty.numProperties; ++h) {
							currentTracker = currentProperty.property(h);
							alert("Found " + currentTracker.name);
	
							// find each track point
							for (var i = 1; i <= currentTracker.numProperties; ++i) {
								currentTrackpoint = currentTracker.property(i);
								currentFeature = currentTrackpoint.property(1);
								alert("Found " + currentTrackpoint.name + " " + currentFeature.name + " with " + currentFeature.numKeys + " keyframes");
							}
						}
					}
				}
			}
		}
	}
}
Last edited by Paul Tuersley on March 13th, 2005, 3:06 am, edited 1 time in total.
Q
Posts: 2
Joined: September 23rd, 2004, 2:35 pm

Thanks Paul! That's exactly what I was looking for. I appreciate the assistance.

Q
Post Reply