Page 1 of 1

Add project item (solid) to compItem through script

Posted: September 10th, 2009, 9:37 am
by Redsandro
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?

Re: Add project item (solid) to compItem through script

Posted: September 10th, 2009, 4:12 pm
by nab
mySolid is a project item, you can add it to a comp like this:

Code: Select all

preComp1.layers.add(mySolid);

Re: Add project item (solid) to compItem through script

Posted: September 10th, 2009, 9:35 pm
by Redsandro
Ah now I see it, so I should

Code: Select all

if (mySolid.name == "AL 1920x1080 White") {
         gotSolid = mySolid;
         break;
}
thanks

Re: Add project item (solid) to compItem through script

Posted: September 11th, 2009, 6:49 am
by Redsandro
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?

Re: Add project item (solid) to compItem through script

Posted: September 13th, 2009, 9:04 am
by nab
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;
	}
}

Re: Add project item (solid) to compItem through script

Posted: September 13th, 2009, 9:25 am
by Redsandro
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.