Can someone fix my UnPreCompose script? [see 2nd post]

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Redsandro
Posts: 108
Joined: June 25th, 2008, 4:55 pm

Hi,

I have a lot of wrongly precomposed layers because of some faulty automation from my part. Now I want to reverse that, but I cannot seem to get this to work properly. Can someone take a look at it?

This script is supposed to walk all selected layers which are precomps, and copy the layers in there back to the parent comp, and move them below the layer currently being processed. But it just removes all selected layers which are precomps.

Code: Select all

clearOutput();

var myComp = app.project.activeItem;

if (myComp == null || !(myComp instanceof CompItem)) {
	alert("No composition selected.");
}
else {
	// Vars
	var myLayers = myComp.layers;
	var headroom = "25";
	//headroom = parseInt(prompt("How much frames headroom are in your precomps?", headroom));
	headroom *= myComp.frameDuration;

	app.beginUndoGroup("UNpreComp Layers");

	// Walk layers 
	for (var l = myLayers.length; l> 0; l--) { // BACKwards
		// Vars
		var layer = myLayers[l];

		// UnPreCompose
		if (!layer.shy && layer.source instanceof CompItem) {
			myPreComp = layer.source;
			for (var n = myPreComp.length; n> 0; n--) {
				myPreComp[n].copyToComp(myComp);
				myComp.layer(1).startTime -= headroom;
				myComp.layer(1).moveAfter(layer);
			}
			layer.remove();
		}
		else alert('Not a PreComp layer');
	}
	app.endUndoGroup();
}

Last edited by Redsandro on October 2nd, 2009, 5:34 pm, edited 2 times in total.
avi + m2t -> Vdub + DGIndex -> AE CS3 -> x264 -> Hell On Earth :mrgreen:
Redsandro
Posts: 108
Joined: June 25th, 2008, 4:55 pm

I have been at this too long. After a little break I immediately noticed how I should change this:

Code: Select all

         myPreComp = layer.source;
         for (var n = myPreComp.length; n> 0; n--) {
            myPreComp[n].copyToComp(myComp);
into this:

Code: Select all

         myPreCompLayers = layer.source.layers;
         for (var n = myPreCompLayers.length; n> 0; n--) {
            myPreCompLayers[n].copyToComp(myComp);
But because of the selectedLayers thing, it doesn't work properly unless the selected layers form a continuous row from the first layer. Because of operations on the wrong index I'd guess.
So here's the complete working script if you select all layers, but it fails if you select random layers or any other than the first. Anyone know a walkaround?

Code: Select all

/**********
 *	LayerNumbers
 **********
 *	Filename:		RED UNPreComp Layers Headroom.jsx
 *	Written by:		Redsandro - http://www.rednet.nl/en/
 *	Date:			2009/10/03
 *	Last updated:	2009/
 **********
 *
 *	Description:
 *
 *	UNshy layers expand
 *
 **********/



clearOutput();

var myComp = app.project.activeItem;

if (myComp == null || !(myComp instanceof CompItem)) {
	alert("No composition selected.");
}
else {
	// Vars
	var myLayers = myComp.layers;
	var headroom = "25";
	headroom = parseInt(prompt("How much frames headroom are in your precomps?", headroom));
	headroom *= myComp.frameDuration; // Irrelevant; headroam is copied also with copyToComp()

	app.beginUndoGroup("UNpreComp Layers");

	// Walk layers 
	for (var l = myLayers.length; l> 0; l--) { // BACKwards
		// Vars
		var layer = myLayers[l];

		// UnPreCompose
		if (!layer.shy && layer.selected && layer.source instanceof CompItem) {
			//var startTime = layer.startTime + layer.inPoint;
			var startTime = layer.inPoint - headroom;
			myPreCompLayers = layer.source.layers;
			for (var n = myPreCompLayers.length; n> 0; n--) {
				myPreCompLayers[n].copyToComp(myComp);
				myComp.layer(1).startTime += startTime;
				myComp.layer(1).moveAfter(layer);
			}
			layer.remove();
		}
		// else alert('Not a PreComp layer'); // annoying, is triggered by every layer
	}

	app.endUndoGroup();
}

avi + m2t -> Vdub + DGIndex -> AE CS3 -> x264 -> Hell On Earth :mrgreen:
Post Reply