Copy link to clipboard
Copied
Hi!
Does anybody know, if it's possible to switch current gradient type (Radial, Linear etc.) with scripts,
patchpanel, or either way programmatically in Photoshop?
Thank you!
Anastasiy
Copy link to clipboard
Copied
Looks to me that you could record applying your gradients via ScriptListener plug-in then use those in your script? Lots of data in there to alter start and finish locations, type, etc.
Copy link to clipboard
Copied
Thank you for suggestion!
But it's a pity, Listener just shows that I've switched to the Gradient mode and
doesn't show what type of gradient is chosen (when I switch the types).
Copy link to clipboard
Copied
I think Mark was talking about using scriptlistner to create the gradient. Scriptlistner does record all the options then.
If you only recorded the selection of the gradient tool, then you are right it doesn't record the options. However you can use scrptlister to select tool presets. Selecting a tool preset will let you change the gradient type with a script.
// tool must be selected or 'show current tool only' unchecked
function selectPreset( presetName ){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( stringIDToTypeID( "toolPreset" ), presetName );
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};
Copy link to clipboard
Copied
Micheal, I was actually thinking of recording the whole using of a Gradient tool if you know which one you wanted to use then you could have a script change the way in which its applied (I only went and picked Spectrum as an example Doh!)
var docRef = app.documents.add(500, 500, 72, 'docRef', NewDocumentMode.RGB)
// The 5 Gradient Modes are below:
// 'Lnr ', 'Rdl ', 'Angl', 'Rflc', 'Dmnd'
SpectrumGradient(250, 250, 250, 0, 'Rdl ')
function SpectrumGradient(x1, y1, x2, y2, gradMode) {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc99 = new ActionDescriptor();
var desc100 = new ActionDescriptor();
desc100.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), x1 ); // Start Point
desc100.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), y1 ); // Start Point
desc99.putObject( cTID('From'), cTID('Pnt '), desc100 );
var desc101 = new ActionDescriptor();
desc101.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), x2 ); // End Point
desc101.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), y2 ); // End Point
desc99.putObject( cTID('T '), cTID('Pnt '), desc101 );
desc99.putEnumerated( cTID('Type'), cTID('GrdT'), cTID( gradMode ) ); // Toggle Gradient Modes
desc99.putBoolean( cTID('Dthr'), true );
desc99.putBoolean( cTID('UsMs'), true );
var desc102 = new ActionDescriptor();
desc102.putString( cTID('Nm '), "Spectrum" );
desc102.putEnumerated( cTID('GrdF'), cTID('GrdF'), cTID('CstS') );
desc102.putDouble( cTID('Intr'), 4096.000000 );
var list7 = new ActionList();
var desc103 = new ActionDescriptor();
var desc104 = new ActionDescriptor();
desc104.putUnitDouble( cTID('H '), cTID('#Ang'), 0.000000 );
desc104.putDouble( cTID('Strt'), 100.000000 );
desc104.putDouble( cTID('Brgh'), 100.000000 );
desc103.putObject( cTID('Clr '), cTID('HSBC'), desc104 );
desc103.putEnumerated( cTID('Type'), cTID('Clry'), cTID('UsrS') );
desc103.putInteger( cTID('Lctn'), 0 );
desc103.putInteger( cTID('Mdpn'), 50 );
list7.putObject( cTID('Clrt'), desc103 );
var desc105 = new ActionDescriptor();
var desc106 = new ActionDescriptor();
desc106.putDouble( cTID('Rd '), 255.000000 );
desc106.putDouble( cTID('Grn '), 0.000000 );
desc106.putDouble( cTID('Bl '), 255.000000 );
desc105.putObject( cTID('Clr '), cTID('RGBC'), desc106 );
desc105.putEnumerated( cTID('Type'), cTID('Clry'), cTID('UsrS') );
desc105.putInteger( cTID('Lctn'), 614 );
desc105.putInteger( cTID('Mdpn'), 50 );
list7.putObject( cTID('Clrt'), desc105 );
var desc107 = new ActionDescriptor();
var desc108 = new ActionDescriptor();
desc108.putDouble( cTID('Rd '), 0.000000 );
desc108.putDouble( cTID('Grn '), 0.000000 );
desc108.putDouble( cTID('Bl '), 255.000000 );
desc107.putObject( cTID('Clr '), cTID('RGBC'), desc108 );
desc107.putEnumerated( cTID('Type'), cTID('Clry'), cTID('UsrS') );
desc107.putInteger( cTID('Lctn'), 1352 );
desc107.putInteger( cTID('Mdpn'), 50 );
list7.putObject( cTID('Clrt'), desc107 );
var desc109 = new ActionDescriptor();
var desc110 = new ActionDescriptor();
desc110.putDouble( cTID('Rd '), 0.000000 );
desc110.putDouble( cTID('Grn '), 255.000000 );
desc110.putDouble( cTID('Bl '), 255.000000 );
desc109.putObject( cTID('Clr '), cTID('RGBC'), desc110 );
desc109.putEnumerated( cTID('Type'), cTID('Clry'), cTID('UsrS') );
desc109.putInteger( cTID('Lctn'), 2007 );
desc109.putInteger( cTID('Mdpn'), 50 );
list7.putObject( cTID('Clrt'), desc109 );
var desc111 = new ActionDescriptor();
var desc112 = new ActionDescriptor();
desc112.putDouble( cTID('Rd '), 0.000000 );
desc112.putDouble( cTID('Grn '), 255.000000 );
desc112.putDouble( cTID('Bl '), 0.000000 );
desc111.putObject( cTID('Clr '), cTID('RGBC'), desc112 );
desc111.putEnumerated( cTID('Type'), cTID('Clry'), cTID('UsrS') );
desc111.putInteger( cTID('Lctn'), 2744 );
desc111.putInteger( cTID('Mdpn'), 50 );
list7.putObject( cTID('Clrt'), desc111 );
var desc113 = new ActionDescriptor();
var desc114 = new ActionDescriptor();
desc114.putDouble( cTID('Rd '), 255.000000 );
desc114.putDouble( cTID('Grn '), 255.000000 );
desc114.putDouble( cTID('Bl '), 0.000000 );
desc113.putObject( cTID('Clr '), cTID('RGBC'), desc114 );
desc113.putEnumerated( cTID('Type'), cTID('Clry'), cTID('UsrS') );
desc113.putInteger( cTID('Lctn'), 3441 );
desc113.putInteger( cTID('Mdpn'), 50 );
list7.putObject( cTID('Clrt'), desc113 );
var desc115 = new ActionDescriptor();
var desc116 = new ActionDescriptor();
desc116.putUnitDouble( cTID('H '), cTID('#Ang'), 0.000000 );
desc116.putDouble( cTID('Strt'), 100.000000 );
desc116.putDouble( cTID('Brgh'), 100.000000 );
desc115.putObject( cTID('Clr '), cTID('HSBC'), desc116 );
desc115.putEnumerated( cTID('Type'), cTID('Clry'), cTID('UsrS') );
desc115.putInteger( cTID('Lctn'), 4096 );
desc115.putInteger( cTID('Mdpn'), 50 );
list7.putObject( cTID('Clrt'), desc115 );
desc102.putList( cTID('Clrs'), list7 );
var list8 = new ActionList();
var desc117 = new ActionDescriptor();
desc117.putUnitDouble( cTID('Opct'), cTID('#Prc'), 100.000000 );
desc117.putInteger( cTID('Lctn'), 0 );
desc117.putInteger( cTID('Mdpn'), 50 );
list8.putObject( cTID('TrnS'), desc117 );
var desc118 = new ActionDescriptor();
desc118.putUnitDouble( cTID('Opct'), cTID('#Prc'), 100.000000 );
desc118.putInteger( cTID('Lctn'), 4096 );
desc118.putInteger( cTID('Mdpn'), 50 );
list8.putObject( cTID('TrnS'), desc118 );
desc102.putList( cTID('Trns'), list8 );
desc99.putObject( cTID('Grad'), cTID('Grdn'), desc102 );
executeAction( cTID('Grdn'), desc99, DialogModes.NO );
};
I would do well to pick a shorter one next time!!!
Copy link to clipboard
Copied
Mark, we were thinking the same thing it's just that I wasn't clear that I was thinking about creating the gradient in the artwork not as 'New Gradient'.
Copy link to clipboard
Copied
Micheal in the above 'Lctn' (location?) is in range of 0-4096 for the gradient stops why 4096? What is special about this number that I just don't see? All I can think of is its 4 x 1024
Copy link to clipboard
Copied
'Lctn' does stand for location and it's the location on the stops in the gradient. In the gradient creation dialog it is express as percent. I don't know why it's not express that way in the descriptor.
In your code if you look at the second stop you see the location is at 614. If you edit the Spectrum gradient in the GUI you will see the second stop is at 15%. 4096 x .15 = 614.4 but I have no idea why it uses 4096 instead on normal percent.
Copy link to clipboard
Copied
Oh, Michael
That's a very interesting trick Thank you!
A good solution, for sure. But that requires to define a preset first. Maybe there's another way to switch the Gradient
Type without defining anything?
Mark, I just wanted to switch the gradient type, without actually painting it.
Copy link to clipboard
Copied
It's is the only work-around I know. Gradient is not in the Scriptingt API and tool options are not in the Action Manager API. That leaves using presets or scripting the placement of the gradient as Mark suggested.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now