当前位置:网站首页>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.作者寄语
合理的脚本代码可以有效的提高工作效率,减少重复劳动。
边栏推荐
- Blink SQL内置函数大全
- 让单测变得如此简单 -- spock 框架初体验
- MySQL中的行转列和列转行
- laravel框架中 定时任务的实现
- MySQL读取Binlog日志常见错误和解决方法
- Vscode suggests that you enable gopls. What exactly is it?
- Market status and development prospect forecast of global active quality control air sampler industry in 2022
- Keras deep learning practice (12) -- facial feature point detection
- Market status and development prospect forecast of phenethyl resorcinol for skin care industry in the world in 2022
- The IPO of Yuchen Airlines was terminated: Guozheng was proposed to raise 500million yuan as the major shareholder
猜你喜欢

Win10 LTSC 2021 wsappx CPU 占用高

明美新能源冲刺深交所:年应收账款超6亿 拟募资4.5亿

Redis 原理 - String

DFS and BFS simple principle

PostgreSQL数据库WAL——资源管理器RMGR

【ELT.ZIP】OpenHarmony啃论文俱乐部—数据密集型应用内存压缩

如何实现IM即时通讯“消息”列表卡顿优化

binder hwbinder vndbinder

Teach you how to install Oracle 19C on Windows 10 (detailed picture and text with step on pit Guide)

推荐几个开源的物联网平台
随机推荐
Open source summer 2022 | opengauss project selected and announced
Keras深度学习实战(12)——面部特征点检测
China's Industrial Software Market Research Report is released, and SCADA and MES of force control enrich the ecology of domestic industrial software
全面解析零知识证明:消解扩容难题 重新定义「隐私安全」
DFS and BFS simple principle
使用logrotate对宝塔的网站日志进行自动切割
实战回忆录:从Webshell开始突破边界
Comprehensively analyze the zero knowledge proof: resolve the expansion problem and redefine "privacy security"
校园书籍资源共享平台
How to view the index information of MySQL tables?
Application of tdengine in monitoring of CNC machine tools
Comment encapsuler un appel à une bibliothèque
What is ICMP? What is the relationship between Ping and ICMP?
International School of Digital Economics, South China Institute of technology 𞓜 unified Bert for few shot natural language understanding
Exporting coordinates of points in TXT format in ArcGIS
2022年第一季度消费金融APP用户洞察——总数达4479万人
Two methods of MySQL database login and logout
技术分享 | kubernetes pod 简介
Win10 LTSC 2021 wsappx CPU usage high
Gartner聚焦中国低代码发展 UniPro如何践行“差异化”