Skip to content

Commit

Permalink
Add 'Create Dropdown from Text'
Browse files Browse the repository at this point in the history
  • Loading branch information
zlovatt committed Oct 12, 2023
1 parent 4bc9f84 commit dccfeb5
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
112 changes: 112 additions & 0 deletions Create Dropdown From Text.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* Provides a panel to quickly create a populated dropdown effect on a layer
*
* @author Zack Lovatt <[email protected]>
* @version 0.1.0
*/
(function createDropdownFromText(thisObj) {
if (parseFloat(app.version) < 17.0) {
alert("This script requires AE 17.0 or newer to run!");
return;
}

var ui = _createUI(thisObj);
ui.show();

/**
* Builds UI
*
* @returns {Window | Panel} Created window
*/
function _createUI(thisObj) {
var win =
thisObj instanceof Panel
? thisObj
: new Window("palette", "Create Dropdown from Text", undefined, {
resizeable: true
});

win.orientation = "column";
win.margins = 5;
win.spacing = 5;

var pnlText = win.add("panel");
pnlText.preferredSize.width = 300;
pnlText.alignChildren = "fill";

pnlText.add("statictext", undefined, "Enter items below, one line per item.");
pnlText.add("statictext", undefined, "For a separator, use: (-");

var etInput = pnlText.add(
"edittext",
undefined,
["Enter", "Items", "Here"].join("\n"),
{ multiline: true }
);

var btnCreateDropdown = win.add(
"button",
undefined,
"Create Dropdown From Text"
);
btnCreateDropdown.onClick = function () {
// Trim the input
var input = etInput.text.replace(/^\s+|\s+$/g, "");

// Break it into lines
var inputSplit = input.replace(/\n\r|\n|\r/gm, "||||").split("||||");

// Check for empty text or empty split
if (input == "" || inputSplit.length == 0) {
alert("Enter some text!");
return;
}

// Validate vs AE rules
if (input.indexOf("|") > -1) {
alert("Text can't contain pipe symbol ('|')!");
return;
}

_createDropdown(inputSplit);
};

return win;
}

/**
* Creates a dropdown controller on the given layer with provided text
*
* @param {string[]} text Multiline text to create with
*/
function _createDropdown(text) {
var comp = app.project.activeItem;

if (!(comp && comp instanceof CompItem)) {
alert("Open a comp!", "Create Dropdown from Text");
return;
}

var layer = comp.selectedLayers[0];

if (!(layer && layer instanceof AVLayer)) {
alert("Select a layer!");
return;
}

app.beginUndoGroup("Create Dropdown from Text");

try {
// Create the dropdown effect & name it
var dropdownEffect = layer.effect.addProperty("ADBE Dropdown Control");
var updatedDropdown = dropdownEffect
.property(1)
.setPropertyParameters(text);
updatedDropdown.propertyGroup(1).name = "Created Dropdown";
} catch (e) {
alert(e, "Create Dropdown from Text");
} finally {
app.endUndoGroup();
}
}
})(this);
19 changes: 19 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ Creates a new null at the center of selected layers (or all comp layers, if none

---

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

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

</div>
<div>

Provides a panel to quickly create a populated dropdown effect on a layer.

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

---

<div>
<div>
<div>
Expand Down

0 comments on commit dccfeb5

Please sign in to comment.