Skip to content

Commit

Permalink
Replace Item with Placeholder: Fix out-of-range values
Browse files Browse the repository at this point in the history
  • Loading branch information
zlovatt committed Aug 3, 2023
1 parent 19bc0af commit 88de275
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Replace Items With Placeholders.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Replaces all eligible selected items with placeholders
*
* @author Zack Lovatt <[email protected]>
* @version 0.1.0
* @version 0.1.1
*/
(function replaceItemsWithPlaceholders() {
var items = app.project.selection;
Expand All @@ -18,12 +18,13 @@
}

var oldName = item.name;

item.replaceWithPlaceholder(
ii.toString(),
item.width,
item.height,
item.frameRate,
item.duration
clamp(item.width, 4, 30000),
clamp(item.height, 4, 30000),
clamp(item.frameRate, 1, 99),
clamp(item.duration, 0, 10800)
);
item.name = oldName;
}
Expand All @@ -32,4 +33,15 @@
} finally {
app.endUndoGroup();
}

/**
* Clamps a value between min and max
*
* @param {number} value Number to clamp
* @param {number} min Min value
* @param {number} max Max value
*/
function clamp(value, min, max) {
return Math.max(Math.min(value, max), min);
}
})();

0 comments on commit 88de275

Please sign in to comment.