' Copyright 2002-2007.  Adobe Systems, Incorporated.  All rights reserved.
' This script demonstrates how to add a LayerSet
' and then duplicate the top layer and place it into
' the Layer Set.

Option Explicit

Dim appRef
Dim docRef
Dim layerSetRef
Dim layerRef
Dim fileName

Dim strSamples
Dim strDune
Dim strLocString
Dim strArg

Set appRef = CreateObject( "Photoshop.Application" )

appRef.BringToFront

If appRef.Documents.Count > 0 Then
    Set docRef = appRef.ActiveDocument
Else ' open sample file

	strSamples = "$$$/Windows/SamplesFolder/Directory=Samples"
	strArg = Array(strSamples)
	Call getLocString(strSamples)

	strDune = "$$$/ALF/Filename/Samples/Dune_tif=Dune.tif"
	strArg = Array(strDune)
	Call getLocString(strDune)

	fileName = appRef.Path & "\" & strSamples & "\" & strDune

	Set docRef = appRef.Open( fileName )
End If

Set layerSetRef = docRef.LayerSets.Add
Set layerRef = docRef.ArtLayers(1).Duplicate
layerRef.MoveToEnd layerSetRef

MsgBox "Duplicate Layers complete"

' ===============================================
' getLocString functions
' ===============================================
' on localized builds we pull the $$$/Strings from a .dat file, see documentation for more details
Function getLocString(strLocString)

	Dim objWshShell
	Dim myScriptPath
	Dim myFSO
	Dim strJSXFile

	Set objWshShell = WScript.CreateObject("WScript.Shell")
	myScriptPath = objWshShell.CurrentDirectory
	Set myFSO = CreateObject("Scripting.FileSystemObject")
	strJSXFile = myScriptPath + "\localize.jsx"

	strLocString =  appRef.DoJavaScriptFile(strJSXFile,Array(strLocString),1)

End Function
