使用Photoshop脚本(JSX)显示/隐藏图层的功能 [英] Function to show/hide layer with Photoshop script (JSX)

查看:615
本文介绍了使用Photoshop脚本(JSX)显示/隐藏图层的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本,该脚本将循环遍历图层,修剪图层并导出.到目前为止,我已经拥有完成此脚本所需的所有要素.我唯一找不到的是如何显示/隐藏单个图层.我发现了可以显示/隐藏所有图层的功能,但对于单个图层则没有任何功能.

I am writing a script that will loop through layers, trim them and export. So far I have most of all the element I need to complete this script. The only thing I can't find is how to show/hide an individual layer. I've found functions to show/hide all layers but nothing for one single layer.

///////////////////////////////////////////////////////////////////////////////
// selectAllLayers - select all layers (Select > All Layers)
///////////////////////////////////////////////////////////////////////////////
function selectAllLayers() {
    var ref = new ActionReference();
    ref.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    var desc = new ActionDescriptor();
    desc.putReference(cTID('null'), ref);

    executeAction(sTID('selectAllLayers'), desc, DialogModes.NO);
}

///////////////////////////////////////////////////////////////////////////////
// hideLayers - hide all selected layers (Layer > Hide Layers)
///////////////////////////////////////////////////////////////////////////////
function hideLayers() {
    var ref = new ActionReference();
    ref.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    var list = new ActionList();
    list.putReference(ref);
    var desc = new ActionDescriptor();
    desc.putList(cTID('null'), list);
    executeAction(cTID('Hd  '), desc, DialogModes.NO);
}

function cTID(s) {return app.charIDToTypeID(s);}
function sTID(s) {return app.stringIDToTypeID(s);}

有什么想法吗?

推荐答案

Layer对象具有.visible布尔属性,可用于分别控制每个图层的可见性:

The Layer object has a .visible boolean property which you can use to control visibility for each layer individually:

// make active layer invisible
app.activeDocument.activeLayer.visible = false;

// make active layer visible
app.activeDocument.activeLayer.visible = true;

甚至切换所选/活动图层的可见性:

or even toggle visibility for the selected/active layer:

app.activeDocument.activeLayer.visible = !app.activeDocument.activeLayer.visible;

或循环浏览所需的图层并切换其可见性:

or loop through what layers you need and toggle their visibility:

//example hides odd layers while showing even layers, based on their index
var doc = app.activeDocument;
for(var i = 0 ; i < doc.layers.length;i++){
    doc.layers[i].visible = (i % 2 == 0);
}

我建议您在 Photoshop CS5 Javascript参考(PDF链接)或在ExtendScript Toolkit的对象模型查看器中.

I suggest having a looks either in the Photoshop CS5 Javascript Reference (PDF link) or in ExtendScript Toolkit's Object Model Viewer.

您可以通过帮助>对象模型查看器对其进行访问,然后从浏览器组合框/列表中选择 Adob​​e Photoshop CS5对象库,以选择Photoshop中可用的类的列表. DOM.

You can access it via Help > Object Model Viewer and select the Adobe Photoshop CS5 Object Library from the browser combobox/list to the list of classes available in the Photoshop DOM.

这篇关于使用Photoshop脚本(JSX)显示/隐藏图层的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆