Accessing Paint Attributes through scripting.

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
oliverj
Posts: 2
Joined: January 24th, 2005, 4:45 pm

I would like to write a script to re-order all of the brush strokes on a Paint effect by inPoint. Unfortunately, when I select brushes in the Comp, I can't seem to access a list of all the currently selected Brushes or strokeOption's (or better yet, have After Effects query all the brushes for the selected Paint Effect). Anybody have an idea as to how I could accomplish this task?

Thanks!
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

You can't get a list of selected brush strokes because they are PropertyGroup's not Properties, so 'selectedProperties' won't work. But you can create a loop that goes through all the strokes and checks whether they are selected.

Here's a script that finds a Paint effect on the first of any selected layers, then reports whether it is selected, how many strokes there are and whether any of them are selected. Unfortunately I appear to have hit a dead end when I try to query the stroke inPoints, presumably because that is a layer attribute, and brush strokes aren't layers. I'll do some more research on this and get back to you.

Paul T

Code: Select all

{
	activeItem = app.project.activeItem;
	theLayer = activeItem.selectedLayers[0];

	// loop through all effects on selected layer
	for (a=1; a <= theLayer.Effects.numProperties; ++a){
		theEffect = theLayer.Effects.property(a);

		if (theEffect.name = "Paint") {

			alert(theLayer.name + " has a Paint effect.")
			if (theEffect.selected) { alert(theLayer.name + "'s Paint effect is selected"); }
			theStrokes = theEffect.property(2)
			alert("The Paint effect has " + theStrokes.numProperties + " brush strokes");

			// loop through all strokes on Paint effect
			for (b = 1; b <= theStrokes.numProperties; ++b) {
				thisStroke = theStrokes.property(b);
				if (thisStroke.selected) { alert(theStrokes.property(b).name + " is selected"); }
			}

			keepSorting = true;
			while(keepSorting) {
				keepSorting = false;
				for (b = 1; b < theStrokes.numProperties; ++b) {
					alert(theStrokes.property(b).inPoint + " " + theStrokes.property(b+1).inPoint);
					if (theStrokes.property(b).inPoint > theStrokes.property(b+1).inPoint) {
						theStrokes.property(b+1).moveTo(b);
						keepSorting = true;
					}
				}
			}
		}
	}
}
Last edited by Paul Tuersley on March 13th, 2005, 2:56 am, edited 1 time in total.
oliverj
Posts: 2
Joined: January 24th, 2005, 4:45 pm

Paul Tuersley wrote:Unfortunately I appear to have hit a dead end when I try to query the stroke inPoints, presumably because that is a layer attribute, and brush strokes aren't layers. I'll do some more research on this and get back to you.

Paul T
Thanks for the help Paul! I managed to access the brush stroke start times by doing the following (thanks also to Dan Ebberts):

Code: Select all

var proj = app.project;
var activeComp = proj.activeItem;
var selectedLayers = activeComp.selectedLayers;
var myEffect = selectedLayers[0].property("ADBE Effect Parade");
var myPaintBrushes = myEffect.property("ADBE Paint").property("ADBE Paint Group");
var myBrush = myPaintBrushes.property(1);

// By querying the Duration you get an array with [starttime,duration]
var myProperty = myBrush.property("ADBE Paint Duration");

// So, here is the start time.
var myStartTime = myProperty.value[0];

I should have a script that works tonight. Thanks for the help,

Oliver.
Post Reply