Skip to content

Instantly share code, notes, and snippets.

View GoodBoyNinja's full-sized avatar
🧠
You are a brain. Be a kind brain!

Good Boy Ninja GoodBoyNinja

🧠
You are a brain. Be a kind brain!
View GitHub Profile
@GoodBoyNinja
GoodBoyNinja / clampNum.jsx
Last active November 17, 2023 22:27
Clamp a number to be in a range. You can also use this to clamp an array of numbers (like an rgb array for example)
function ClampNum(num, min, max, inErrReturn) {
function SingleChannelClamp(num, min, max) {
if (
isNaN(num) ||
min == undefined ||
isNaN(min) ||
isNaN(max) ||
max == undefined
) {
return num;
@GoodBoyNinja
GoodBoyNinja / modNum.jsx
Last active November 17, 2023 22:27
Modulate a number, including negative numbers.
function ModNum (n, m) {
try {
if (n >= m || n <= 0) {
return ((n % m) + m) % m;
} else {
return n;
}
} catch (e) {
// maybe print or alert an error
return n;
@GoodBoyNinja
GoodBoyNinja / JSONforExpression.jsx
Last active November 17, 2023 22:27
A compact one line version of the json2.js JSON.stringify() and JSON.parse() functions. The function returns the library as a text string so you can use it in an expression.
function libForExpressions(){
var theLib = '(function includeJSON(){ if (!this.JSON) { this.JSON = {}; } (function () { function f(n) { return n < 10 ? \'0\' + n : n; } if (typeof Date.prototype.toJSON !== \'function\') { Date.prototype.toJSON = function (key) { return isFinite(this.valueOf()) ? this.getUTCFullYear() + \'-\' + f(this.getUTCMonth() + 1) + \'-\' + f(this.getUTCDate()) + \'T\' + f(this.getUTCHours()) + \':\' + f(this.getUTCMinutes()) + \':\' + f(this.getUTCSeconds()) + \'Z\' : null; }; String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function (key) { return this.valueOf(); }; } var cx = \/[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]\/g, escapable = \/[\\\\\\\"\\x00-\\x1f\\x7f-\\x9f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]\/g, gap, indent, meta = { \'\\b\': \'\\\\b\', \'\\t\': \'\\\\t\', \'\\n\': \'\\\\n
@GoodBoyNinja
GoodBoyNinja / renderChimeState.jsx
Created June 7, 2021 20:24
Get / Set render chime setting. You can use the get function to check whether it is enabled or not. Use the set function to set it to a new state.
function getRenderChimeState () {
try {
return app.preferences.getPrefAsLong(
"Misc Section",
"Play sound when render finishes",
PREFType.PREF_Type_MACHINE_INDEPENDENT
);
} catch (e) {
// something went wrong, maybe print or alert the error
return
@GoodBoyNinja
GoodBoyNinja / removeChildrenFromScriptUIItem.jsx
Created June 7, 2021 20:17
You can remove all the children of a group or a panel in a scriptUI panel using this function. Just pass that object to the function call
function RemoveAllChildrenFromPanel (panelObj) {
var panelObj = panelObj || undefined;
if (!panelObj || !panelObj.children || !panelObj.children.length) {
// no panel, or no children found
return;
}
for (var i = panelObj.children.length - 1; i >= 0; i--) {
var crntChildren = panelObj.children[i];
@GoodBoyNinja
GoodBoyNinja / refreshScriptUIGroupPanel.jsx
Last active November 17, 2023 22:28
If you are drawing something to a group or a panel using an onDraw() function, you can use this function to refresh the graphics of this panel on demand.
function RefreshPanel(panelObj) {
try {
if (!panelObj) {
// no panel or group passed to function
return false;
}
if (!panelObj.size) {
// size property of the panelObj wasn't found?
return false;
}
@GoodBoyNinja
GoodBoyNinja / paintPanelGroupScriptUI.jsx
Last active November 17, 2023 22:28
Use this to paint a group or a panel object by passing the object variable and an RGBA color ([x,x,x,x])
function FillPanel(panelOBJ, color) {
if (
panelOBJ &&
color &&
(panelOBJ.type == "panel" ||
panelOBJ.type == "group" ||
panelOBJ.type == "dialog" ||
panelOBJ.type == "palette" ||
panelOBJ.type == "window") &&
panelOBJ.graphics.BrushType
@GoodBoyNinja
GoodBoyNinja / StaticTextFillScriptUI.jsx
Created June 7, 2021 20:11
Pass in a staticText object and an rgba color array [x,x,x,x] to paint it
function FillText(textOBJ, color) {
if (textOBJ && color) {
var g = textOBJ.graphics;
g.foregroundColor = g.newPen(g.PenType.SOLID_COLOR, color, 1);
}
};
@GoodBoyNinja
GoodBoyNinja / GoodBoyNinjaColorPicker.jsx
Last active November 17, 2023 22:28
After-Effects Extendscript doesn't let you use the actual color picker ships with After-Effects. Using $.colorPicker() opens the OS color picker which sucks on windows. This method adds a temporary null to a comp, then uses the "Edit Value" command in order to launch the AE color picker. Once done, the function returns the data of the new color …
function GoodBoyNinjaColorPicker(startValue){
// find the active comp
var crntComp = app.project.activeItem;
if (!crntComp || !(crntComp instanceof CompItem)) {
alert("Please open a comp first");
return [];
}
// add a temp null;
var tempLayer = crntComp.layers.addShape();
function AllEffectsOnLayer(layer) {
if (layer !== undefined) {
// alert ("shit")
var effectsGroup = layer("ADBE Effect Parade");
//var effectsOnLayer = new Array();