在 Photoshop 脚本中打开和关闭多个图层
我在 Photoshop 中有 6 个组,每个组内包含多个图层。我希望打开/关闭每个组中的图层以创建图像的每种可能的组合。
有人能指出我正确的方向吗?
我从来没有在 Photoshop 中编写过脚本,而是尝试自己解决这个问题。
I have 6 groups in Photoshop that contain a number of layers within each group. I'm looking to turn on/off a layer within each group to create every possible combination of the image.
Can someone point me in the right direction?
I've never scripted in Photoshop but trying to figure this out on my own.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己对 CS5 脚本编写很陌生,但我想我可以解释它是如何工作的。代码示例可能不是最有效的方法,但它确实有效。
一组层或单个层本身之间存在很大差异。
所有层和组均以 DOM 格式排序。要获取 root 权限,您可以使用全局实例
app
来获取活动文档:app.activeDocument
。混乱的部分是单层和组有两个单独的数组。
要获取单层数组,请使用
app.activeDocument.layers
和app.activeDocument.layerSets
作为组。要深入层次结构,请使用 layerSets 数组向下迭代。
例如,让我们假设以下层次结构:
这里
Border
、Star
、Home
、Add
和删除
都是单层,而Icons
、Left
和Right
是组。要打开组
Left
,我们需要向下迭代Icon
组:如果您通过单击鼠标在 CS5 中显示图层/组,则所有父组将自动显示也。通过编写脚本,情况并非如此,您还必须启用所有父母。
要显示边框图层,您需要使用图层数组。
如果您想显示添加图层,同样的情况也适用。
如果您有很多组和图层,这可能会有点混乱。我创建了一个函数,它遵循提供的路径来获取最终对象。它会自行确定它是一个图层还是一个组。
...还有一个功能可以通过其路径简单地设置或清除组或图层。
..最后我编写了这个函数来隐藏用户指定根目录中的所有组和/或层。
这是如何使用这些功能的示例
,我希望这对我以外的其他人有用:)
I'm quite new to CS5 scripting myself, but I think I can explain how it works. The code examples may not be the most effective way to do it, but it does the trick.
There is a big difference between a Group of layers or the individual layer itself.
All layers and groups are ordered in the DOM format. To get your root you can use the global instance
app
to get the active document:app.activeDocument
.The messy part is that there are two separate arrays for single layers and groups.
To get the array of single layers use
app.activeDocument.layers
andapp.activeDocument.layerSets
for the groups.To go deeper down in the hieralcy, use the layerSets array to iterate down.
For example, let us assume the following hieralcy:
Here
Border
,Star
,Home
,Add
andRemove
are all single layers whileIcons
,Left
andRight
are Groups.To turn on group
Left
we need to iterate down theIcon
group:If you show a layer/group in CS5 by clicking with your mouse, all parent groups will automatically be shown too. By scripting this isn't the case, you have to enable all parents as well.
To show the Border layer you need to use the layers array instead.
Same things apply if you want to show the Add layer.
This can be a bit messy if you have a lot of groups and layers. I created a function that follows a supplied path to get the end object. It will determine by itself if it is a layer or a group.
...and one function to simply set or clear a group or layer by its path.
..and at last I wrote this function to hide all groups and/or layers from a user specified root.
Here is an example of how to use the functions
I hope this is useful to someone more than just me :)