Function to show/hide layer with Photoshop script (JSX)

▼魔方 西西 提交于 2019-12-05 13:29:22

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!