Level One Magic
"Any sufficiently advanced technology is indistinguishable from magic." - Arthur C. Clarke
createTextureTemplate.js
///////////////////////////////////////////////////////////////////////////////
// Function: makeGroup
// Usage:   create a new layer set
// Input:   the name of a group to make
// Return:  the new group object
///////////////////////////////////////////////////////////////////////////////
function makeGroup(groupName)
{
    var docRef = app.activeDocument
    var newGroup = docRef.layerSets.add()
    newGroup.name = groupName
    return newGroup
}

///////////////////////////////////////////////////////////////////////////////
// Function: makeBase
// Usage:   create a new layer set
// Input:   the name of the layer to make,
//          the name of the group to put the layer in,
//          the color to fill the layer with
// Return:  the new layer object
///////////////////////////////////////////////////////////////////////////////
function makeBase(baseName, groupName, fillColor)
{
    var docRef = app.activeDocument
    var newBase = docRef.artLayers.add()
    newBase.name = baseName
    newBase.move(groupName, ElementPlacement.INSIDE)
    docRef.selection.fill(fillColor)
    return newBase
}

///////////////////////////////////////////////////////////////////////////////
// Function: main
// Usage: the main function to call
// Input: none
// Return: none
///////////////////////////////////////////////////////////////////////////////
function main()
{
    preferences.rulerUnits = Units.PIXELS

    var docRef = app.documents.add(1024, 1024)
    docRef.selection.selectAll()

    var glowGrp = makeGroup("Glow")
    var heightGrp = makeGroup("Height")
    var specGrp = makeGroup("Specular")
    var diffuseGrp = makeGroup("Diffuse")

    var blackColor = new SolidColor()
    blackColor.rgb.red = 0
    blackColor.rgb.green = 0
    blackColor.rgb.blue = 0

    var glowBase = makeBase("Glow Base", glowGrp, blackColor)
    var heightBase = makeBase("Height Base", heightGrp, blackColor)
    var specBase = makeBase("Spec Base", specGrp, blackColor)
    var diffuseBase = makeBase("Diffuse Base", diffuseGrp, blackColor)

    // clear selection and remove "Background" layer
    docRef.selection.deselect()
    docRef.artLayers[docRef.artLayers.length - 1].remove()
}

main()

Back to Main

© 2003-2013 Andrew Kelts