Activity › Forums › Adobe After Effects Expressions › Scripting – Set Layer Selection
-
Scripting – Set Layer Selection
Posted by Kevin Snyder on October 20, 2022 at 4:37 amI have a script that applies an effect. The effect has a layer dropdown menu. I would like to change the layer selected by inputting a numeric value. I’m not sure if this is close.
var myComp = app.project.activeItem;
var myLayers = myComp.selectedLayers[0];
myParent = myLayers.effect("Parent Me")("Select Parent");
myParent.selection = 3;
Kevin Snyder replied 1 year, 1 month ago 3 Members · 8 Replies -
8 Replies
-
Andrei Popa
October 20, 2022 at 6:10 amI think this should work
var myComp = app.project.activeItem;
var myLayers = myComp.selectedLayers[0];
myParent = myLayers.effect("Parent Me")("Select Parent");
myParent.setValue(3);
-
Kevin Snyder
October 20, 2022 at 2:46 pmThank you for your response. I gave it a go, but it doesn’t change the value. The effect is a pseudo-effect. Maybe that makes a difference?
-
Dan Ebberts
October 20, 2022 at 3:28 pmThat seems like the correct syntax, unless there’s something unusual going on. Maybe you can post a screen shot?
-
Kevin Snyder
October 20, 2022 at 4:06 pmI had another line of code that was interfering with it working. The last thing I would like to do is use the value from a text field box in the script to generate the number, but I might be going about it wrong.
var myComp = app.project.activeItem;
var myLayers = myComp.selectedLayers[0];
var myIndex = edittext1.value;
myParent = myLayers.effect("Parent Me")("Select Parent");
myParent.setValue(myIndex);
-
Dan Ebberts
October 20, 2022 at 4:11 pmDepending on what edittext1 is, it might be:
var myIndex = parseInt(edittext1.text,10);
-
Kevin Snyder
October 20, 2022 at 4:44 pmMaybe I have something in the text field incorrect? I still can’t get it to parse the value. My text field in the script is as follows.
var edittext1 = group1.add('edittext {justify: "center", properties: {name: "edittext1"}}');
edittext1.text = "";
edittext1.helpTip = "Enter the parent layer index.";
edittext1.preferredSize.width = 40;
-
Dan Ebberts
October 20, 2022 at 8:15 pmSo you did change from .value to .text in your myIndex definition and it didn’t help?
-
Kevin Snyder
October 20, 2022 at 8:28 pmI just realized that var edittext1 from the UI was outside the function so the value from the field wasn’t being transferred. It’s working now. Thank you for your help!
Reply to this Discussion! Login or Sign Up