[?] Clone and remove trackers - not working

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Redsandro
Posts: 108
Joined: June 25th, 2008, 4:55 pm

Hi,

I am trying to make a script that takes a (selected) Tracker full of Tracker Points and makes multiple Trackers with a single Track Point each out of it.
This is because I like to track stuff at the same time, but TrackerViz wants tracks in separate trackers.

However, when I want to remove all Track Points except for one, it appears there are no Properties in the Property Group.

Look for this line:

Code: Select all

newProp[0].remove(); // THERE ARE NO PROPERTIES!?! But in AE there are.

Code: Select all

/**********
 *	RED TrackerUnique
 **********
 *	Filename:		RED TrackerUnique.jsx
 *	Written by:		Redsandro - http://www.rednet.nl/en/
 *	Date:			2009/03/19
 *	Last updated:
 **********
 *
 *	Description:
 *
 *	Turns a Tracker with many TrackPoints into a multiple Trackers with a single TrackPoint
 *
 **********/



clearOutput();

var myComp = app.project.activeItem;
if (myComp == null) {
	alert("No composition selected.");
}
else {
	// Local Vars
	var myLayers = myComp.selectedLayers;
	var selProp = myComp.selectedProperties;
	var expanded = 1;

	app.beginUndoGroup("Tracker Unique");

	// Walk Selected Properties
	for (var p = 0; p < selProp.length; p++) {
		if (selProp[p].matchName == "ADBE MTracker" ) { // Tracker Group found //MTrackers -> MTracker -> MTracker Pt
			var selPropNo = selProp[p].numProperties;
			if (selPropNo > 1) {		// Multiple trackpoints found
				for (var i in selProp[p]) {		// Walk Track Points
					// Create New Tracker
					var newProp = selProp[p].duplicate();
					for (var n = (selPropNo-1); n >= 0; n--)	// Remove other Track Points from clone
						if (n != i)
							newProp[0].remove(); // THERE ARE NO PROPERTIES!?! But in AE there are.
							//alert(newProp);
				}
				// Delete parent tracker
				selProp[p].remove();
			}
		}
	}

	app.endUndoGroup();
}
Who can help?
avi + m2t -> Vdub + DGIndex -> AE CS3 -> x264 -> Hell On Earth :mrgreen:
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Is it that you're treating a property group as an array? Maybe you need something more like:

Code: Select all

newProp.property(1).remove();
Redsandro
Posts: 108
Joined: June 25th, 2008, 4:55 pm

I thought all groups were sort of arrays. Anyway, using that syntax I still get
Unable to execute at line [you know]. Object is invalid.
avi + m2t -> Vdub + DGIndex -> AE CS3 -> x264 -> Hell On Earth :mrgreen:
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

It worked for me on the first pass through the loop, removing one of the track points from the duplicate group, then failed on this line:

Code: Select all

var newProp = selProp[p].duplicate();
Redsandro
Posts: 108
Joined: June 25th, 2008, 4:55 pm

You were right. I didn't notice it worked because a new tracker was copied, all points were deleted, and the empty tracker got auto-removed so nothing seemed to change.
That error you mentioned, I don't know why it occurs (yet) because it duplicates exactly wat was correctly duplicated in the first loop.

Here's the new loop:

Code: Select all

	for (var p = 0; p < selProp.length; p++) {//alert(selProp[p].matchName);
		if (selProp[p].matchName == "ADBE MTracker" ) { // Tracker Group found //MTrackers -> MTracker -> MTracker Pt
			var selPropNo = selProp[p].numProperties;
			if (selPropNo > 1) {		// Multiple trackpoints found
				// expand selProp
				for (var i=0; i<selPropNo; i++) {      // Walk Track Points
					// Create New Tracker
					var newProp = selProp[p].duplicate();
					for (var n=selPropNo; n>0; n--) {	// Remove other Track Points from clone
						if (n != i+1)
							newProp(n).remove();
					}
				}
				// Delete parent tracker
				selProp[p].remove();
			}
		}
	}
-edit-

After duplicate it seems to exclude itself from the selection even if the selection is hardlinked to another variable.
Do

Code: Select all

var newProp = selProp[p].duplicate();
var newProp = selProp[p].duplicate();
and the second one already gives an error.
avi + m2t -> Vdub + DGIndex -> AE CS3 -> x264 -> Hell On Earth :mrgreen:
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

I think that's because when you duplicate the first track the original selection is lost, so selProp.length then equals 0. To get around that you should make an array of the initial selected properties at the start.

Also I'm having a hard time following your logic as to why you're looping through selPropNo (which is the number of track points in the selected tracker) and the duplicate method is included in that loop.

I think you should put in loads of alerts so at all times you're aware of things like the value of p, i, selProp.length, selPropNo, etc, etc. That should help you figure out what's going wrong.
Redsandro
Posts: 108
Joined: June 25th, 2008, 4:55 pm

Please someone with more knowledge teach me a trick. Because I am thinking it is impossible.

I worked around the above limitation by putting the clones in an array:

Code: Select all

				// Create clones
				var sourceProp = Array(selPropNo);		// Array of clones
				sourceProp[0] = selProp[p].duplicate();	// After first clone, original is gone (??)
				for (var n=1; n<selPropNo; n++)	{		// So clone every new one instead 1-16
					sourceProp[n] = sourceProp[n-1].duplicate();	// Works, I get 16 duplicates in my timeline

					alert(sourceProp[n].matchName);
					alert(sourceProp[n-1].matchName); // THIS OBJECT IS NOW INVALID
Since the previous clone is invalid after another clone, how can I remove all but one tracker AFTER it is being cloned?
Headache for a small script.
avi + m2t -> Vdub + DGIndex -> AE CS3 -> x264 -> Hell On Earth :mrgreen:
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

This isn't very elegant, but it seems to work:

Code: Select all

{
	clearOutput();

	var myComp = app.project.activeItem;
	if (myComp == null) {
		alert("No composition selected.");
	} else {
		// Local Vars
		var myLayers = myComp.selectedLayers;
		var selProp = myComp.selectedProperties;
		var expanded = 1;

		var selPropTrackNameArray = new Array();	
		var selPropLayerArray = new Array();
		for (var x = 0; x < selProp.length; x++) {
			if (selProp[x].matchName == "ADBE MTracker" ) {
				selPropTrackNameArray[selPropTrackNameArray.length] = selProp[x].name;
				selPropLayerArray[selPropLayerArray.length] = selProp[x].propertyGroup(selProp[x].propertyDepth);
			}
		}
		app.beginUndoGroup("Tracker Unique");

		// Walk Selected Properties
		for (var p = 0; p < selPropTrackNameArray.length; p++) {//alert(selProp[p].matchName);

			var theTrack = selPropLayerArray[p].property("Motion Trackers").property(selPropTrackNameArray[p]);
			var selPropNo = theTrack.numProperties;
			if (selPropNo > 1) {      // Multiple trackpoints found
				// expand selProp
				for (var i=0; i<selPropNo; i++) {      // Walk Track Points

					// Create New Tracker
					var theTrack = selPropLayerArray[p].property("Motion Trackers").property(selPropTrackNameArray[p]);
					var newProp = theTrack.duplicate();
					for (var n=selPropNo; n>0; n--) {   // Remove other Track Points from clone
						if (n != i+1)
							newProp(n).remove();
					}
				}
				// Delete parent tracker
				var theTrack = selPropLayerArray[p].property("Motion Trackers").property(selPropTrackNameArray[p]);
				theTrack.remove();
			}
		}
		app.endUndoGroup();
	}
}
Redsandro
Posts: 108
Joined: June 25th, 2008, 4:55 pm

Wow, I didn't even notice this reply! How rude. Maybe it's because I am used to forums auto-subscribing you to your own topics.
Anyway, thank you! I do appreciate this.
I will check it out the next time I have to some tracker fun.
avi + m2t -> Vdub + DGIndex -> AE CS3 -> x264 -> Hell On Earth :mrgreen:
Redsandro
Posts: 108
Joined: June 25th, 2008, 4:55 pm

It works like a charm!
I don't really get why it must be like this, but your solution works!
Thanks.
avi + m2t -> Vdub + DGIndex -> AE CS3 -> x264 -> Hell On Earth :mrgreen:
Post Reply