1
我想修改一个脚本来为我需要它做的工作,并继续得到“TypeError:undefined不是一个对象...我找不到为什么,但我' VE的问题行复制并粘贴几乎一切。作为字体设置为Adobe Garamond字体。Photoshop JS指定字体
脚本听者这些行,我认为是相关的,但是,我不知道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!");
}
Photoshop倾向于使用Postscript字体名称(如果内存服务) - 这使复杂的事情:) –