Skip to main content
Inspiring
November 2, 2021
解決済み

How do I extract the name of the footage folder in Finder and pass it to a script?

  • November 2, 2021
  • 返信数 1.
  • 814 ビュー

I have a ScriptUI button that creates a comp of selected SWF files in my AE project panel and applies a few settings to them. You'll see how the comp is named "COMP_v01" but what I need is for the name to be taken from the name of the SWF folder in Finder. For example, the whole path might be "Volumes/Work/Project/MyGreatAnimation/Elephant/" with the 'Elephant' folder containing the SWFs. When I click the button I want the new comp to be named 'Elephant'.

 

         myPanel.grp.group2.swfSetup.onClick = function() {

            app.beginUndoGroup("SWF Setup")

            var myItems = app.project.selection;
            
             // Create comp
            var myComp = app.project.items.addComp("COMP_v01",1920,1080,1,60,24);

            // Put comp in the same folder as the selected footage
            myComp.parentFolder = myItems[0].parentFolder;

            // Create zAssets folder at comp location
            var myFolder = app.project.items.addFolder("zAssets");

            // Reverse for loop, so that the numerical layer names are listed correctly 00-99
            for (var i = myItems.length-1; i >= 0; i--) {

               var myItem = myItems[i];

               // Add selected footage
               myComp.layers.add(myItem);

               // Move footage to sub folder
               myFolder.parentFolder = myItems[0].parentFolder;
               myItems[i].parentFolder = myFolder;
               
               // Scale footage, and collapse tranformation
               //myComp.layer(1).transform.scale.setValue([200,200]);
               myComp.layer(1).collapseTransformation = true;
               
            }

            // Trim comp to duration of footage
            myComp.duration = myComp.layer(1).source.duration;

            // Deselects all items in the Project window
            var selectedItems = app.project.selection;
            for (var i = 0; i < selectedItems.length; i++)
               selectedItems[i].selected = false;

            // Selects the new comp
            myComp.selected = true;

            // Open comp
            myComp.openInViewer();
            
            app.endUndoGroup();

         }

 

For bonus points, I'd love it if the selected SWFs in the AE project panel could first be placed into a project panel folder named 'Elephants', before contiuing with the rest of the script.

 

I've taken this as far as I can right now, so any help is appreciated. Thanks!

このトピックへの返信は締め切られました。
解決に役立った回答 Paul Tuersley

Oops also aware that I missed off the semicolon from… 

var myItemsFolder = myItems.file.parent

 Told you I was rusty LOL. But it still doesnt work when added to it, so something else is broken.


Oh yeah, my bad. file.parent returns the Folder object, so you'd need file.parent.name

返信数 1

Inspiring
November 2, 2021

You can use myItem.file.parent to get the parent folder name from one of them, assuming they're all in the same system folder and all are FootageItems. Just access any one of myItems and do it before the loop.

 

https://ae-scripting.docsforadobe.dev/items/footageitem.html#footageitem-file

https://extendscript.docsforadobe.dev/file-system-access/file-object.html#file-object-properties

 

 

Mark Paterson作成者
Inspiring
November 2, 2021

Thanks! That definitely helps me on the right track but it's probably been a year since I touched scripting and i'm a little rusty.

 

I tried this, but it didn't work.

var myItems = app.project.selection;
var myItemsFolder = myItems.file.parent
            
// Create comp
var myComp = app.project.items.addComp(myItemsFolder,1920,1080,1,60,24);

 

If I replace myItems.file.parent with "test", that works. So I know it's being passed along, I just think I went wrong somewhere with your suggestion.

var myItems = app.project.selection;
var myItemsFolder = "test"
            
// Create comp
var myComp = app.project.items.addComp(myItemsFolder,1920,1080,1,60,24);
Mark Paterson作成者
Inspiring
November 2, 2021

MyItems is your array of selected items. You'll need to use just one so something like myItems[0].file.parent


Thanks. I'm getting somewhere. It now names the comp "Folder". I'm not sure where it's getting that name from though, as it's not the name of the footage folder in the Finder. All items are in the same folder.