-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'Create Layer Selector Dropdown'
- Loading branch information
Showing
2 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters