ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Identifying a Video or image ExtendScript

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Avinash Ramanath
Identifying a Video or image ExtendScript
on Sep 21, 2018 at 1:11:15 pm

Hello,
Am trying to import a video file or image and move it to a folder called "Videos". But am unable to do so. Could you please have a look.

var myPath = "/Users/avinashramanath/Desktop/Video/1.mp4";

newFootageItem = app.project.importFile(new ImportOptions(new File(myPath)));

var compFolder = app.project.items.addFolder("Videos");
for(var i = 1; i &lt;= app.project.numItems; i++) {
if(app.project.item(i).hasVideo == true && item.hasAudio == true && item.duration != 0)

app.project.item(i).parentFolder = compFolder ;
}


Return to posts index

James Ronan
Re: Identifying a Video or image ExtendScript
on Sep 21, 2018 at 2:19:28 pm

If that's all you want to do, you don't need to loop through all the items in the project:



var myPath = "/Users/avinashramanath/Desktop/Video/1.mp4";

newFootageItem = app.project.importFile(new ImportOptions(new File(myPath)));

var compFolder = app.project.items.addFolder("Videos");
newFootageItem.parentFolder = compFolder ;


Return to posts index

Avinash Ramanath
Re: Identifying a Video or image ExtendScript
on Sep 21, 2018 at 2:43:54 pm

Yes thanks James. That worked. But I'm still wondering how to identify a video file or an image file via scripting.
For example a comp can be identified by instanceof CompItem.


Return to posts index


Avinash Ramanath
Re: Identifying a Video or image ExtendScript
on Sep 21, 2018 at 3:55:41 pm

Could you please tell me why the below code is omitting files with odd number names. Am very new to scripting and figuring out a lot of things

{
var targetFolder = File("/Users/avinashramanath/Desktop/Video");

if (targetFolder) {

var files = targetFolder.getFiles();



for (var i = 0; i &lt; files.length; i++)

{

try {

var importOptions = new ImportOptions (files[i]);

app.project.importFile (importOptions);

} catch (error) { /*alert(error.toString());*/}

}

}
}


{
var compFolder = app.project.items.addFolder("Assets");

for(var i = 1; i &lt;= app.project.numItems; i++)
{

if(app.project.item(i) instanceof FootageItem)

app.project.item(i).parentFolder = compFolder;

}
}


Return to posts index

James Ronan
Re: Identifying a Video or image ExtendScript
on Sep 22, 2018 at 8:18:15 am

Here is a basic example of determining whether it's an image or video:
It didn't omit odd file names for me.



var targetFolder = File("/Users/avinashramanath/Desktop/Video");
var compFolder = app.project.items.addFolder("Assets");

if (targetFolder) {

var files = targetFolder.getFiles();

for (var i = 0; i <= files.length; i++) {

try {

var importOptions = new ImportOptions(files[i]);
var newItem = app.project.importFile(importOptions);

if (newItem instanceof FootageItem && !newItem.mainSource.isStill) { // Check if Video or image

newItem.parentFolder = compFolder;

}

} catch (error) { /*alert(error.toString());*/ }

}
}



Return to posts index

Avinash Ramanath
Re: Identifying a Video or image ExtendScript
on Sep 22, 2018 at 4:38:00 pm

I don't know what am doing wrong here, must be in the for loop. The script seems to be selecting files with odd number names and only placing those inside the Assets folder. Please check the image to understand my problem,



// Select folder to import
var targetFolder = Folder.selectDialog("Import Files From Folder");
if (targetFolder)
{
var files = targetFolder.getFiles();
for (var i = 0; i &lt; files.length; i++)
{
try
{
var importOptions = new ImportOptions(files[i]);
app.project.importFile(importOptions);
}
catch (error)
{ /*alert(error.toString());*/ }
}
}
//create Assets folder
var compFolder = app.project.items.addFolder("Assets");
//collect items and move to Assets folder
var files = app.project.items.length;
for (var i = 1; i &lt;= files; i++)
{
if (app.project.item(i).hasVideo == true && app.project.item(i).hasAudio == false && app.project.item(i).duration == 0)
{ // Check if Video or image
app.project.item(i).parentFolder = compFolder;
}
else
if (app.project.item(i).hasVideo == true && app.project.item(i).hasAudio == true && app.project.item(i).duration !== 0)
{ // Check if Video or image
app.project.item(i).parentFolder = compFolder;
}
}


Return to posts index


Avinash Ramanath
Re: Identifying a Video or image ExtendScript
on Sep 22, 2018 at 4:39:21 pm

The wrong image uploaded in the previous post. Please see this one.



Return to posts index

Dan Ebberts
Re: Identifying a Video or image ExtendScript
on Sep 22, 2018 at 5:18:56 pm

You're changing the order of the items while you're looping through them. I would loop through all the items and store the ones that need to be moved into an array. Then loop through the array and move them into the compFolder.


Dan



Return to posts index

Avinash Ramanath
Re: Identifying a Video or image ExtendScript
on Sep 22, 2018 at 6:01:01 pm

Dan, could you please modify the script for me.


Return to posts index


Dan Ebberts
Re: Identifying a Video or image ExtendScript
on Sep 22, 2018 at 6:09:14 pm

I haven't tested it, but here you go:


// Select folder to import
var targetFolder = Folder.selectDialog("Import Files From Folder");
if (targetFolder)
{
var files = targetFolder.getFiles();
for (var i = 0; i < files.length; i++)
{
try
{
var importOptions = new ImportOptions(files[i]);
app.project.importFile(importOptions);
}
catch (error)
{ /*alert(error.toString());*/ }
}
}
//create Assets folder
var compFolder = app.project.items.addFolder("Assets");
//collect items and move to Assets folder
var files = app.project.items.length;
var myItems = [];
for (var i = 1; i <= files; i++)
{
if (app.project.item(i).hasVideo == true && app.project.item(i).hasAudio == false && app.project.item(i).duration == 0)
{ // Check if Video or image
myItems.push(app.project.item(i));
}
else
if (app.project.item(i).hasVideo == true && app.project.item(i).hasAudio == true && app.project.item(i).duration !== 0)
{ // Check if Video or image
myItems.push(app.project.item(i));
}
}
for (var i = 0; i < myItems.length; i++){
myItems[i].parentFolder = compFolder;
}



Dan



Return to posts index

Avinash Ramanath
Re: Identifying a Video or image ExtendScript
on Sep 22, 2018 at 6:13:29 pm

Yes Dan, it works fine now. Thanks to you James Ronan. I have learned a new thing now.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]