Add project item (solid) to compItem through script

Find out why the . goes before the /

Moderator: Paul Tuersley

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

First I look for my solid like so:

Code: Select all

	// Check for my favourite solid
	var gotSolid = false;
	for (i = app.project.numItems; i >= 1; i--) { // Backwards is faster for finding the solid
	var mySolid = app.project.item(i);
		if (mySolid.name == "AL 1920x1080 White") {
			gotSolid = mySolid.id;
			break;
		}
	}
And then I add it like so:

Code: Select all

		// Add the solid
		if (gotSolid != false)
			preComp1.layers.add(gotSolid); // <<< does not work with item ID??
		else
			preComp1.layers.addSolid([1,1,1],"SomeName",1920,1080,1);
Look for the layers.add. It does not work. The AddSolid does work when it's triggered, but I want to have my specific solid in there. If you cannot reference it by ID, how else can you get it in there?
avi + m2t -> Vdub + DGIndex -> AE CS3 -> x264 -> Hell On Earth :mrgreen:
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

mySolid is a project item, you can add it to a comp like this:

Code: Select all

preComp1.layers.add(mySolid);
Redsandro
Posts: 108
Joined: June 25th, 2008, 4:55 pm

Ah now I see it, so I should

Code: Select all

if (mySolid.name == "AL 1920x1080 White") {
         gotSolid = mySolid;
         break;
}
thanks
avi + m2t -> Vdub + DGIndex -> AE CS3 -> x264 -> Hell On Earth :mrgreen:
Redsandro
Posts: 108
Joined: June 25th, 2008, 4:55 pm

One more related section I fail to make up; what is best to find all instances in any comp of all selected footage items and replace them with a solid?
Like is there a function that tells me what comps/layers use the AVItem, or would I loop through all comps and compare all layers to all selected project items?
avi + m2t -> Vdub + DGIndex -> AE CS3 -> x264 -> Hell On Earth :mrgreen:
nab
Posts: 203
Joined: November 29th, 2005, 3:00 am
Location: Royan
Contact:

When you replace an item with something else, the change is reflected in all comps that use an instance of that item. You don't have to walk through each comp individually.

Code: Select all

var found = false;
for (var i = 1; !found && i <= app.project.numItems; i++)
{ 
	if (app.project.item(i).name == "3D Bend.mov")
	{
		// replace footage with solid
		app.project.item(i).replaceWithSolid([1,1,1],"My White Solid",1920,1080,1);
		
		// replace footage with another footage
		//app.project.item(i).replace(File("~/desktop/3D Quantize.mov"));
		
		found = true;
	}
}
Redsandro
Posts: 108
Joined: June 25th, 2008, 4:55 pm

Thanks, but in this case the solid I want to use is already in my project. So I think I need to do the walking through after all.
avi + m2t -> Vdub + DGIndex -> AE CS3 -> x264 -> Hell On Earth :mrgreen:
Post Reply