Photoshop JS指定字体

时间:2016-12-05 00:36:40

标签: javascript photoshop photoshop-script

我正在尝试修改脚本以满足我的需要,并继续获取“TypeError:undefined不是对象......我无法弄明白为什么。我已经复制并粘贴了几乎所有的东西。问题在于将字体设置为Adobe Garamond。

脚本监听器有这些我认为相关的行但是,我不知道JS足以得到它。

    var idfontPostScriptName = stringIDToTypeID( "fontPostScriptName" );
    desc22.putString( idfontPostScriptName, """AGaramondPro-Regular""" );
    var idFntN = charIDToTypeID( "FntN" );
    desc22.putString( idFntN, """Adobe Garamond Pro""" );
    var idFntS = charIDToTypeID( "FntS" );
    desc22.putString( idFntS, """Regular""" );

我的脚本看起来像

    // this script is a variation of the script addTimeStamp.js that is installed with PH7

    //OPENED document has size
    if ( documents.length > 0 )
    {
var originalDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.ERROR;
var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

try
{
    var docRef = activeDocument;

    // Now create a text layer at the front
    var myLayerRef = docRef.artLayers.add();
    myLayerRef.kind = LayerKind.TEXT;
    myLayerRef.name = "Filename";

    var myTextRef = myLayerRef.textItem;

    // strip the extension off
    var fileNameNoExtension = docRef.name;
    fileNameNoExtension = fileNameNoExtension.split( "." );
    if ( fileNameNoExtension.length > 1 ) {
        fileNameNoExtension.length--;
    }
    fileNameNoExtension = fileNameNoExtension.join(".");

    myTextRef.contents = fileNameNoExtension;



    // off set the text to be in the middle
    myTextRef.position = new Array( docRef.width / 2, docRef.height / 2 );
    myTextRef.size = 135;
     myTextRef.textItem.font = 'AGaramondPro-Regular';
}
catch( e )
{
    // An error occurred. Restore ruler units, then propagate the error back
    // to the user
    preferences.rulerUnits = originalRulerUnits;
    app.displayDialogs = originalDialogMode;
    throw e;
}

// Everything went Ok. Restore ruler units
preferences.rulerUnits = originalRulerUnits;
app.displayDialogs = originalDialogMode;
    }
    else
    {
alert( "You must have a document open to add the filename!" );
    }

1 个答案:

答案 0 :(得分:1)

哦,我的地狱。刚回答了我自己的问题。对不起大家。

    myTextRef.font = 'AGaramondPro-Regular';