我在任何地方都搜索过,因为我无法找到使用脚本关闭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 :(得分: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 );