Question

i am trying to automate a task in photoshop cs3. i want to add a gradient to a layer. i could not find any methods or classes in the javascript reference regarding this.

i am able to set background color and foreground color and apply it to a selection like this

var docRef_1 = app.documents.add( 1000, 1000 )
docRef_1.artLayers.add(); 

var white = new SolidColor();
white.rgb["hexValue"] = "ffffff" 
var black = new SolidColor(); 
black.rgb["hexValue"] = "000000" 

foregroundColor = black; 
backgroundColor = white; 

docRef_1.selection.selectAll(); 
docRef_1.selection.fill(black); 
docRef_1.selection.deselect();

but i can not find any way to fill the selection with gradient. i am wondering if this can be achieved only with executeAction as is the case with emboss and other specific filters which are not directly available in object model

but i guess, for that i need to have a scriptlistener and record the action and generate the javascript log. can someone point me in the right direction?

Was it helpful?

Solution

Yep, scripting gradients is not well documented (or implemented in my opinion). You'll need to use scriptlistener to glean the correct code. Keep in mind, the start and end positions of the gradient will be hard coded. If you want to vary the gradient's position by the selection's size, set it each point relative to activeDocuments.selection.bounds.

If you want to save a gradient for re-use, create a new layer and apply a gradient overlay. See this answer on the graphic design SE site for more details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top