Moving Objects Around in the Project Panel

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
JungWhelp
Posts: 5
Joined: September 6th, 2015, 5:27 pm

September 6th, 2015, 7:54 pm

Hello AE script gurus. I am brand new to java scripting. But I have years of experience of object oriented programming in VBA for Excel. Through various tutorials and this forum I have managed to write the following code which has me jumping up and down! However, now I am hitting a road block. As you can hopefully see from my script below, I put a bunch of footage items in a folder. Then I create a new folder for each footage item. That part is solved. Now I want to move each footage item into its respective folder. Can someone please tell me how to do that? TIA

Code: Select all

var myFolder = app.project.selection[0]
if (!(myFolder instanceof FolderItem)) {
	alert("Please organize the footage into a single folder and select the folder item in the project panel. Then re-run script.");
} else {
	if (myFolder.numItems < 1) {
		alert("Folder is empty! Please organize the footage into a single folder and select the folder item in the project panel. Then re-run script.");
	} else {
		for (i=1; i<=myFolder.numItems; i++) {
			var footageItem = myFolder.item(i);	
			var newFolder = app.project.items.addFolder(footageItem.name);
};};};
EDIT: I should point out that the above code works fine in creating new folders for each footage item in the folder. However, when I tried the following code, the code I think gets confused once I start moving the footage to their respective folders. IOW, it doesn't move all the files. I guess it is because the numItems changes dynamically as items are moved out of the folder. So I am not sure the best way to go about this. TIA

Code: Select all

var myFolder = app.project.selection[0]
if (!(myFolder instanceof FolderItem)) {
	alert("Please organize the footage into a single folder and select the folder item in the project panel. Then re-run script.");
} else {
	if (myFolder.numItems < 1) {
		alert("Folder is empty! Please organize the footage into a single folder and select the folder item in the project panel. Then re-run script.");
	} else {
		for (i=1; i<=myFolder.numItems; i++) {
			var footageItem = myFolder.item(i);	
			var newFolder = app.project.items.addFolder(footageItem.name);
			footageItem.parentFolder = newFolder;
};};};
beginUndoGroup
Posts: 81
Joined: November 27th, 2012, 6:41 am

September 7th, 2015, 1:22 am

Try running over items in reverse order : for (i=myFolder.numItems; i>0; i--)

Xavier.
JungWhelp
Posts: 5
Joined: September 6th, 2015, 5:27 pm

September 7th, 2015, 5:28 am

LOL! Seems so obvious now. Thanks for the tip that did the trick! I am now one step closer to fully automating this process.
JungWhelp
Posts: 5
Joined: September 6th, 2015, 5:27 pm

September 7th, 2015, 6:12 pm

Ok I am back and now struggling once again :(. Hopefully someone can help me. My code seems to work ok, but I can't seem to successfully move the new adjustment layers to the newFolder. When AE adds the new Adjustment Layer, it automatically puts them in a Solids folder (one of the things that annoys me about AE and why I am scripting this up). The line with

Code: Select all

layerRG.parentFolder = newFolder;
doesn't error out, but at the same time doesn't move the new Adjustment Layer to the newFolder but leaves it in the Solids folder. This is literally the last step before my script is complete. TIA

Code: Select all

var myFolder = app.project.selection[0];
if (!(myFolder instanceof FolderItem)) {
	alert("Please organize the footage into a single folder and select the folder item in the project panel. Then re-run script.");
} else {
	if (myFolder.numItems < 1) {
		alert("Folder is empty! Please organize the footage into a single folder and select the folder item in the project panel. Then re-run script.");
	} else {
		for (i=myFolder.numItems; i>0; i--) {
			// Create new folder for each footage item and move the footage item to that folder
			var footageItem = myFolder.item(i);	
			var newFolder = app.project.items.addFolder(footageItem.name);
			footageItem.parentFolder = newFolder;
			// Create a new comp for each footage item
			with (footageItem) var myComp = app.project.items.addComp(name, width, height, pixelAspect, duration, frameRate);
			myComp.parentFolder = newFolder; // Put Comp in new folder
			var footageLayer = myComp.layers.add(footageItem); // Add footageItem to the new Comp
			var layerRG = addAdjLayer(myComp, "RG"); // Add new adjustment layer to the new Comp
			layerRG.parentFolder = newFolder;
};};};

function addAdjLayer(adjComp, adjLayerName) {
	// Add Adjustment Layer
	app.beginUndoGroup("Add Adjustment Layer");	
		if (adjComp != null) { // Always best to check if it's safe before adding
			with (adjComp) var newLayer = adjComp.layers.addSolid([1,1,1], adjLayerName, width, height, pixelAspect);
			with (newLayer) {
				startTime = 0;
				adjustmentLayer = true;
			};
		} else {
			alert("Unable to add new layer. Aborting!");
		};
	app.endUndoGroup();
return newLayer;
};
beginUndoGroup
Posts: 81
Joined: November 27th, 2012, 6:41 am

September 8th, 2015, 12:56 am

Move the source of the layer:

Code: Select all

layerRG.source.parentFolder = newFolder;
JungWhelp
Posts: 5
Joined: September 6th, 2015, 5:27 pm

September 8th, 2015, 5:30 pm

Awesome! That solved my problem. I have no idea how to figure that out on my own. Anyway, fyi, here is the final version of my script. It basically preps my project for me by adding the adjustment layers and organizing the files for me. So all I have to do is tweak the adjustment layers.

Code: Select all

var myFolder = app.project.selection[0];
if (!(myFolder instanceof FolderItem))
{
	alert("Please organize the footage into a single folder and select the folder item in the project panel. Then re-run script.");
} else {
	if (myFolder.numItems < 1) {
		alert("Folder is empty! Please organize the footage into a single folder and select the folder item in the project panel. Then re-run script.");
	} else {
		for (i=myFolder.numItems; i>0; i--)
		{
			// Create new folder for each footage item and move the footage item to that folder
			var footageItem = myFolder.item(i);	
			var newFolder = app.project.items.addFolder(footageItem.name);
			footageItem.parentFolder = newFolder;

			// Create a new comp for each footage item
			with (footageItem) var myComp = app.project.items.addComp(name, width, height, pixelAspect, duration, frameRate);
			myComp.parentFolder = newFolder; // Put Comp in new folder
			var footageLayer = myComp.layers.add(footageItem); // Add footage to the new Comp

			// Add Remove Grain adjustment layer to the new Comp
			var layerRG = addAdjLayer(myComp, "RG");
			layerRG.source.parentFolder = newFolder;
			addNoiseRedux(layerRG); // Put some initial settings on the Remove Grain effect

			// Add Color Correction adjustment layer to the new Comp
			var layerCC = addAdjLayer(myComp, "CC");
			layerCC.source.parentFolder = newFolder;
			addColorCorrect(layerCC);
		};
	};
};

// Add Adjustment Layer
function addAdjLayer(adjComp, adjLayerName)
{
	app.beginUndoGroup("Add Adjustment Layer");	
		if (adjComp != null) // Always best to check if it's safe before adding
		{
			with (adjComp) var newLayer = adjComp.layers.addSolid([1,1,1], adjLayerName, width, height, pixelAspect); // Add Remove Grain effect
			with (newLayer) {
				startTime = 0;
				adjustmentLayer = true;
			};
		} else {
			alert("Unable to add new layer. Aborting!");
		};
	app.endUndoGroup();
return newLayer;
};

// Add Remove Grain effect
function addNoiseRedux(nrLayer)
{
	app.beginUndoGroup("Add Remove Grain Effect");	
	var effName = "Remove Grain"; // The Remove Grain effect name
	if (nrLayer.Effects.canAddProperty(effName))
	{
		var remGrain = nrLayer.Effects.addProperty(effName); // Add Remove Grain effect
		var nrEffect = nrLayer.Effects.property(effName); //The Effect Obj
		app.endUndoGroup();

		// Noise Reduction Settings
		app.beginUndoGroup("Noise Reduction Channel Settings");
		var chMode = nrEffect.property(12); //Noise reduction mode: Multi-channel = 1, Single channel = 2
		chMode.setValue(2);
		var chRedRedux = nrEffect.property(14); //Red channel noise reduction
		chRedRedux.setValue(0.3);
		var chRedRedux = nrEffect.property(15); //Green channel noise reduction
		chRedRedux.setValue(0.3);
		var chRedRedux = nrEffect.property(16); //Blue channel noise reduction
		chRedRedux.setValue(0.8);
		app.endUndoGroup();

		// Unsharp Mask Settings
		app.beginUndoGroup("Unsharp Mask Settings");
		var umAmount = nrEffect.property(31); //Unsharp Mask Amount
		umAmount.setValue(0.5);
		var umRadius = nrEffect.property(32); //Unsharp Mask Radius
		umRadius.setValue(1.2);
		app.endUndoGroup();
	} else {
		alert("Unable to add Remove Grain effect. Aborting!");
	};
};

// Add Synthetic Aperture Color Finesse 2 effect
function addColorCorrect(ccLayer)
{
	app.beginUndoGroup("Add SA Color Finesse 2 Effect");	
	var effName = "SA Color Finesse 2"; // The SA Color Finesse 2 effect name
	if (ccLayer.Effects.canAddProperty(effName))
	{
		var saCC = ccLayer.Effects.addProperty(effName); // Add SA Color Finesse 2 effect
		var ccEffect = ccLayer.Effects.property(effName); //The Effect Obj
		app.endUndoGroup();
	} else {
		alert("Unable to add Color Correction effect. Aborting!");
	};
};
JungWhelp
Posts: 5
Joined: September 6th, 2015, 5:27 pm

September 8th, 2015, 6:18 pm

WOW!!!!!!!!!!!! I just ran my script on about 30+ footage items I imported into AE and what would have taken me who knows how long, ran in less than 2 seconds!!!!!!!! I am simply speechless!!!!
Post Reply