Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Count all markers on a layer with JavaScript

Explorer ,
Jun 17, 2010 Jun 17, 2010

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

TOPICS
Scripting
3.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 18, 2010 Jun 18, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 18, 2010 Jun 18, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 18, 2010 Jun 18, 2010

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){

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 18, 2010 Jun 18, 2010

Ah, okay.

So the property is always there.

Thanx.

:F

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 18, 2010 Jun 18, 2010
LATEST
 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines