当前位置:网站首页>Photoshop-图层相关概念-LayerComp-Layers-移动旋转复制图层-复合图层
Photoshop-图层相关概念-LayerComp-Layers-移动旋转复制图层-复合图层
2022-06-27 17:13:00 【插件开发】
文章目录
1.简介
Photoshop图层就如同透明纸堆叠在一起。通过图层来包含其它元素,可以移动图层来移动整个图层。
2.图层相关概念
2.1.LayerComp
文档中图层状态的快照,可用于查看不同的页面布局或合成。通过 Document.layerComps 集合访问。 您可以按名称访问图层复合。 例如,这为名为 myLayerComp 的 LayerComp 对象设置了 comment 属性值:
var layercompRef = app.activeDocument.layerComps.getByName("myLayerComp");
layercompRef.comment = "View from shoreline";
2.2.LayerComps
文档中 LayerComp 对象的集合。通过 Document.layerComps 集合属性访问。 例如:
app.activeDocument.layerComps.add("myLayerComp", "View from Shoreline",
true, true, true);
2.3.Layers
文档中图层对象的集合,包括 ArtLayer 和 LayerSet 对象。 通过访问Document.layers 或 LayerSet.layers 集合属性。例如,这使用 length 属性来计算活动文档中图层对象的数量,然后在屏幕上显示数字:
var layerNum = app.activeDocument.layers.length
alert(layerNum)
2.4.LayerSet
一组图层对象,可以包括 ArtLayer 对象和其他(嵌套的)LayerSet 对象。 单个命令可以操作集合中的所有层。通过 Document.layerSets 集合访问文档中的顶级图层集。 您可以按名称访问图层集。 例如,以下设置“myLayerSet”的 allLocked 值:
var layerSetRef = app.activeDocument.layerSets.getByName("myLayerSet");
layerSetRef.allLocked = true
通过父集中的 LayerSet.layerSets 集合访问嵌套层集。 例如:
app.activeDocument.layerSets[0].layerSets[0];
2.5.LayerSets
文档中 LayerSet 对象的集合。通过 Document.layerSets 集合属性访问文档中的顶级图层集。 例如:
var layerSetRef = app.activeDocument.layerSets.add()
通过父集中的 LayerSet.layerSets 集合属性访问嵌套层集。 例如:
var layerSetRef = app.activeDocument.layerSets.getByName("myParentSet");
var childSet = layerSetRef.layerSets.getByName("myChildSet");
3.范例
3.1.设置激活图层
将活动图层设置为活动文档的最后一个艺术图层。
app.bringToFront();
if (app.documents.length == 0)
{
var docRef = app.documents.add();
}
else
{
var docRef = app.activeDocument;
}
if (docRef.layers.length < 2)
{
docRef.artLayers.add();
}
var activeLayerName = docRef.activeLayer.name;
var setLayerName = "";
if (docRef.activeLayer.name != app.activeDocument.layers[docRef.layers.length - 1].name)
{
docRef.activeLayer = docRef.layers[docRef.layers.length - 1];
}
else
{
docRef.activeLayer = docRef.layers[0];
}
docRef = null;
3.2.设置图层样式
此脚本演示了如何将样式应用于图层。
// in case we double clicked the file
app.bringToFront();
$.localize = true;
var strStyleDefaultPuzzleImage = localize( "$$$/Presets/Styles/DefaultStyles_asl/PuzzleImage=Puzzle (Image)" );
var strtRulerUnits = app.preferences.rulerUnits;
if (strtRulerUnits != Units.PIXELS)
{
app.preferences.rulerUnits = Units.PIXELS;
}
if (app.documents.length == 0)
{
var docRef = app.documents.add(320, 240, 72, null, NewDocumentMode.RGB, DocumentFill.WHITE);
}
else
{
var docRef = app.activeDocument;
}
// 确保 activeLayer 不是背景图层,以便我们可以对其应用样式
docRef.activeLayer.isBackgroundLayer = false;
docRef.artLayers[0].applyStyle(strStyleDefaultPuzzleImage);
docRef = null;
if (strtRulerUnits != Units.PIXELS)
{
app.preferences.rulerUnits = strtRulerUnits;
}
3.3.复制移动图层
此脚本演示了如何复制移动图层。
if (!app.documents.length > 0) //文档不存在则新建文档
{
var strtRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var docRef = app.documents.add(320, 240, 72, null, NewDocumentMode.RGB, DocumentFill.WHITE);
app.preferences.rulerUnits = strtRulerUnits;
}
var docRef = app.activeDocument;
var layerSetRef = docRef.layerSets.add();
var layerRef = docRef.artLayers[0].duplicate();
layerRef.moveToEnd(layerSetRef);
docRef = null;
layerSetRef = null;
layerRef = null;
3.4.旋转图层
if (app.documents.length > 0)
{
if (app.activeDocument.activeLayer.isBackgroundLayer == false)
{
docRef = app.activeDocument;
layerRef = docRef.layers[0];
layerRef.rotate(45.0);
}
else
{
alert("Operation cannot be performed on background layer");
}
}
else
{
alert("You must have at least one open document to run this script!");
}
3.5.图层类型
if (!app.documents.length > 0) {
// open new file if no document is opened.
var strtRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var docRef = app.documents.add(320, 240, 72, null, NewDocumentMode.RGB, DocumentFill.WHITE);
app.preferences.rulerUnits = strtRulerUnits;
}
var docRef = app.activeDocument;
var layerRef = docRef.artLayers.add();
layerRef.kind = LayerKind.TEXT;
docRef = null;
layerRef = null;
4.作者寄语
合理的脚本代码可以有效的提高工作效率,减少重复劳动。
边栏推荐
- Vs code runs "yarn run dev" and reports "yarn": the file XXX cannot be loaded
- Recommend several open source IOT platforms
- 2022年信创行业空间测算
- The difficulty of realizing time series database "far surpassing" general database in specific scenarios
- openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
- Galaxy Kirin V10 system activation
- Cucumber自动化测试框架使用
- 开源之夏 2022 | openGauss 项目中选公布
- 脉脉热帖:为啥大厂都热衷于造轮子?
- Win10 LTSC 2021 wsappx CPU 占用高
猜你喜欢
Using WebDAV instead of 445 port file share
Summary of domestic database certification test guide (updated on June 16, 2022)
Good news - British software 2022 has obtained 10 invention patents!
工作流自动化 低代码是关键
技术分享 | kubernetes pod 简介
破解仓储难题?WMS仓储管理系统解决方案
How to use the low code platform of the Internet of things for picture management?
Open source summer 2022 | opengauss project selected and announced
Jinyuan's high-end IPO was terminated: it was planned to raise 750million Rushan assets and Liyang industrial investment were shareholders
binder hwbinder vndbinder
随机推荐
Good news - British software 2022 has obtained 10 invention patents!
Teach you how to install Oracle 19C on Windows 10 (detailed picture and text with step on pit Guide)
基于STM32F103ZET6库函数蜂鸣器实验
使用logrotate对宝塔的网站日志进行自动切割
通过 G1 GC Log 重新认识 G1 垃圾回收器
Implementation of reliable distributed locks redlock and redisson
Ansible environment installation and data recovery
Campus book resource sharing platform
PCB线路板蛇形布线要注意哪些问题?
Introduction to deep learning and neural networks
驾驭一切的垃圾收集器 -- G1
Making single test so simple -- initial experience of Spock framework
xctf攻防世界 MISC薪手进阶区
Blink SQL内置函数大全
One week technical update express of substrate and Boca 20220425 - 20220501
Two methods of MySQL database login and logout
基于STM32F103ZET6库函数跑马灯实验
Redis Series 2: data persistence improves availability
Technology sharing | introduction to kubernetes pod
云笔记到底哪家强 -- 教你搭建自己的网盘服务器