Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
dcrooks
Topic Author
Posts: 8
Joined: Tue Dec 14, 2010 9:13 pm

function to select comps weirdness ???

Thu Oct 29, 2015 4:44 pm

hi

I wrote a function a while back to return an array of selected comps, either the frontmost comp timeline or the comps in the Project Panel if it is front most. The idea is that if the user was viewing a comp's Timeline (or viewer window) it would only return an array with ONLY that single comp, but if the user was looking at the Project Panel and had selected multiple comps there the function would return ALL those selected comps. It works a treat.

But... I've just noticed a weird behaviour which I can't for the life of me work out. If a project is opened fresh and I go straight to the Project Panel and select 2 or more comp items and run my script the function sees the Comp timeline panel (or the viewer) which is in the background as being the active Item and only returns that single comp. If I then bring the comp Timeline to the front momentarily and then go back to the Project Panel and select one or more comp items then the function works as expected. It is only this first time behaviour that is odd.

to be honest I find the whole task of determining which panel the user is currently interacting with quite confusing...

Any ideas as to why this is happening very greatly appreciated !

heres's the code

var selComps = selectComps();
alert(selComps.length);

function selectComps(){     //returns an array of the selected comps using either the front most timeline or any comps selected in the project panel if it is front most

    var activeItem = app.project.activeItem;
    var projectSelection = app.project.selection;
    var selComps = [];

    if(activeItem != null){                         //use front most timeline
        if(activeItem.layers && app.activeViewer.type != ViewerType.VIEWER_FOOTAGE){
            selComps[0] = activeItem;
        }
    }
    else if(activeItem == null){                // use project selection instead and check for comps
        for(i=0;i<projectSelection.length;i++){
            if(projectSelection[i].typeName== "Composition"){
                selComps.push(projectSelection[i])
            }
        }
    }
    return selComps
}

Who is online

Users browsing this forum: No registered users and 6 guests