Page 1 of 1
Create Layer Markers from XML File & render these seqs.
Posted: August 8th, 2007, 12:31 pm
by menonerd
Hi guys,
i need to create a bunch of markers from an XML-file on some layer, maybe a null or something. the xml contains a timecode (millisecs) and according marker names. is there an easy way to do this?
i have accomplished this in flash using actionscript but i am new to AE scripting and cannot imagine how i would do this...
and while we're at it: i wish i had a script allowing for automatically sending sequences between layer markers to the render queue (to "chop up" my video file), preferably with the comment of the preceeding marker as output file name (using the custom render settings i set as standard).
any ideas anyone..?
thank you!!
Posted: August 9th, 2007, 5:40 am
by Atomic
You could take a look at these scripts I found on this site.
Here is one that has some code for creating a marker.
viewtopic.php?t=543
Code: Select all
{
// define variables;
var myMarker, currentLayer, chapterString;
// assign currently selected item to a variable;
var activeItem = app.project.activeItem;
// if nothing is selected, or it isn't a comp, post an alert;
if ( activeItem == null || ! activeItem instanceof CompItem) alert("You need to select a comp first.");
// otherwise...;
else
{
// everything that happens next will be grouped into one undo;
app.beginUndoGroup("Add Chapter Markers");
// loop through the layers in the comp;
for ( var x = 1; x <= activeItem.layers.length; ++x)
{
// assign current layer to a variable;
currentLayer = activeItem.layer(x);
// convert the layer number to a character string;
chapterString = x.toString();
// if there is only one character, put a zero in front of it;
if (chapterString.length == 1) chapterString = "0" + chapterString;
// create a new marker object;
myMarker = new MarkerValue("", chapterString);
// add that marker to the current layer's in point;
currentLayer.Marker.setValueAtTime(currentLayer.inPoint,myMarker);
}
app.endUndoGroup();
}
}
This one reads a folder of images, then looks at the first layer in a comp. It examines the markers in the layer and places the images in the folder at the markers and extends their in and out points.
viewtopic.php?t=719
Code: Select all
{
//Functions used by this script.
function processFile (theFile)
{
writeLn("Processing file: " + theFile.name);
try
{
var importOptions = new ImportOptions (theFile); //create a variable containing ImportOptions
importSafeWithError (importOptions);
}
catch( error )
{
// display errors.
writeLn(error);
}
}
function testForSequence (files)
{
var searcher = new RegExp ("[0-9]+");
var movieFileSearcher = new RegExp ("(mov|avi|mpg)$", "i");
var parseResults = new Array;
for (x = 0; (x < files.length) & x < 10; x++)
{
//test that we have a sequence, stop parsing after 10 files
var movieFileResult = movieFileSearcher.exec(files[x].name);
if (! movieFileResult)
{
var currentResult = searcher.exec(files[x].name);
//regular expressions return null if no match was found
//otherwise they return an array with the following information:
//array[0] = the matched string
//array[1..n] = the matched capturing parentheses
if (currentResult)
{ //we have a match - the string contains numbers
//the match of those numbers is stored in the array[1]
//take that number and save it into parseResults
parseResults[parseResults.length] = currentResult[0];
}
else
{
parseResults[parseResults.length] = null;
}
}
else
{
parseResults[parseResults.length] = null;
}
}
//if all the files we just went through have a number in their file names,
//assume they are part of a sequence & return the first file
var result = null;
for (i = 0; i < parseResults.length; ++i)
{
if (parseResults[i])
{
if (! result)
{
result = files[i];
}
}
else
{
//case in which a file name did not contain a number
result = null;
break;
}
}
return result;
}
function importSafeWithError (importOptions)
{
try
{
app.project.importFile (importOptions);
} catch (error)
{
alert(error.toString() + importOptions.file.fsName);
}
}
function processFolder(theFolder)
{
var files = theFolder.getFiles(); //Get an array of files in the target folder
//test whether theFolder contains a sequence
//var sequenceStartFile = testForSequence(files);
var sequenceStartFile =null;
//if it does contain a sequence, import the sequence
if (sequenceStartFile)
{
try
{
var importOptions = new ImportOptions (sequenceStartFile); //create a variable containing ImportOptions
importOptions.sequence = true;
//importOptions.forceAlphabetical = true; //un-comment this if you want to force alpha order by default
importSafeWithError (importOptions);
}
catch (error)
{
// display errors.
writeLn(error);
}
}
//otherwise, import the files and recurse
for (index in files)
{ //Go through the array and set each element to singleFile, then run the following
if (files[index] instanceof File)
{
if (! sequenceStartFile)
{ //if file is already part of a sequence, don't import it individually
processFile (files[index]); //calls the processFile function above
}
}
if (files[index] instanceof Folder)
{
processFolder (files[index]); // recursion
}
}
}
// create project if necessary
var proj = app.project;
if(!proj) proj = app.newProject();
try
{
//set currently selected comp to variable
var myComp = app.project.activeItem;
var shouldContinue = confirm("This script will operate on the selected comp named: " + myComp.name + " do you want to continue?");
if (shouldContinue == true)
{
//Begin the script by creating an undo group.
app.beginUndoGroup("Create Image Layers From Folder");
//Ask the user for a folder whose contents are to be imported
var targetFolder = folderGetDialog("Import Items from Folder..."); //returns a folder or null
if (targetFolder)
{
// if no project open, create a new project to toss the files into.
if (!app.project)
{
app.newProject();
}
//Import folder items into the project window.
processFolder(targetFolder);
//Take advantage of the fact that after footage is imported, it is selected in the project window.
var projSelection = app.project.selection; //Set selected import items to an array.
//Set our defaults.
var markerTime;
var myCount = 1;
var myImageDuration = 5; //In seconds.
var myImageEnterSpeed = 0.25; //In seconds.
var myImageExitSpeed = 0.25; //In seconds.
var compW = myComp.width;
var compH = myComp.height;
var widthDiv4 = myComp.width/4;
var blurStrength = 150;
var blurAngle = -90;
//The marker layer is assumed to be in the comp and be the first layer in the comp (look out for crashes here, no checking for shame!)
var markerLayer = myComp.layer(1);
var markerGroup = markerLayer.Marker;
//Add footage items from the project window to the composition.
for (i=0; i <projSelection> markerGroup.numKeys)
{
markerTime = 0;
}
else
{
markerTime = markerGroup.keyTime(n);
}
//Set the in point and length for this layer.
var curIn = markerTime;
var curOut = markerTime + myImageDuration;
thisImageLayer.startTime = curIn;
thisImageLayer.outPoint= curOut;
writeLn("Setting in/out points to [" + curIn + ", " + curOut +"]");
//Move to the next marker, if there is one.
myCount = myCount + 1;
}
}
//Blank our folder to prevent a re-run of this script from failing on a browse cancel.
targetFolder = "";
writeLn("Finished folder items.");
}
else
{
writeLn("User cancels import operation.");
}
app.endUndoGroup();
}
else
{
writeLn ("User canceled script.");
}
}
catch(error)
{
writeLn ("Select the comp in the project window be fore running this script.");
}
}
Posted: August 9th, 2007, 6:01 am
by menonerd
phew
whole lotta code 'ere - thanks so far, i'll look into it (and come back with questions
