简体   繁体   English

Photoshop JavaScript图层创建

[英]Photoshop JavaScript Layer creation

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" 我从ExtendScript Toolkit得到了这个响应:“你只能将图层的类改为文本或正常”

I would have thought that there would be a way to pass arguments of some sort to the add() method of artLayers ?! 我会想到有一种方法可以将某种类型的参数传递给artLayersadd()方法吗? 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 另外,我不知道这是否重要,但我正在运行Ps CC15,ES工具包4,并使用脚本参考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 实心填充使用RGB颜色,前景颜色使用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 );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM