Skip to content

Commit

Permalink
Add 'Create Layer Selector Dropdown'
Browse files Browse the repository at this point in the history
  • Loading branch information
zlovatt committed Sep 20, 2023
1 parent a918cd1 commit a74406e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
56 changes: 56 additions & 0 deletions Create Layer Selector Dropdown.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Creates a null with a dropdown menu to select any layer in current comp,
* toggling its visibility.
*
* Also adds dropdown to EGP.
*
* @author Zack Lovatt <[email protected]>
* @version 0.1.0
*/
(function createLayerSelectorDropdown() {
var comp = app.project.activeItem;

if (!(comp && comp instanceof CompItem)) {
alert("Open a comp!");
return;
}

var layers = comp.layers;
var layerNames = [];
var selectorName = comp.name + " Selector";
var controllerName = "_Controller";

app.beginUndoGroup("Toggle All Comp Expressions");

try {
// Add expression to all layers, and get their names
for (var ii = 1, il = layers.length; ii <= il; ii++) {
var layer = layers[ii];
layerNames.push(layer.name);

layer.opacity.expression = [
"posterizeTime(0);",
'const menu = thisComp.layer("' + controllerName + '").effect("' + selectorName + '")(1).value;',
"menu == index - 1 ? value : 0;"
].join("\n");
}

// Create control null
var controlNull = comp.layers.addNull();
controlNull.name = controllerName;
controlNull.guideLayer = true;
controlNull.label = 14;
controlNull.enabled = false;
controlNull.moveToBeginning();

// Create the dropdown effect & name it
var dropdownEffect = controlNull.effect.addProperty("ADBE Dropdown Control");
var updatedDropdown = dropdownEffect.property(1).setPropertyParameters(layerNames);
updatedDropdown.propertyGroup(1).name = selectorName;
updatedDropdown.addToMotionGraphicsTemplate(comp);
} catch (e) {
alert(e, "Create Layer Selector Dropdown");
} finally {
app.endUndoGroup();
}
})();
24 changes: 23 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Changes the background colour of all selected comps in the project panel to the
<div>
<div>

#### [Convert New Gaussian Blur to Old](<https://raw.githubusercontent.com/zlovatt/zl_Scriptlets/master/Convert New Gaussian Blur to Old.jsx>)
#### [Convert New Gaussian Blur to Old](<https://raw.githubusercontent.com/zlovatt/zl_Scriptlets/master/Convert New Gaussian Blur To Old.jsx>)

</div>
<div>
Expand Down Expand Up @@ -228,6 +228,28 @@ Creates a new null at the center of selected layers (or all comp layers, if none

---

<div>
<div>
<div>
<div>

#### [Create Layer Selector Dropdown](<https://raw.githubusercontent.com/zlovatt/zl_Scriptlets/master/Create Layer Selector Dropdown.jsx>)

</div>
<div>

Creates a null with a dropdown menu to select any layer in current comp,
toggling its visibility.

Also adds dropdown to EGP.

</div>
</div>
</div>
</div>

---

<div>
<div>
<div>
Expand Down

0 comments on commit a74406e

Please sign in to comment.