Class Index | File Index

Classes


Namespace jamStyles


Version 4.5.

Defined in: jamStyles.jsxinc.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Global object (used to simulate a namespace in JavaScript) containing a set of layer styles-related functions for scripts written with the JSON Action Manager engine.
Method Summary
Method Attributes Method Name and Description
<static>  
jamStyles.applyLayerStyle(styleName, merge)
Apply a layer style preset.
<static>  
jamStyles.clearLayerStyle()
Clear a layer style (reset blending options to default and remove all layer effects).
<static>  
jamStyles.copyLayerStyle()
Copy a layer style.
<static>  
jamStyles.dataFromStylesFile(stylesFile, includePatternsInfo)
Convert a styles file (*.asl or Styles.psp) into a data structure in JSON format [available in CS2 or later].
<static>  
jamStyles.fromBlendOptionsObject(blendOptionsObject)
Get a simplified blending options JSON object from a blending options object in JSON AM Data Format.
<static>  
jamStyles.fromDocumentModeObject(documentModeObject)
Get a simplified document mode JSON object from a document mode object in JSON AM Data Format.
<static>  
jamStyles.fromLayerEffectsObject(layerEffectsObject)
Get a simplified layer effects JSON object from a layer effects object in JSON AM Data Format.
<static>  
jamStyles.getLayerStyle()
Get the current layer style (blending options and layer effects) [available in CS2 or later].
<static>  
jamStyles.isStylesFile(file)
Test if a given file is a styles file (*.asl).
<static>  
jamStyles.isStylesPalette(file)
Test if a given file is a styles palette file (Styles.psp).
<static>  
jamStyles.pasteLayerStyle()
Paste a layer style.
<static>  
jamStyles.patternsFileFromPatterns(patternsFile, patternsData)
Generate a patterns file from patterns data extracted from a styles file (*.asl or Styles.psp).
<static>  
jamStyles.patternsFromStylesFile(stylesFile)
Extract patterns data from a styles file (*.asl or Styles.psp).
<static>  
Remove (delete) all layer effects.
<static>  
jamStyles.removeLayerEffect(effect)
Remove (delete) a layer effect.
<static>  
jamStyles.removeLayerEffects(effects)
Remove (delete) several layer effects.
<static>  
jamStyles.scaleLayerEffects(scale)
Scale layer effects.
<static>  
jamStyles.setApplicationGlobalAngle(globalLightingAngle, globalAltitude)
Set application's layer effects global angle (global light: lighting angle and altitude).
<static>  
jamStyles.setDocumentGlobalAngle(globalLightingAngle, globalAltitude)
Set document's layer effects global angle (global light: lighting angle and altitude).
<static>  
jamStyles.setLayerStyle(layerStyleObj, ignoreScale)
Set the current layer style (blending options and layer effects).
<static>  
Show or hide all document effects.
<static>  
jamStyles.showHideAllLayerEffects(show)
Show or hide all layer effects.
<static>  
jamStyles.showHideLayerEffect(effect, show)
Show or hide a layer effect.
<static>  
jamStyles.showHideLayerEffects(effects, show)
Show or hide several layer effects.
<static>  
jamStyles.toBlendOptionsObject(blendOptions)
Get a blending options object in JSON AM Data Format from a simplified blending options JSON object.
<static>  
jamStyles.toDocumentModeObject(documentMode)
Get a document mode object in JSON AM Data Format from a simplified document mode JSON object.
<static>  
jamStyles.toLayerEffectsObject(layerEffects)
Get a layer effects object in JSON AM Data Format from a simplified layer effects JSON object.
Namespace Detail
jamStyles
Global object (used to simulate a namespace in JavaScript) containing a set of layer styles-related functions for scripts written with the JSON Action Manager engine.
Uses information found in the document Photoshop Styles File Format.
Author: Michel MARIANI.
Method Detail
<static> jamStyles.applyLayerStyle(styleName, merge)
Apply a layer style preset.
jamUtils.loadPreset ("style", "Logo X-Aqua in Blue Glass (Button)", "Logo-X-Aqua.asl");
jamStyles.applyLayerStyle ("Logo X-Aqua in Blue Glass (Button)");
Parameters:
{String} styleName
Layer style preset name
{Boolean} merge Optional
Merge with current layer style

<static> jamStyles.clearLayerStyle()
Clear a layer style (reset blending options to default and remove all layer effects).
jamStyles.clearLayerStyle ();

<static> jamStyles.copyLayerStyle()
Copy a layer style.
jamStyles.copyLayerStyle ();
See:
jamStyles.pasteLayerStyle

<static> {Object|String} jamStyles.dataFromStylesFile(stylesFile, includePatternsInfo)
Convert a styles file (*.asl or Styles.psp) into a data structure in JSON format [available in CS2 or later].
function stylesFileFilter (f)
{
    return (f instanceof Folder) || jamStyles.isStylesFile (f);
}
var select = (File.fs === "Macintosh") ? stylesFileFilter : "Styles Files:*.asl,All Files:*";
var stylesFile = File.openDialog ("Select a styles file:", select);
if (stylesFile !== null)
{
    var fileData = jamStyles.dataFromStylesFile (stylesFile, true);
    if (typeof fileData === 'string')
    {
        alert (fileData + "\n" + "Styles file: “" + File.decode (stylesFile.name) + "”");
    }
    else
    {
        alert ("Number of patterns: " + fileData["patterns"].length);
        alert ("Number of styles: " + fileData["styles"].length);
    }
}
Parameters:
{String|Object} stylesFile
Styles file path string or File object
{Boolean} includePatternsInfo
Include embedded patterns basic info
Returns:
{Object|String} Converted styles file data structure in JSON format, or error message string

<static> {Object} jamStyles.fromBlendOptionsObject(blendOptionsObject)
Get a simplified blending options JSON object from a blending options object in JSON AM Data Format.
jamEngine.meaningfulIds = true;
jamEngine.parseFriendly = true;
var style = { };
var actionDescriptor;
var jsonDesc;
actionDescriptor = jamActions.readActionDescriptor (stylesFile);
jsonDesc = jamEngine.classIdAndActionDescriptorToJson (0, actionDescriptor)["<descriptor>"];
style["name"] = jsonDesc["name"][1];
style["ID"] = jsonDesc["ID"][1];
actionDescriptor = jamActions.readActionDescriptor (stylesFile);
jsonDesc = jamEngine.classIdAndActionDescriptorToJson (0, actionDescriptor)["<descriptor>"];
if ("blendOptions" in jsonDesc)
{
    style["blendOptions"] = jamStyles.fromBlendOptionsObject (jsonDesc["blendOptions"]);
}
$.writeln (jamJSON.stringify (style, '\t'));
Parameters:
{Object|Array} blendOptionsObject
Blending options object in JSON AM Data Format
Returns:
{Object} Simplified blending options JSON object (cf. Blending Options Object Simplified Format)
See:
jamStyles.toBlendOptionsObject

<static> {Object} jamStyles.fromDocumentModeObject(documentModeObject)
Get a simplified document mode JSON object from a document mode object in JSON AM Data Format.
jamEngine.meaningfulIds = true;
jamEngine.parseFriendly = true;
var style = { };
var actionDescriptor;
var jsonDesc;
actionDescriptor = jamActions.readActionDescriptor (stylesFile);
jsonDesc = jamEngine.classIdAndActionDescriptorToJson (0, actionDescriptor)["<descriptor>"];
style["name"] = jsonDesc["name"][1];
style["ID"] = jsonDesc["ID"][1];
actionDescriptor = jamActions.readActionDescriptor (stylesFile);
jsonDesc = jamEngine.classIdAndActionDescriptorToJson (0, actionDescriptor)["<descriptor>"];
if ("documentMode" in jsonDesc)
{
    style["documentMode"] = jamStyles.fromDocumentModeObject (jsonDesc["documentMode"]);
}
$.writeln (jamJSON.stringify (style, '\t'));
Parameters:
{Object|Array} documentModeObject
Document mode object in JSON AM Data Format
Returns:
{Object} Simplified document mode JSON object (cf. Document Mode Object Simplified Format)
See:
jamStyles.toDocumentModeObject

<static> {Object} jamStyles.fromLayerEffectsObject(layerEffectsObject)
Get a simplified layer effects JSON object from a layer effects object in JSON AM Data Format.
if (parseInt (app.version) >= 10) // CS3
{
    jamEngine.meaningfulIds = true;
    jamEngine.parseFriendly = true;
    try
    {
        var resultDescObj = jamEngine.jsonGet
        (
            [
                [ "property", [ "<property>", "layerEffects" ] ],
                [ "layer", [ "<enumerated>", [ "ordinal", "targetEnum" ] ] ]
            ]
        );
        var layerEffects = jamStyles.fromLayerEffectsObject (resultDescObj["layerEffects"]);
    }
    catch (e)
    {
        var layerEffects = null;
    }
    if (layerEffects)
    {
        $.writeln (jamJSON.stringify (layerEffects, '\t'));
    }
    else
    {
        alert ("No layer effects selected.");
    }
}
Parameters:
{Object|Array} layerEffectsObject
Layer effects object in JSON AM Data Format
Returns:
{Object} Simplified layer effects JSON object (cf. Layer Effects Object Simplified Format)
See:
jamStyles.toLayerEffectsObject

<static> {Object|Null} jamStyles.getLayerStyle()
Get the current layer style (blending options and layer effects) [available in CS2 or later].
var layerStyleObj = jamStyles.getLayerStyle ();
if (layerStyleObj)
{
    if ("layerEffects" in layerStyleObj)
    {
        var layerEffectsObj = layerStyleObj["layerEffects"];
        if ("dropShadow" in layerEffectsObj)
        {
            var dropShadowObj = layerEffectsObj["dropShadow"];
            alert ("Drop shadow distance: " + dropShadowObj["distance"]);
        }
        else
        {
            alert ("No drop shadow");
        }
    }
    else
    {
        alert ("No layer effects");
    }
}
Returns:
{Object|Null} Simplified layer style JSON object made of two optional members:
"blendOptions" (cf. Blending Options Object Simplified Format)
"layerEffects" (cf. Layer Effects Object Simplified Format)
or null if not available
See:
jamStyles.setLayerStyle

<static> {Boolean} jamStyles.isStylesFile(file)
Test if a given file is a styles file (*.asl).
function stylesFileFilter (f)
{
    return (f instanceof Folder) || jamStyles.isStylesFile (f);
}
var select = (File.fs === "Macintosh") ? stylesFileFilter : "Styles Files:*.asl,All Files:*";
var stylesFile = File.openDialog ("Select a styles file:", select);
if (stylesFile !== null)
{
    alert ("OK!");
}
Parameters:
{Object} file
File object
Returns:
{Boolean} true if styles file
See:
jamStyles.isStylesPalette

<static> {Boolean} jamStyles.isStylesPalette(file)
Test if a given file is a styles palette file (Styles.psp).
function stylesPaletteFilter (f)
{
    return (f instanceof Folder) || jamStyles.isStylesPalette (f);
}
var select = (File.fs === "Macintosh") ? stylesPaletteFilter : "Styles Palette File:Styles.psp,All Files:*.*";
var stylesPaletteFile = File.openDialog ("Select a styles palette file:", select);
if (stylesPaletteFile !== null)
{
    alert ("OK!");
}
Parameters:
{Object} file
File object
Returns:
{Boolean} true if styles palette file
See:
jamStyles.isStylesFile

<static> jamStyles.pasteLayerStyle()
Paste a layer style.
jamStyles.pasteLayerStyle ();
See:
jamStyles.copyLayerStyle

<static> jamStyles.patternsFileFromPatterns(patternsFile, patternsData)
Generate a patterns file from patterns data extracted from a styles file (*.asl or Styles.psp).
function stylesFileFilter (f)
{
    return (f instanceof Folder) || jamStyles.isStylesFile (f);
}
var select = (File.fs === "Macintosh") ? stylesFileFilter : "Styles Files:*.asl,All Files:*";
var stylesFile = File.openDialog ("Select a styles file:", select);
if (stylesFile !== null)
{
    var patternsData = jamStyles.patternsFromStylesFile (stylesFile);
    if (typeof patternsData === 'string')
    {
        alert (patternsData + "\n" + "Styles file: “" + File.decode (stylesFile.name) + "”");
    }
    else
    {
        var patternsFile = new File ("~/Desktop/myPatterns.pat");
        jamStyles.patternsFileFromPatterns (patternsFile, patternsData);
        patternsFile.parent.execute ();
    }
}
Parameters:
{String|Object} patternsFile
Patterns file path string or File object
{Array} patternsData
JSON array of patterns data

<static> {Array|String} jamStyles.patternsFromStylesFile(stylesFile)
Extract patterns data from a styles file (*.asl or Styles.psp).
function stylesFileFilter (f)
{
    return (f instanceof Folder) || jamStyles.isStylesFile (f);
}
var select = (File.fs === "Macintosh") ? stylesFileFilter : "Styles Files:*.asl,All Files:*";
var stylesFile = File.openDialog ("Select a styles file:", select);
if (stylesFile !== null)
{
    var patternsData = jamStyles.patternsFromStylesFile (stylesFile);
    if (typeof patternsData === 'string')
    {
        alert (patternsData + "\n" + "Styles file: “" + File.decode (stylesFile.name) + "”");
    }
    else
    {
        alert ("Number of patterns: " + patternsData.length);
    }
}
Parameters:
{String|Object} stylesFile
Styles file path string or File object
Returns:
{Array|String} JSON array of patterns data, or error message string

<static> jamStyles.removeAllLayerEffects()
Remove (delete) all layer effects.
jamStyles.removeAllLayerEffects ();
See:
jamStyles.removeLayerEffect
jamStyles.removeLayerEffects

<static> jamStyles.removeLayerEffect(effect)
Remove (delete) a layer effect.
jamStyles.removeLayerEffect ("dropShadow");
Parameters:
{String} effect
Layer effect to remove (delete), among:
  • "bevelEmboss"
  • "frameFX"
  • "innerShadow"
  • "innerGlow"
  • "chromeFX"
  • "solidFill"
  • "gradientFill"
  • "patternFill"
  • "outerGlow"
  • "dropShadow"
See:
jamStyles.removeLayerEffects
jamStyles.removeAllLayerEffects

<static> jamStyles.removeLayerEffects(effects)
Remove (delete) several layer effects.
jamStyles.removeLayerEffects ([ "dropShadow", "bevelEmboss" ]);
Parameters:
{Array} effects
Array of layer effects to remove (delete), among:
  • "bevelEmboss"
  • "frameFX"
  • "innerShadow"
  • "innerGlow"
  • "chromeFX"
  • "solidFill"
  • "gradientFill"
  • "patternFill"
  • "outerGlow"
  • "dropShadow"
See:
jamStyles.removeLayerEffect
jamStyles.removeAllLayerEffects

<static> jamStyles.scaleLayerEffects(scale)
Scale layer effects.
jamStyles.scaleLayerEffects (200);
Parameters:
{Number} scale
Layer effects scaling factor (percentage: 1% to 1000%)

<static> jamStyles.setApplicationGlobalAngle(globalLightingAngle, globalAltitude)
Set application's layer effects global angle (global light: lighting angle and altitude).
jamStyles.setApplicationGlobalAngle (30, 45);
Parameters:
{Number} globalLightingAngle
Global lighting angle (-180° to 180°)
{Number} globalAltitude Optional
Global altitude (0° to 90°)
See:
jamStyles.setDocumentGlobalAngle

<static> jamStyles.setDocumentGlobalAngle(globalLightingAngle, globalAltitude)
Set document's layer effects global angle (global light: lighting angle and altitude).
jamStyles.setDocumentGlobalAngle (120, 90);
Parameters:
{Number} globalLightingAngle
Global lighting angle (-180° to 180°)
{Number} globalAltitude Optional
Global altitude (0° to 90°)
See:
jamStyles.setApplicationGlobalAngle

<static> jamStyles.setLayerStyle(layerStyleObj, ignoreScale)
Set the current layer style (blending options and layer effects).
jamStyles.setLayerStyle
(
    {
        "blendOptions":
        {
            "mode": "difference",
            "opacity": 100,
            "fillOpacity": 70,
            "blendInterior": true
        },
        "layerEffects":
        {
            "scale": 100,
            "solidFill":
            {
                "enabled": true,
                "mode": "normal",
                "opacity": 100,
                "color": { "red": 125, "green": 0, "blue": 215 }
            },
            "dropShadow":
            {
                "enabled": true,
                "mode": "multiply",
                "color": { "red": 0, "green": 0, "blue": 0 },
                "opacity": 70,
                "localLightingAngle": 135,
                "useGlobalAngle": false,
                "distance": 10,
                "chokeMatte": 20,
                "blur": 15,
                "transparencyShape":
                {
                    "name": "Linear",
                    "curve":
                    [
                        { "horizontal": 0, "vertical": 0 },
                        { "horizontal": 255, "vertical": 255 }
                    ]
                },
                "antiAlias": false,
                "noise": 8,
                "layerConceals": true
            }
        }
    }
);
Parameters:
{Object|Null} layerStyleObj
Simplified layer style JSON object made of two optional members:
"blendOptions" (cf. Blending Options Object Simplified Format)
"layerEffects" (cf. Layer Effects Object Simplified Format)
If null, apply default style (none), i.e., reset blending options to default and remove all layer effects
{Boolean} ignoreScale Optional
Ignore scale property of layer effects; false by default
See:
jamStyles.getLayerStyle

<static> jamStyles.showHideAllDocumentEffects(show)
Show or hide all document effects.
jamStyles.showHideAllDocumentEffects ();      // Hide
jamStyles.showHideAllDocumentEffects (true);  // Show
Parameters:
{Boolean} show Optional
Show (instead of hide) all document effects; false by default
See:
jamStyles.showHideLayerEffect
jamStyles.showHideLayerEffects
jamStyles.showHideAllLayerEffects

<static> jamStyles.showHideAllLayerEffects(show)
Show or hide all layer effects.
jamStyles.showHideAllLayerEffects ();      // Hide
jamStyles.showHideAllLayerEffects (true);  // Show
Parameters:
{Boolean} show Optional
Show (instead of hide) all layer effects; false by default
See:
jamStyles.showHideLayerEffect
jamStyles.showHideLayerEffects
jamStyles.showHideAllDocumentEffects

<static> jamStyles.showHideLayerEffect(effect, show)
Show or hide a layer effect.
jamStyles.showHideLayerEffect ("dropShadow");         // Hide
jamStyles.showHideLayerEffect ("bevelEmboss", true);  // Show
Parameters:
{String} effect
Layer effect to show or hide, among:
  • "bevelEmboss"
  • "frameFX"
  • "innerShadow"
  • "innerGlow"
  • "chromeFX"
  • "solidFill"
  • "gradientFill"
  • "patternFill"
  • "outerGlow"
  • "dropShadow"
{Boolean} show Optional
Show (instead of hide) the layer effect; false by default
See:
jamStyles.showHideLayerEffects
jamStyles.showHideAllLayerEffects
jamStyles.showHideAllDocumentEffects

<static> jamStyles.showHideLayerEffects(effects, show)
Show or hide several layer effects.
jamStyles.showHideLayerEffects ([ "dropShadow", "bevelEmboss" ]);                       // Hide
jamStyles.showHideLayerEffects ([ "solidFill", "gradientFill", "patternFill" ], true);  // Show
Parameters:
{Array} effects
Array of layer effects to show or hide, among:
  • "bevelEmboss"
  • "frameFX"
  • "innerShadow"
  • "innerGlow"
  • "chromeFX"
  • "solidFill"
  • "gradientFill"
  • "patternFill"
  • "outerGlow"
  • "dropShadow"
{Boolean} show Optional
Show (instead of hide) the layer effects; false by default
See:
jamStyles.showHideLayerEffect
jamStyles.showHideAllLayerEffects
jamStyles.showHideAllDocumentEffects

<static> {Object|Array} jamStyles.toBlendOptionsObject(blendOptions)
Get a blending options object in JSON AM Data Format from a simplified blending options JSON object.
var blendOptions =
{
    "mode": "overlay",
    "opacity": 75,
    "fillOpacity": 50
};
jamEngine.jsonPlay
(
    "set",
    {
        "target":
        {
            "<reference>":
            [
                { "layer": { "<enumerated>": { "ordinal": "targetEnum" } } }
            ]
        },
        "to": jamStyles.toBlendOptionsObject (blendOptions)
    }
);
Parameters:
{Object} blendOptions
Simplified blending options JSON object (cf. Blending Options Object Simplified Format)
Returns:
{Object|Array} Blending options object in JSON AM Data Format
See:
jamStyles.fromBlendOptionsObject

<static> {Object|Array} jamStyles.toDocumentModeObject(documentMode)
Get a document mode object in JSON AM Data Format from a simplified document mode JSON object.
var documentMode =
{
    "colorSpace": "RGBColor",
    "depth": 8
};
alert (jamJSON.stringify (jamStyles.toDocumentModeObject (documentMode), '\t'));
// ->
// [
//     "<object>",
//     [
//         "documentMode",
//         {
//             "colorSpace":
//             [
//                 "<enumerated>",
//                 [
//                     "colorSpace",
//                     "RGBColor"
//                 ]
//             ],
//             "depth":
//             [
//                 "<integer>",
//                 8
//             ]
//         }
//     ]
// ]
Parameters:
{Object} documentMode
Simplified document mode JSON object (cf. Document Mode Object Simplified Format)
Returns:
{Object|Array} Document mode object in JSON AM Data Format
See:
jamStyles.fromDocumentModeObject

<static> {Object|Array} jamStyles.toLayerEffectsObject(layerEffects)
Get a layer effects object in JSON AM Data Format from a simplified layer effects JSON object.
var layerEffects =
{
    "scale": 100,
    "dropShadow":
    {
        "enabled": true,
        "mode": "multiply",
        "color": { "red": 0, "green": 0, "blue": 0 },
        "opacity": 70,
        "localLightingAngle": 135,
        "useGlobalAngle": false,
        "distance": 10,
        "chokeMatte": 20,
        "blur": 15,
        "transparencyShape":
        {
            "name": "Linear",
            "curve":
            [
                { "horizontal": 0, "vertical": 0 },
                { "horizontal": 255, "vertical": 255 }
            ]
        },
        "antiAlias": false,
        "noise": 8,
        "layerConceals": true
    }
};
jamEngine.jsonPlay
(
    "set",
    {
        "target":
        {
            "<reference>":
            [
                { "property": { "<property>": "layerEffects" } },
                { "layer": { "<enumerated>": { "ordinal": "targetEnum" } } }
            ]
        },
        "to": jamStyles.toLayerEffectsObject (layerEffects)
    }
);
Parameters:
{Object} layerEffects
Simplified layer effects JSON object (cf. Layer Effects Object Simplified Format)
Returns:
{Object|Array} Layer effects object in JSON AM Data Format
See:
jamStyles.fromLayerEffectsObject

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 12 2016 23:32:44 GMT+0200 (CEST)