Copy link to clipboard
Copied
Hi.
I'm trying to (like the title says) count all markers on a layer with this code.
// CodeStart
function countMarkers(){
var layer = app.project.activeItem.selectedLayers[0];
var markers = layer.property("marker");
if(layer.property("marker").length==null){
alert("There are no Markers in this layer!");
}else{
alert("There are: "+ markers.length+" in this layer");
}
}
countMarkers();
//Code End
But that doesn't work.
I did some Indesign Scripting but i am totally new to scripting AE - seems like another world. So maybe the ".length" on my "markers" object is wrong. But how do i get the propertys "length"?
Another question is: Where can i find a complete reference for AE and JavaScript? I only found the AE CS3 Scripting Guide but nothing else. Does somebody know something like an "JavaDoc" or can i load the commands somehow in the Object Model Viewer of the Extended Toolkit. or or or …
Thanx a lot
:fabiantheblind
Copy link to clipboard
Copied
You need to use markers.numKeys instead of length. I believe you can't use .length because markers is a property object, not an array
Along with the AE CS3 scripting guide, you can see the changes in CS4 and 5 here:
http://blogs.adobe.com/toddkopriva/2008/12/after_effects_cs4_scripting_ch.html
http://blogs.adobe.com/toddkopriva/2010/04/scripting-changes-in-after-eff.html
And for generic Adobe scripting such as the UI and file system access:
http://www.adobe.com/devnet/scripting/
http://www.adobe.com/devnet/scripting/pdfs/javascript_tools_guide_cs4.pdf
Copy link to clipboard
Copied
Jiiihhaaa it works, thanx a lot, also for the links.
here the working code:
// code start countMarkers.jsx
function countMarkers(){
var layer = app.project.activeItem.selectedLayers[0];
var markers = layer.property("marker");
if(layer.property("marker").numKeys==null){
alert("There are no Markers in this layer!");
}else{
alert("There are: "+ markers.numKeys+" markers in this layer");
}
}
countMarkers();
//code end countMarkers.jsx
If somebody wants to know why:
I've been using the following script to make some subtitles. So it is nice to count all the markers before running the subtitles.jsx if u have an even number you have the right number of markers. Is it odd…
see the original post here: http://www.ithowto.ro/2008/12/adobe-after-effects-subtitle-script/
//code start subtitles.jsx
{
// Subtitle generator by !Rocky
// modified by Colin Harman ( http://colinharman.com/ ) to work on a Mac
//
// Save this code as
// "subtitles.jsx"
//
// Create a text file with your subtitles.
// Each line of text is one on-screen line.
// To have several lines on-screen at the same time,
// simply separate them with a pipe ( | ) character.
// eg "Character 1 talks|Character 2 interrupts"
//
// Create a new text layer in your comp, adjust its position,
// make sure the text's centered, so it looks nice
// Add markers (Numpad *) where each subtitle line must be shown/hidden.
// With the text layer selected, run the script, and select the subtitles file.
// Enjoy!
function makeSubs() {
var layer = app.project.activeItem.selectedLayers[0];
if (layer.property("sourceText") != null) {
var textFile = fileGetDialog("Select a text file to open.", "");
if (textFile != null) {
var textLines = new Array();
textFile.open("r", "TEXT", "????");
while (!textFile.eof) {
textLines[textLines.length] = textFile.readln();
}
textFile.close();
var sourceText = layer.property("sourceText");
var markers = layer.property("marker");
for (var i = sourceText.numKeys; i >= 1; i--)
sourceText.removeKey(i);
var line = 0;
var subTime, subText;
for (var i = 1; i <= markers.numKeys; i++) {
subTime = markers.keyTime(i);
sourceText.setValueAtTime(0, " ");
if ((i % 2) == 0) {
subText = " ";
}
else {
subText = textLines[line].replace("|", "\x0d\x0a");
line++;
}
sourceText.setValueAtTime(subTime, new TextDocument(subText));
}
}
}
}
makeSubs();
}
//code end subtitles.jsx
Copy link to clipboard
Copied
The code in your countMarkers.jsx example isn't quite right. Where you have:
if(layer.property("marker").numKeys==null){
it should be:
if(layer.property("marker").numKeys == 0){
Copy link to clipboard
Copied
Ah, okay.
So the property is always there.
Thanx.
:F
Copy link to clipboard
Copied
Find more inspiration, events, and resources on the new Adobe Community
Explore Now