Eyedropper and Fill Color (+ Solid Color)

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
User avatar
monter
Posts: 21
Joined: July 15th, 2004, 1:03 am
Location: Russia, Moskow
Contact:

As in JavaScript to make tool Eyedropper and Fill Color.
Thank.
MEGABASTARD
Posts: 3
Joined: June 23rd, 2004, 2:03 am
Location: London

Better yet is there a way to create a tool that would scrub over several pixels to find the average rgb values? ala Shake.
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

It isn't possible to create an Eyedropper or Fill Color swatch in the scripting UI, but you
could always use the Expression Controls > Color Control effect. You can set the value
of that effect using code such as:

curLayer.Effects.property("Color Control").property("Color").setValue([0,0,0,0]);

(the Color parameter requires a 4 dimensional array [r,g,b,a] of values between 0-1.)

Scripting isn't able to analyze pixel values either, which would be necessary for
an averaging tool. I believe this kind of thing may be possible with Useful Things.
Check out this link: http://www.4thparty.com/products/colorsampler.htm

Paul T
miki
Posts: 17
Joined: December 20th, 2004, 10:48 am
Location: London, UK
Contact:

That's a good idea.

Another way to specify a colour (<'scuse the spelling - I'm a Brit!) would have been to create a solid layer (Layer -> New.. -> Solid...) and set the colour on that.
But I can't see a scripting way of reading the colour value of the solid! :?

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

Here are a couple of scripts that show some ways of working with a Solid's color. First, create a new comp and run this script. It creates a new solid with a specific color value, then reads that value from the solid's source:

Code: Select all

{
	var activeItem = app.project.activeItem;

	if (activeItem == null || !(activeItem instanceof CompItem)) {
		alert("Select a comp before running this script");
	} else {
		// create a red, comp-sized solid layer.
		theSolid = activeItem.layers.addSolid([1,0,0],"Solid Layer", activeItem.width, activeItem.height, 1);

		// find the solid's color array values.
		c = theSolid.source.mainSource.color;

		alert("Created a new solid with color values [" + c[0] + "," + c[1] + "," + c[2] + "]");
	}
}
Then select the new Solid and run this script. It changes the Solid source's color to white:

Code: Select all

{
	var activeItem = app.project.activeItem;

	if (activeItem == null || !(activeItem instanceof CompItem)) {
		alert("Select a comp before running this script");
	} else {
		if (activeItem.selectedLayers.length < 1) {
			alert("Select a solid layer before running this script");
		} else {
			solidLayer = activeItem.selectedLayers[0];
			solidLayer.source.mainSource.color = [1,1,1];
			alert("Changed solid's color to white.");
		}
	}
}
Last edited by Paul Tuersley on March 13th, 2005, 2:57 am, edited 1 time in total.
miki
Posts: 17
Joined: December 20th, 2004, 10:48 am
Location: London, UK
Contact:

aha!
Thanks very much for those examples - it all makes sense now!

Miki
vidpat
Posts: 86
Joined: October 21st, 2004, 12:36 am
Location: Phoenix, AZ
Contact:

As for pixel averaging, two effects come to mind that do this. I am not certain if this is what you had in mind or how they compare to Shake's functionality.

Image Control > Color Link colorizes a layer with several types of averages of the pixels from a layer.

Render > Eyedropper Fill similarly colorizes a layer with the average color within a specified radius of a point.
Post Reply