reporting values, can't figure out why this won't work.

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
ScottG
Posts: 38
Joined: March 19th, 2006, 2:45 am

hey,

new to scripting. learning with the help of these forums, the dan ebberts stuff, jjgifford, creativecow, books, etc.

problem: i can't seem to pass along frameRate, pixelAspect or other numbers in the script i'm trying to write. i've cut out everything except the reporting for debug purposes. can someone tell me what is wrong with the following script? using the adobe reference etc, i can't see anything wrong with it, and yet my values are returned as "undefined".


{
// select the active item in the project window
// and make sure it's a comp

var myComp = app.project.activeItem;
if(myComp instanceof CompItem) {


// make sure one layer has been selected

var myLayers = myComp.selectedLayers;
if(myLayers.length = 1)
{

// put all attributes into variables that i can use later

var chosenLayer = myLayers[0];
var layerHeight = chosenLayer.height;
var layerWidth = chosenLayer.width;
var layerPixelAspect = chosenLayer.pixelAspect;
var layerDuration = chosenLayer.duration;
var layerFrameRate = chosenLayer.frameRate;
var backgroundColour = [0,0,0];


// report

alert("Height is " + layerHeight + ". Width is " + layerWidth + ". Duration of original layer is " + layerDuration + ". Pixel Aspect is " + layerPixelAspect + ". Frame Rate is " + layerFrameRate + ".");


}
else
{
alert("Please select a layer.");
}

}
else
{
alert("Please select a Composition.");
}


}

the problem is probably right in front of me, but i can't see the forest for the trees.
feedback much appreciated! thanks.
User avatar
redefinery
Posts: 112
Joined: April 1st, 2005, 8:16 pm
Location: CA
Contact:

Hi ScottG,

First thing I noticed (not related to your issue) is that your check for myLayers.length is using the assignment operator (=) instead of the comparison operator (==).

As for your question...you can get values for pixelAspect, duration, and frameRate for AVLayer objects, but these attributes are of AVItem, not AVLayer, so you need to reference them from the AVLayer.source attribute, as in:

var layerPixelAspect = chosenLayer.source.pixelAspect;
var layerDuration = chosenLayer.source.duration;
var layerFrameRate = chosenLayer.source.frameRate;

This will work only when you have an AVLayer selected, but will give undefined values for text, camera, and light layers. Solid footage layers have pixelAspect, but not duration (other than using the comp's duration) and frameRate. Text layers don't have useful width/height values (as they match the comp's dimensions), and their detection is different between AE 6.5 and 7.0.

(Detection of different layer types can be a little extra work. I documented most stuff on my web site at http://www.redefinery.com/ae/fundamentals/layers/, but I forgot to do SolidSource detection, though it is similar to the one shown for PlaceholderSource. I'll try to update sometime soon.)

Hope this helps.

Jeff
ScottG
Posts: 38
Joined: March 19th, 2006, 2:45 am

yes, that helps a lot! thankyou so much for explaining that to me. :)

when you say that these values will only work when a layer is selected, does that mean that the values will still persist when the layer is unselected? ie, i want to be able to use these values later in my script when i create 3 other comps, all of which i wish to inherit the attributes of the original source footage layer (duration, frame rate, size etc).
User avatar
redefinery
Posts: 112
Joined: April 1st, 2005, 8:16 pm
Location: CA
Contact:

I meant that you can access those attributes of the layer's source only if the layer is an AVLayer; text/camera/light layers don't have pixel aspect, duration (other than using the comp's duration), or frame rate values.

After the values are copied to your variables, you can use them later on in your script.

Jeff
ScottG
Posts: 38
Joined: March 19th, 2006, 2:45 am

Jeff,

That's an AWESOME website you have there, I shall be checking out your scripts as soon as I get a break from work!

Thanks so much for sharing your knowledge with the rest of us.

Regards,
Scott.
Post Reply