Highlighted

Can a script rename footage in the Project window and also in Finder without breaking links?

Participant ,
Nov 12, 2020

Copy link to clipboard

Copied

I'm using the brand new Timelord extension which easily imports multiple Animate SWF layers directly into AE.

 

The trouble is, the exported SWFs are simply named after the layer in Animate. This makes sense for most users. However, for our specific workflow I need to prefix the names with the name of the FLA file they came from. So the new worklow involves exporting the layers from Animate using Timelord, they are then automatically copied in to AE, I then need to rename them in the Finder, and then manually re-link each file in AE. Not ideal!

 

I would want to select multiple SWF files in the project window, then hit a Script UI button that asks me what prefix I want to use, which I would then type in. That name would then also get automatically written to the file in Finder without breaking the AE projects link to that file. Is this possible?

TOPICS
Scripting

Views

33

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Can a script rename footage in the Project window and also in Finder without breaking links?

Participant ,
Nov 12, 2020

Copy link to clipboard

Copied

I'm using the brand new Timelord extension which easily imports multiple Animate SWF layers directly into AE.

 

The trouble is, the exported SWFs are simply named after the layer in Animate. This makes sense for most users. However, for our specific workflow I need to prefix the names with the name of the FLA file they came from. So the new worklow involves exporting the layers from Animate using Timelord, they are then automatically copied in to AE, I then need to rename them in the Finder, and then manually re-link each file in AE. Not ideal!

 

I would want to select multiple SWF files in the project window, then hit a Script UI button that asks me what prefix I want to use, which I would then type in. That name would then also get automatically written to the file in Finder without breaking the AE projects link to that file. Is this possible?

TOPICS
Scripting

Views

34

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 12, 2020 0
Participant ,
Nov 12, 2020

Copy link to clipboard

Copied

This is how far I've got up to now…

 

// Get selected item
var myItem = app.project.activeItem;

// This is the new name
var myNewName = "new_name.swf";

// Rename Footage
myItem.name = myNewName;

// Rename File
myItem.file.rename(myNewName);

// Replace footage
var myPath = "~/Desktop/TEST/"+myNewName;
myItem.replace(File(myPath));

 

 
I just need to figure out how to change it from a hard coded variable to something that prompts the user for a name instead. And I guess also something which uses the current SWF folder and not a test folder on the desktop. hmm.

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 12, 2020 0
Participant ,
Nov 12, 2020

Copy link to clipboard

Copied

Or should I say… something that prompts the user for a *prefix* to the current name

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 12, 2020 0
Participant ,
Nov 12, 2020

Copy link to clipboard

Copied

I've made a little more progress. The user is now prompted for a prefix.

var myItem = app.project.activeItem;
var oldName = myItem.name.substring(0, myItem.name.lastIndexOf("."));
var spacer = " - "
var fileExt = ".swf"

// Prompt for prefix
var myNewName = prompt('Enter a prefix', oldName);

// Assemble new footage name
myItem.name = myNewName+spacer+oldName+fileExt;

// Assemble new file name
myItem.file.rename(myNewName+spacer+oldName+fileExt);

// Replace missing footage
var myPath = "~/Desktop/TEST/"+myNewName+spacer+oldName+fileExt;
myItem.replace(File(myPath));

 

All I need to solve now is to (1) make it work with multiple files at once, and (2) change the hard coded myPath to instead be the current path the footage was/is located. I'm stuck though, so any help would be appreciated!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 12, 2020 0
Participant ,
Nov 12, 2020

Copy link to clipboard

Copied

Got even further. I figured out how to replace the footage no matter where it is located, using fsName and then regEx to remove the file name, leaving only the path, which I then add the newName variable to.

 

 

var myItem = app.project.activeItem;

var oldName = myItem.name.substring(0, myItem.name.lastIndexOf("."));

var spacer = " - ";
var fileExt = ".swf";

var path = myItem.file.fsName;

// Strip filename from the path
var regEx = /[^\/]*$/;
var dirOnly = path.replace(regEx, '');

// Prompt for prefix
var prefix = prompt("Enter a prefix", "SH_20X_ST-XX-0XX_v0X");

// Assemble new footage name
myItem.name = prefix+spacer+oldName+fileExt;

// Assemble new file name
var newName = myItem.name;
myItem.file.rename(newName);

// Replace missing footage
myItem.replace(File(dirOnly+newName));

 

It works perfectly for single selections. The only part i'm genuinely stuck on now is how to make this work for multiple selections. I believe I need to change the first line to var myItem = app.project.selected; but when I do that, it says there's an error at line 3 (the var oldName line). The error is "Undefined is not an object". This is my brick wall. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 12, 2020 0
Participant ,
Nov 13, 2020

Copy link to clipboard

Copied

Ok. So I'm basically done here. It now runs on multiple selections.

 

The only issue I have now is that if I cancel the rename prompt, the footage and files are renamed anyway, but with a "null" prefix. How do I stop that from happening?

 

var items = app.project.selection;

// Prompt for prefix
var prefix = prompt("Enter a prefix", "SH_20X_ST-XX-0XX_v0X");
         
// Rename Loop
for(var i = 0; i < items.length; i++) {
var myItem = items[i];
         
// Strip extension from old name
var oldName = myItem.name.substring(0, myItem.name.lastIndexOf("."));
         
var spacer = " - ";
var fileExt = ".swf";
         
var path = myItem.file.fsName;
         
// Strip filename from the path
var regEx = /[^\/]*$/;
var dirOnly = path.replace(regEx, '');
         
// Assemble new footage name
myItem.name = prefix+spacer+oldName+fileExt;
         
// Assemble new file name
var newName = myItem.name;
myItem.file.rename(newName);
         
// Replace missing footage
myItem.replace(File(dirOnly+newName));

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 13, 2020 0