【问题标题】:Finding the index # of a layer after locating it by name按名称定位图层后查找图层的索引号
【发布时间】:2016-07-25 00:32:08
【问题描述】:

我了解图层名称只能作为对象访问。但是有没有办法使用该对象名称来查找数组中的索引位置?换句话说,我在一个文件中有多个图层。我想找到一个特定的图层,锁定并更改其上方所有图层的可见性,然后解锁并更改其下方所有图层的可见性。我将始终寻找相同的层,但总层数会因工作而异。任何帮助将不胜感激!

【问题讨论】:

    标签: javascript object layer indexof adobe-illustrator


    【解决方案1】:

    只需遍历所有层并检查每个层是否与您的名字匹配。如果它确实保存了索引(当前循环计数)。

    // get index (from top layer down) of named layer... expects only one layer  with this name
    // name of layer you are looking for
    var targetLayerName = 'name'  
    
    var targetDocument = app.activeDocument;
    var layerCount = targetDocument.layers.length;
    var namedLayerIndex = 0;
    // loop through layers and find the named layer
    for ( i = 0; i < layerCount; i++ ) {
        if (targetDocument.layers[i].name == targetLayerName) {
            namedLayerIndex = i;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-03-30
      • 2021-03-02
      • 2013-08-28
      • 2012-10-13
      • 1970-01-01
      • 1970-01-01
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多