🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.after.effects.scripting.render
Article #3

BUG & FIX: importFile() function AfterEffects 6.5 WIN

#3
From: jdnorthrup
Date: Wed, 28 Jul 2004 20:15
42 lines
2527 bytes
Hi all --

have been having fun with javascript in afx, but i ran into a bug with the built-in function importFile.

when i import multiple files in a script, successive calls to importFile return the FootageItem that was imported first, not each new item added. this is clearly not what's stated in the scripting guide.

for example, run this script on a project with at least three footage files already added:

      var sources = app.project.items; var myfname = sources[1].file.fsName;
      alert(app.project.importFile(new ImportOptions(new File(myfname))).id);
      myfname = sources[3].file.fsName; alert(app.project.importFile(new ImportOptions(new
      File(myfname))).id); myfname = sources[5].file.fsName; alert(app.project.importFile(new
      ImportOptions(new File(myfname))).id);




will incorrectly display the same id for each newly imported file.
the files themselves are imported correctly, but the returned item is wrong.

here's a function that works as intended:

// bug-fix for the built-in importFile function;
// returns proper FootageItem added
function importFile(theProject, myImportOpt) {
	// store the id's of the current FootageItems in an array
	var sources = theProject.items;
	var ids = new Array(sources.length+1);
	for (var i = 1; i <= sources.length; i++) { 		if(sources[i] instanceof FootageItem) { 			ids[i] = sources[i].id; 		} 	}

	// import the file and throw away the reference returned
        theProject.importFile( myImportOpt );

	// search for the new id and return the new FootageItem
	sources = theProject.items;
	for (var i = 1; i <= sources.length; i++) { 		if(sources[i] instanceof FootageItem) { 			if (ids[i] != sources[i].id) { 				return sources[i]; 			} 		} 	} }

enjoy!
jd
vision wise, inc.

jdn at raintone dot com
Technical Details
Message-ID: <3bb53e4e.-1@webx.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!proxad.net!proxad.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!demon!news.clara.net!wagner.news.clara.net!newsfeed01.sul.t-online.de!t-online.de!webx

Show Full Headers
Complete Article Headers
X-Google-Thread: 1efebe,fe822d1c54d3de64,start
X-Google-Attributes: gid1efebe,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: jdnorthrup@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!proxad.net!proxad.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!demon!news.clara.net!wagner.news.clara.net!newsfeed01.sul.t-online.de!t-online.de!webx
Newsgroups: adobe.after.effects.scripting.render
Subject: BUG & FIX: importFile() function AfterEffects 6.5 WIN
Message-ID: <3bb53e4e.-1@webx.la2eafNXanI>
Date: Wed, 28 Jul 2004 13:15:42 -0700
Lines: 60
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit