Skip to content

Instantly share code, notes, and snippets.

@moelle89
Created January 10, 2024 21:23
Show Gist options
  • Save moelle89/6c59a89df8af262d01951458a886d677 to your computer and use it in GitHub Desktop.
Save moelle89/6c59a89df8af262d01951458a886d677 to your computer and use it in GitHub Desktop.
findReplaceString
// Function to replace composition name
function findReplaceCompositionName(prefix, replaceStr) {
// Get the current project
var currentProject = app.project;
// Check if a project is open
if (currentProject) {
// Get all compositions in the project
var allComps = currentProject.rootFolder.items;
// Loop through each composition
for (var i = 1; i <= allComps.length; i++) {
var comp = allComps[i];
// Check if it's a composition
if (comp instanceof CompItem) {
// Check if the composition name starts with the specified prefix
if (comp.name.indexOf(prefix) === 0) {
// Find the position of the next underscore after the prefix
var underscoreIndex = comp.name.indexOf("_", prefix.length);
// Check if an underscore is found
if (underscoreIndex !== -1) {
// Replace the portion of the composition name
comp.name = comp.name.substring(0, prefix.length) + replaceStr + comp.name.substring(underscoreIndex);
} else {
// If no underscore is found, replace the portion after the prefix
comp.name = comp.name.substring(0, prefix.length) + replaceStr;
}
}
}
}
} else {
// No project is open
alert("No project is currently open");
}
}
// Usage: Replace everything after "comp_" with "mustername"
findReplaceCompositionName("comp_", "mustername");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment