FORUMS: list search recent posts

Loop through motion tracker points

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Bryan Woods
Loop through motion tracker points
on Sep 25, 2015 at 10:23:23 pm

Trying to figure out what the right syntax is for looping through a group of tracker points on a layer. I want to create a null for every tracker point present (not just Tracker, but for every tracker point, the one under "Tracker 1", "Tracker 2", etc...).

I'm assuming i'll need to first loop through my selected layers, then loop through all the motion trackers of that object, and kick out a new null object for each one found.


Return to posts index


Xavier Gomez
Re: Loop through motion tracker points
on Sep 27, 2015 at 1:07:40 pm

To access the feature center (say) of a tracker point :

myLayer.motionTracker(identifier1)(identifier2).featureCenter

where the identifiers are the name (string) or propertyIndex (number).
To loop through all trackers of a layer:

var i, I, tracker;
var j, J, trackerPoint;
for (I=myLayer.motionTracker.numProperties, i=1; i<=I; i++){
tracker = myLayer.motionTracker(i); // If not renamed, this is the thing called "Tracker i"
for (J=tracker.numProperties, j=1; j<=J; j++){
trackerPoint = tracker(j); // If not renamed, this is the thing called "Tracker Point j"
/* do something with that tracker point*/
};
};


Xavier


Return to posts index

Bryan Woods
Re: Loop through motion tracker points
on Sep 27, 2015 at 3:41:59 pm

AH, I new it would be a double loop, but just couldn't figure out the correct property names to get the tracker's points.

I'm noticing the first two variables seem to have multiple items in them. Is this a compact way of defining multiple variables on one line? I'm used to just "var "x" = "z"; I haven't seen comma separated values inside a defined variable before (aside from something like an array).

Thanks for your response Xavier! I'll try this out on monday and report back if I have any more issues or questions.


Return to posts index



Xavier Gomez
Re: Loop through motion tracker points
on Sep 27, 2015 at 5:38:33 pm

Yes you can define several variables in a row like above.

var x=0, y=0, z=3; // OK

...also works. It declares 3 variables and assigns them a value each;
But use with caution. For instance:

var x=y=0, z=3; // WRONG

isnt too good because it only declares x (and z) but not y.
If y has been declared, it will overwrite it, and if not it will create a variable y in the global workspace.


Return to posts index

Bryan Woods
Re: Loop through motion tracker points
on Sep 29, 2015 at 6:43:09 pm

Thanks Xavier. This all worked really well once I pulled it apart and got it working with my existing code.

One issue I'm having though is detecting if the layer actually has tracking data or not. Here's part of my code:


if (selectedLayers[i].property("motionTracker")){ // I would think this would work, but its not


Return to posts index


Xavier Gomez
Re: Loop through motion tracker points
on Oct 1, 2015 at 7:08:42 am
Last Edited By Xavier Gomez on Oct 1, 2015 at 7:10:38 am

Sorry, i didnt see your post immediately.


if (selectedLayers[i].property("motionTracker")){/**/}

==> this tells you if the layer has a motion tracker group, that is, can accept trackers.
I think (not sure) that only layers with matchName "AVLayer" can be tracked (Solids, precomps, footage, etc) but not cameras, lights, texts and shapes. So, it should be equivalent to (not sure..)
if (selectedLayers[i].matchName === "AVLayer"){/**/}

Nevermind. Then, if the first test is true, to check that the layer actually has tracker(s): if (myLayer.motionTracker.numProperties>0). Overall :

if (myLayer.motionTracker && myLayer.motionTracker.numProperties>0){/**/}

This tells if the motion tracker group exists and has trackers (hence is visible in the timeline).
It can still be that there are no tracker point in it, for instance the user deleted all tracker points...

One last thing, the notation "myLayer.motionTracker..." is the one that appears if you activate an expression somewhere on a tracker property. It's compact and handy, but you can also use matchNames:

whole tracker group : "ADBE MTrackers"
tracker 1: "ADBE MTracker"
tracker point 1: "ADBE MTracker Pt"

if (myLayer.property("ADBE MTrackers") && myLayer.property("ADBE MTrackers").numProperties>0){/**/}, etc

Xavier


Return to posts index


Bryan Woods
Re: Loop through motion tracker points
on Oct 1, 2015 at 11:09:01 pm

Thanks Xavier! That worked great.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]