• Photoshop-图层相关概念-LayerComp-Layers-移动旋转复制图层-复合图层


    1.简介

      Photoshop图层就如同透明纸堆叠在一起。通过图层来包含其它元素,可以移动图层来移动整个图层。

    2.图层相关概念

    2.1.LayerComp

      文档中图层状态的快照,可用于查看不同的页面布局或合成。通过 Document.layerComps 集合访问。 您可以按名称访问图层复合。 例如,这为名为 myLayerComp 的 LayerComp 对象设置了 comment 属性值:

    var layercompRef = app.activeDocument.layerComps.getByName("myLayerComp");
    layercompRef.comment = "View from shoreline";
    
    • 1
    • 2

    2.2.LayerComps

      文档中 LayerComp 对象的集合。通过 Document.layerComps 集合属性访问。 例如:

    app.activeDocument.layerComps.add("myLayerComp", "View from Shoreline",
    true, true, true);
    
    • 1
    • 2

    2.3.Layers

      文档中图层对象的集合,包括 ArtLayer 和 LayerSet 对象。 通过访问Document.layers 或 LayerSet.layers 集合属性。例如,这使用 length 属性来计算活动文档中图层对象的数量,然后在屏幕上显示数字:

    var layerNum = app.activeDocument.layers.length
    alert(layerNum)
    
    • 1
    • 2

    2.4.LayerSet

      一组图层对象,可以包括 ArtLayer 对象和其他(嵌套的)LayerSet 对象。 单个命令可以操作集合中的所有层。通过 Document.layerSets 集合访问文档中的顶级图层集。 您可以按名称访问图层集。 例如,以下设置“myLayerSet”的 allLocked 值:

    var layerSetRef = app.activeDocument.layerSets.getByName("myLayerSet");
    layerSetRef.allLocked = true
    
    • 1
    • 2

      通过父集中的 LayerSet.layerSets 集合访问嵌套层集。 例如:

    app.activeDocument.layerSets[0].layerSets[0];
    
    • 1

    2.5.LayerSets

      文档中 LayerSet 对象的集合。通过 Document.layerSets 集合属性访问文档中的顶级图层集。 例如:

    var layerSetRef = app.activeDocument.layerSets.add()
    
    • 1

      通过父集中的 LayerSet.layerSets 集合属性访问嵌套层集。 例如:

    var layerSetRef = app.activeDocument.layerSets.getByName("myParentSet");
    var childSet = layerSetRef.layerSets.getByName("myChildSet");
    
    • 1
    • 2

    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;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    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;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30

    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;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    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!");
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    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;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    4.作者寄语

      合理的脚本代码可以有效的提高工作效率,减少重复劳动。

  • 相关阅读:
    如何在你的 wordpress 网站中添加搜索框
    【Kotlin】扩展属性、扩展函数
    【好书推荐】写Web必须知道的安全知识 | 《白帽子讲Web安全》
    Python内置函数/方法详解—列表list
    【scikit-learn基础】--『监督学习』之 空间聚类
    什么是微网格?微网格规划应考虑哪些因素?
    企业微信下班后能收到通知吗?不接收消息怎么设置?
    游戏中有n条龙,每条龙都有自身力量x及战胜它后的奖励力量 y,当你的力量超过龙时,才能打败龙和获得奖励力量。你可以自由选择挑战顺序,问最后你最多能打败多少条龙?
    网络拓扑结构
    标号变迁系统(Labelled Transition System)
  • 原文地址:https://blog.csdn.net/m0_67316550/article/details/125485059