ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Get layer from selected property (in a script)

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Pierre-Alain Lécroart
Get layer from selected property (in a script)
on May 4, 2020 at 10:00:01 am

Hi !

Disclaimer : I'm doing my first script ever

I'm looking for a function that would help me retrieve the layer of a selected property.
If I have this line :

//Get selected property
var myProperty = app.project.activeItem.selectedProperties[0];

How can I do something like this :

//Get layer of selected property
var myLayer = myProperty.parentLayer;



For now, my only solution is to stack a bunch of ".parentProperty" until I get something that I want but I don't find this really clean ☺

var selectedProperties = app.project.activeItem.selectedProperties;
for(var i=0; i < selectedProperties.length; i++) {
//If property is a group, try next property
if (selectedProperties[i].canAddProperty) {
continue;
}
var test = app.project.activeItem.selectedProperties[0].parentProperty.parentProperty.property("ADBE Effect Parade");
//Property is in a property from an effect
if (test == "Effects") {
var myLayer = app.project.activeItem.selectedProperties[i].parentProperty.parentProperty.parentProperty;
}
//Property is a transform property
else {
var myLayer = app.project.activeItem.selectedProperties[i].parentProperty;
}
}


Return to posts index

Dan Ebberts
Re: Get layer from selected property (in a script)
on May 4, 2020 at 5:53:00 pm

Try this:

var myProperty = app.project.activeItem.selectedProperties[0];
var myLayer = myProperty.propertyGroup(myProperty.propertyDepth);


Dan



Return to posts index

Pierre-Alain Lécroart
Re: Get layer from selected property (in a script)
on May 4, 2020 at 6:20:04 pm

Perfect solution ! Thanks a lot Dan.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]