app.project.activeItem index

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
)orgen
Posts: 34
Joined: August 28th, 2006, 4:12 am

Hi, I'm trying to retrieve the index of app.project.activeItem. I get the name by doing app.project.activeItem.name but .index does not work. Any suggestions?
)orgen
Posts: 34
Joined: August 28th, 2006, 4:12 am

Sorry, that does not do what I need it to. I need the index of this object app.activeViewer. (anyone?)
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

You mean you want the index as it would be in app.project.items? I think that's the only way in which a CompItem has an index. You could loop through app.project.items comparing it to the CompItem you already have to find a match. CompItems do also have an .id which is a number unique to that item and won't change.

Paul
)orgen
Posts: 34
Joined: August 28th, 2006, 4:12 am

Hi Paul, what I'm trying to do is to identify what composition is open in the viewer. I'm building a interface for our promoproducers to interact with our after effects templates. When they reopen a saved project I need to know which comp they are looking at. Is it possible to get the name or .id of the comp that is active in the viewer?

When I do alert(app.activeViewer.type) I get "6812" but that number is the same for different compostions and I assume just means "composition"..

Any suggestions are much appreciated!! :)
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

You can get the id from app.project.activeItem.id but a possible problem with this is, if the project panel is active it will return the item selected in the project panel which may not be the currently open comp. If multiple items are selected in an active project panel, activeItem will return null.

So you could do this, but it may return misleading results as I've just explained:

Code: Select all

var activeItem = app.project.activeItem;
if  (activeItem != null && activeItem instanceof CompItem) {
	alert("comp id is " + activeItem.id + ", name is " + activeItem.name);
}
I've not played with the viewer functionality much, but it doesn't appear that you can get the actual CompItem object from it. You could do this to ensure that the comp is active (not the project panel) so the activeItem will definitely be the comp. This will work if the comp is active or it was the last previously active viewer if the project panel is currently selected.

Code: Select all

var viewer = app.activeViewer;
if (viewer.type == ViewerType.VIEWER_COMPOSITION) {
	viewer.setActive();
	alert("comp id is " + app.project.activeItem.id + ", name is " + app.project.activeItem.name);
	
} else {
	alert("comp viewer wasn't last active");
}
Once you've grabbed the CompItem object you could still loop through app.project.items, comparing if item == yourCompItemObject to figure out the index, but sticking with the id is safer because it won't change. The index is purely based on the current state of app.project.items and could change if the project changes. It isn't something actually associated with the item object (which is why you can't do item.index to find it).

If you use index you'll have to loop through the items at the initial stage to figure out the index, but then later you can access the comp directly using that index (assuming it's still accurate). Grabbing the id is easier at the initial stage, but then to find the comp again later you'll have to loop through app.project.items looking for the comp with that id (but at least it's guaranteed to be accurate).

Paul
)orgen
Posts: 34
Joined: August 28th, 2006, 4:12 am

That is very helpful. Thanks a lot Paul!! ;)
Post Reply