首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何用自动识别水平和垂直帧重命名层[Photoshop脚本]

如何用自动识别水平和垂直帧重命名层[Photoshop脚本]
EN

Stack Overflow用户
提问于 2020-06-29 05:51:01
回答 1查看 358关注 0票数 0

我是新来的photoshop脚本。我想要加载一个PSD文件,其中有2个垂直照片和3个水平照片,我选择该层。现在,我希望所有选定的层都用VFrame重命名为垂直层,用HFrameHFrame进行水平存储,并以2v3h_My Name_0001的名称保存,如何做到这一点?有人能分享Photoshop的javascript吗?

EN

回答 1

Stack Overflow用户

发布于 2020-07-24 08:48:01

这是你的第一个问题,欢迎来到StackOverflow。有很多Photoshop脚本指南。这一个涵盖了基本知识。

您想要的脚本需要:

  • 在层上循环(我们将省略组,这很快就会变得复杂)
  • 识别一个层是水平的还是垂直的
  • 适当地重命名该层
  • 根据水平层的数量,使用新名称复制文档
代码语言:javascript
运行
复制
// Switch off any dialog boxes
displayDialogs = DialogModes.NO; // OFF 

// call the source document
var srcDoc = app.activeDocument;
var numOfLayers = srcDoc.layers.length;
var vCount = 0;
var hCount = 0;


// main loop
for (var i = numOfLayers -1; i >= 0  ; i--) 
{
  // get a referenec to each layer as we loop over them
  var thisLayer = srcDoc.layers[i];

  // get the layer bounds of each layer as you go
  srcDoc.activeLayer = thisLayer;
  var lb = get_layer_bounds();

  // set a variable to for portrait or landscape
  var portrait = true;

  // if layer is wider than it is long,
  // it's landscape
  if (lb[0] > lb[1]) portrait = false;
  //alert(lb[0] + "," + lb[1] + "\n" + portrait + "\n" +thisLayer.name);

  // ignore the background layer
  // if there is one
  if (thisLayer.isBackgroundLayer == false)
  {
    if (portrait)
      {
        srcDoc.artLayers[i].name = "HFrame";
        // add one to the horizontal count
        hCount +=1
      }
    else
      {
        srcDoc.artLayers[i].name = "VFrame";
        // add one to the vertical count
        vCount+=1
      }
  }
}
var docName = srcDoc.name.substring(0, srcDoc.name.length -4);
var imgName = vCount + "v" + hCount + "h_" + docName + "_0001.psd";
duplicateIt(imgName);


// Set Display Dialogs back to normal
displayDialogs = DialogModes.ALL; // NORMAL



// function GET LAYER BOUNDS ()
// ----------------------------------------------------------------
function get_layer_bounds()
{
  var x = parseFloat(app.activeDocument.activeLayer.bounds[0]);
  var y = parseFloat(app.activeDocument.activeLayer.bounds[1]);
  var x1 = parseFloat(app.activeDocument.activeLayer.bounds[2]);
  var y1 = parseFloat(app.activeDocument.activeLayer.bounds[3]);

  var selW = parseFloat(x1-x);
  var selH = parseFloat(y1-y);

  // return the results as an array
  return [selW, selH];
}


function duplicateIt(str)
{
  // duplicate image into new document
  if (arguments.length == 0) str = "temp";

  var id428 = charIDToTypeID( "Dplc" );
  var desc92 = new ActionDescriptor();
  var id429 = charIDToTypeID( "null" );
  var ref27 = new ActionReference();
  var id430 = charIDToTypeID( "Dcmn" );
  var id431 = charIDToTypeID( "Ordn" );
  var id432 = charIDToTypeID( "Frst" );
  ref27.putEnumerated( id430, id431, id432 );
  desc92.putReference( id429, ref27 );
  var id433 = charIDToTypeID( "Nm  " );
  desc92.putString( id433, str ); // name
  executeAction( id428, desc92, DialogModes.NO );
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62632015

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档