You can probably guess what I'm trying to do by this snippet:
var docRef = app.activeDocument;
var layerRef = app.activeDocument.artLayers.add();
layerRef.kind = LayerKind.SOLIDFILL;
I want to script the creation of a fill layer (and then later designate color, remove mask, etc). I get this response from the ExtendScript Toolkit: "You can only change the layer's kind to text or normal"
I would have thought that there would be a way to pass arguments of some sort to the add()
method of artLayers
?! Am I missing something really simple? Thanks.
I know this can be done with actions but I would like to learn how to do this (seemingly) very simple task and build on it to create more complex, useful scripts.
Also, i don't know if this is important but I'm running Ps CC15, ES toolkit 4, and using script reference CC14
For a simple fill, you just need to change the third line to
app.activeDocument.selection.fill(app.foregroundColor, ColorBlendMode.NORMAL, 100, false);
If you want to add a new solid fill to the script I've added a function to that. The solid fill works with RGB colours, the foreground colour works with HEX cols
var docRef = app.activeDocument;
var layerRef = app.activeDocument.artLayers.add();
// set the foreground colour
var myColour = "F7E7CE";
setColour(myColour);
// fill this
// app.activeDocument.selection.fill(app.foregroundColor, ColorBlendMode.NORMAL, 100, false);
//or
// new solid fill
fillSolidColour(247,231,206);
// function SET COLOUR (hexcolour, set background?)
// --------------------------------------------------------
function setColour(hexcolour)
{
// set foreground colour to matching colour
var tempColor = new SolidColor;
hexcolour = hexcolour.toString(); // stringify it
tempColor.rgb.hexValue = hexcolour;
// set foreground
foregroundColor = tempColor;
}
function fillSolidColour(R, G, B)
{
// =======================================================
var id117 = charIDToTypeID( "Mk " );
var desc25 = new ActionDescriptor();
var id118 = charIDToTypeID( "null" );
var ref13 = new ActionReference();
var id119 = stringIDToTypeID( "contentLayer" );
ref13.putClass( id119 );
desc25.putReference( id118, ref13 );
var id120 = charIDToTypeID( "Usng" );
var desc26 = new ActionDescriptor();
var id121 = charIDToTypeID( "Type" );
var desc27 = new ActionDescriptor();
var id122 = charIDToTypeID( "Clr " );
var desc28 = new ActionDescriptor();
var id123 = charIDToTypeID( "Rd " );
desc28.putDouble( id123, R ); //red
var id124 = charIDToTypeID( "Grn " );
desc28.putDouble( id124, G ); //green
var id125 = charIDToTypeID( "Bl " );
desc28.putDouble( id125, B ); //blue
var id126 = charIDToTypeID( "RGBC" );
desc27.putObject( id122, id126, desc28 );
var id127 = stringIDToTypeID( "solidColorLayer" );
desc26.putObject( id121, id127, desc27 );
var id128 = stringIDToTypeID( "contentLayer" );
desc25.putObject( id120, id128, desc26 );
executeAction( id117, desc25, DialogModes.NO );
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.