2012-02-22 15 views
3

Photoshopには、各グループ内に複数のレイヤーを含む6つのグループがあります。私は、各グループ内のレイヤーをオン/オフにして、イメージのすべての可能な組み合わせを作成することを検討しています。Photoshop Scriptで複数のレイヤーをオン/オフに切り替える

誰かが正しい方向に向かうことができますか?

私はPhotoshopでスクリプトを作成したことはありませんが、私自身でこれを理解しようとしました。

+1

に便利であると思います。この答えを見てくださいます。http:/ /stackoverflow.com/a/8544923/327466 – KatieK

答えて

3

私は自分自身でスクリプトを書くのが初めてですが、どのように動作するのか説明できます。コード例は、それを実行する最も効果的な方法ではないかもしれませんが、それはトリックです。

レイヤーのグループまたは個々のレイヤー自体に大きな違いがあります。 すべてのレイヤーとグループは、DOM形式で並べ替えられています。ルートを取得するには、グローバルインスタンスappを使用してアクティブドキュメントを取得します。app.activeDocument

単なる層とグループのための2つの別個のアレイがあるというのは面倒な部分です。 単一のレイヤの配列を取得するには、グループにapp.activeDocument.layersapp.activeDocument.layerSetsを使用します。

hieralcyでさらに深く進むには、layerSets配列を使用して反復処理を行います。

たとえば、私たちは次のようhieralcyを想定してみましょう:

ここ
-Border 
+Icons 
    +Left 
     -Star 
     -Home 
    +Right 
     -Add 
     -Remove 

BorderIconsLeftRightが基でありながらStarHomeAddRemoveはすべて、単一の層です。我々はIconグループをダウン反復処理する必要があるグループLeftをオンにするには

:あなたは、マウスでクリックして、CS5で層/グループを表示する場合は

Icons = app.activeDocument.layerSets.getByName("Icons"); 
Left = Icons.layerSets.getByName("Left"); 
Left.visible = true; 

、すべての親グループも自動的に表示されます。これをスクリプト化することによって、すべての親を有効にする必要があります。

Icons = app.activeDocument.layerSets.getByName("Icons"); 
Icons.visible = true; 
Left = Icons.layerSets.getByName("Left"); 
Left.visible = true; 

ボーダーレイヤーを表示するには、代わりにレイヤー配列を使用する必要があります。

app.activeDocument.layers.getByName("Border").visible = true; 

追加レイヤーを表示する場合は、同じことが適用されます。

Icons = app.activeDocument.layerSets.getByName("Icons"); 
Icons.visible = true; 
Right = Icons.layerSets.getByName("Right"); 
Right.visible = true; 
AddLayer = Right.layers.getByName("Add"); 
AddLayer.visible = true; 

あなたがグループと層の多くを持っている場合、これは少し厄介ことができます。最後のオブジェクトを取得するために、指定されたパスの後に続く関数を作成しました。レイヤーまたはグループであるかどうかは、単独で判断されます。

//****************************************** 
// GET BY PATH 
// Author: Max Kielland 
// 
// Gets the LayerSet or Layer at the path's end. 
// Example path "Icons/left" will return the LayerSet object "Left" 
// while "Icons/left/Star" will return the Layer object "Star" 
// If fSetPath is true, all the parents will be visible as well. 

function GetByPath(fPath,fSetPath) { 

    var lGroup = null; 
    var lPathArray = new Array(); 

    lPathArray = fPath.split('/'); 
    try { 
    lGroup = app.activeDocument.layers.getByName(lPathArray[0]); 
    } catch (err) { 
    lGroup = app.activeDocument.layerSets.getByName(lPathArray[0]); 
    } 

    if (fSetPath) 
    lGroup.visible = true; 

    for (n=1; n<lPathArray.length; n++) { 
    try { 
     lGroup = lGroup.layerSets.getByName(lPathArray[n]); 
    } catch(err) { 
     lGroup = lGroup.layers.getByName(lPathArray[n]); 
    } 
    if (fSetPath == true) 
     lGroup.visible = true; 
    } 

    return lGroup; 
} 

...グループやレイヤーをそのパスで簡単に設定またはクリアする機能です。

//****************************************** 
// SET STATUS 
// Author: Max Kielland 
// 
// Sets the Group or Layer's visible property 
// at the end of the path to fStatus. 

function SetStatus(fPath, fStatus) { 

    Obj = GetByPath(fPath,false); 
    Obj.visible = fStatus; 
} 

最後に、ユーザー指定のルートからすべてのグループおよび/またはレイヤーを非表示にするこの機能を書きました。ここで

/****************************************** 
// CLEAR GROUP 
// Author: Max Kielland 
// 
// Clears the visible property in a single 
// group/layer with the option to clear all 
// its children as well (fRecurs = true). 
// fLayerSet can be a layerSet object or a 
// String path. 

function ClearGroup(fLayerSet,fRecurs) { 

    var n; 
    var TargetGroup; 

    // Get LayerSet Object if reference is a string. 
    if (typeof fLayerSet == "string") 
    TargetGroup = GetByPath(fLayerSet); 
    else 
    TargetGroup = fLayerSet; 

    // Iterate through all LayerSets 
    for (n=0; n<TargetGroup.layerSets.length; n++) { 
    if (fRecurs == true) 
     ClearGroup(TargetGroup.layerSets[n],true); 
    else 
    TargetGroup.layerSets[n].visible = false; 
    } 

    // Iterate through all layers 
    for (n=0; n<TargetGroup.layers.length; n++) { 
    TargetGroup.layers[n].visible = false; 
    } 

    // Clear self 
    TargetGroup.visible = false; 
} 

// Hide group "Icon" and its children 
ClearGroup("Icons",true); 

//Show the layer "Home" 
GetByPath("Icons/Left/Home",true); 

// To just get the object "Right" 
var MyGroup = GetByPath("Icons/Right"); 

// Save the current document as a PNG file 
app.activeDocument.saveAs(File("Scripted Document.png"),PNGSaveOptions); 

機能を使用する方法の例です。私は、これは私だけよりも、誰か:)

関連する問題