ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

[Script UI] Create button with .onclick function for each layer on buttonclick

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jeroen Rommelaars
[Script UI] Create button with .onclick function for each layer on buttonclick
on Dec 20, 2017 at 1:53:55 pm
Last Edited By Jeroen Rommelaars on Dec 20, 2017 at 2:30:48 pm

Im trying to create new buttons for each layer in a 'master' comp, which all have a .onclick function corresponding to their layer index number - all on the press of a button.

Let me elaborate, as this all might be quite confusing:
I am filling a master comp with textual layers, which are refferenced troughout my projects. For standard layers I have created buttons. If i want to link a text layer somewhere in my animation to, for example, an emailadress - I click the button email adress. It then creates a new layer in the comp 'master' called email adress (if it doesnt already exist) and links the sourcetexts of the layers.

However, I also created a button to add 'new' layers to the master comp. This is used when I want to add non-standard layers, like for example social security number. It asks the layer name, and creates a corresponding layer in master comp with some expressions in place.

Finally - I have a 'Refresh UI' button, which checks if the layers in master comp are 'known layers'. If a layer is present which is not often used, like one created through the create layer button, it generates a new button for that layer with its layername as a button name. It skips layers that are hidden/or already have buttons created for them

So far, everything works.

However, those newly created buttons have no functions set for them

I need to create a .onclick command for each created button, and then add a function for each new button. Both the .onclick command as well as the function for that button need to have a unique index value corresponding to the layer index number. It is especially annoying that the function needs to be stored somewhere, so that it isnt overwritten by any newly detected layers.

My code looks like this so far for the creation of the buttons:
// Refresh function
function refreshFunction(){
for(i=1; i <= masterComp.numLayers; i++){
var layerName = masterComp.layer(i).name;
if (checkIfValueIsInArray(layerName, existingLayers) == false
&& masterComp.layer(i).shy!=true){

myPanel.grp.groupTwo.add("button",[1,1,80,20],layerName);
existingLayers.push(layerName);

}
}

myPanel.layout.layout(true);
return myPanel;

}

So far it creates a button with the layername, and add said layername to an array to exclude it from future button creations. This works, but im clueless on how to create and store functions for those created buttons.

Does anyone have ANY clue how to get this to work? Im running out of ideas 😉
I tried adding buttons and functions to arrays, but so far no luck. Any help is more than appreciated.

// Refresh function
function refreshFunction(){
for(i=1; i &lt;= masterComp.numLayers; i++){
var layerName = masterComp.layer(i).name;
if (checkIfValueIsInArray(layerName, existingLayers) == false
&& masterComp.layer(i).shy!=true){

myPanel.grp.groupTwo.add("button",[1,1,80,20],layerName);
existingLayers.push(layerName);

}
}

myPanel.layout.layout(true);
return myPanel;

}


Return to posts index

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