2016-01-13 86 views
0

我到處搜索,無法找到語法/屬性來使用腳本關閉圖層集。Photoshop腳本(JSX):如何契約layerSet?

我有這個,我layerSet擴展:http://i.imgur.com/uVBiPa4.jpg

v Group 1 
    - Layer 1 
    - Layer 2 

我想這一點,在我的layerSet關閉:http://i.imgur.com/j6BVyYu.jpg

> Group 1 

起初,我嘗試一些東西,因爲我知道layerSet名稱,但沒有任何事情發生。

doc.layerSets.getByName('Group 1').groupContract = true; 

我想這個另一種,但它決不能是正確的兩種。

doc.layerSets.getByName('Group 1').groupExpand = false; 

如果任何人有一個想法......

回答

0

發現我的答案,從JJMack: https://forums.adobe.com/thread/1315645?start=0&tstart=0

這是一個有點棘手,但它的工作。 這是一個簡化版本:

//For code readability 
function cTID(s){return charIDToTypeID(s)} 
function sTID(s){return stringIDToTypeID(s)} 
// =============================   

function closeAllLayerSets(ref) { 
      var layers = ref.layers; 
      var len = layers.length; 
      for (var i = 0; i < len; i ++) { 
        var layer = layers[i]; 
        if (layer.typename == 'LayerSet') {app.activeDocument.activeLayer = layer; closeGroup(layer); var layer = layers[i]; closeAllLayerSets(layer);}; 
      } 
} 

function hasLayerMask() { 
    var m_Ref01 = new ActionReference(); 
    m_Ref01.putEnumerated(sTID("layer"), cTID("Ordn"), cTID("Trgt")); 
    var m_Dsc01= executeActionGet(m_Ref01); 
    return m_Dsc01.hasKey(cTID('Usrs')); 
}   

function addLayer() { 
    var m_ActiveLayer   = activeDocument.activeLayer; 
    var m_NewLayer    = activeDocument.artLayers.add(); 
    m_NewLayer.move(m_ActiveLayer, ElementPlacement.PLACEBEFORE); 

    return m_NewLayer; 
} 

function addToSelection(layerName) { 
    var m_Dsc01 = new ActionDescriptor(); 
    var m_Ref01 = new ActionReference(); 
    m_Ref01.putName(cTID("Lyr "), layerName); 
    m_Dsc01.putReference(cTID("null"), m_Ref01); 
    m_Dsc01.putEnumerated(sTID("selectionModifier"), sTID("selectionModifierType"), sTID("addToSelection")); 
    m_Dsc01.putBoolean(cTID("MkVs"), false); 

    try { 
     executeAction(cTID("slct"), m_Dsc01, DialogModes.NO); 
    } catch(e) {} 
} 

function groupSelected(name) { 
    var m_Dsc01 = new ActionDescriptor(); 
    var m_Ref01 = new ActionReference(); 
    m_Ref01.putClass(sTID("layerSection")); 
    m_Dsc01.putReference( cTID("null"), m_Ref01); 
    var m_Ref02 = new ActionReference(); 
    m_Ref02.putEnumerated(cTID("Lyr "), cTID("Ordn"), cTID("Trgt")); 
    m_Dsc01.putReference(cTID("From"), m_Ref02); 
    var m_Dsc02 = new ActionDescriptor(); 
    m_Dsc02.putString(cTID("Nm "), name); 
    m_Dsc01.putObject(cTID("Usng"), sTID("layerSection"), m_Dsc02); 
    executeAction(cTID("Mk "), m_Dsc01, DialogModes.NO); 

    return activeDocument.activeLayer; 
}  

function closeGroup(layerSet) { 
    var m_Name = layerSet.name; 
    var m_Opacity = layerSet.opacity; 
    var m_BlendMode = layerSet.blendMode; 
    var m_LinkedLayers = layerSet.linkedLayers; 

    var m_bHasMask = hasLayerMask(); 
    if(m_bHasMask) loadSelectionOfMask(); 


    if(layerSet.layers.length <= 1) { 
     addLayer(); 
     var m_Tmp = activeDocument.activeLayer; 
     m_Tmp.name = "dummy - feel free to remove me"; 
     activeDocument.activeLayer = layerSet; 
     ungroup(); 
     addToSelection("dummy - feel free to remove me"); 
     groupSelected(m_Name); 

    } else { 
     activeDocument.activeLayer = layerSet; 
     ungroup(); 
     groupSelected(m_Name); 
    } 


    var m_Closed = activeDocument.activeLayer; 
    m_Closed.opacity = m_Opacity; 
    m_Closed.blendMode = m_BlendMode; 

    for(x in m_LinkedLayers) { 
     if(m_LinkedLayers[x].typename == "LayerSet") 
     activeDocument.activeLayer.link(m_LinkedLayers[x]); 
    } 

    if(m_bHasMask) maskFromSelection(); 

    return m_Closed; 
} 

function ungroup() { 
    var m_Dsc01 = new ActionDescriptor(); 
    var m_Ref01 = new ActionReference(); 
    m_Ref01.putEnumerated(cTID("Lyr "), cTID("Ordn"), cTID("Trgt")); 
    m_Dsc01.putReference(cTID("null"), m_Ref01); 

    try { 
     executeAction(sTID("ungroupLayersEvent"), m_Dsc01, DialogModes.NO); 
    } catch(e) {} 
} 

closeAllLayerSets(app.activeDocument);