java脚本隐藏图层,使用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);}

Any ideas?

解决方案

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;

or

// 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);

}

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

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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值