有没有办法使用ExtendScript在Adobe Photoshop CS5中获取文本(或其他)图层阴影参数,以便进一步将其转换为类似文本字符串的CSS3?
谢谢!
谢谢!
有一种方法。
您需要使用ActionManager:
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('dropShadow'));
desc.getUnitDoubleValue(stringIDToTypeID('distance'))
"dropShadow"是您想要读取的图层效果,例如"distance"是将返回的参数。其他图层效果和参数仅作为事件ID已知。如果需要其他事件ID,请查看文档(文档记录不良)。
下一个AM代码将检查是否存在图层样式阴影。
var res = false;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var hasFX = executeActionGet(ref).hasKey(stringIDToTypeID('layerEffects'));
if ( hasFX ){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
res = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).hasKey(stringIDToTypeID('dropShadow'));
}
return res;
这将会更详细地解释:http://forums.adobe.com/thread/714406
如果你找到了一种在不设置其他参数的情况下设置阴影的方法,请告诉我...
也许不是你想要的答案,但实际上没有办法从extendscript中访问图层样式的各个属性。API中唯一涉及图层样式的方法(截至CS6)是ArtLayer.applyStyle(name)
。你必须在Photoshop中创建一个样式,并按名称保存到调色板中才能使用它。
我能想到的唯一方法就是使用C/C++解析adobe/Adobe Photoshop/presets/styles/
中找到的.asl
文件。这些文件包含以专有格式保存的几个图层样式。我还没有找到任何解析这些文件的库,但它们可能存在。
Adobe Photoshop CS6\Required\CopyCSSToClipboard.jsx
Adobe Photoshop CS6/Adobe Photoshop CS6.app/Contents/Required/CopyCSSToClipboard.jsx
cssToClip.addDropShadow
以了解如何提取信息。 如果您想在自己的代码中使用CopyCSSToClipboard.jsx中的例程,请将以下片段添加到JSX文件中:runCopyCSSFromScript = true;
if (typeof cssToClip == "undefined")
$.evalFile( app.path + "/" + localize("$$$/ScriptingSupport/Required=Required") + "/CopyCSSToClipboard.jsx" );
CopyCSSToClipboard.jsx
的底部,有对 cssToClip.dumpLayerAttr
的示例调用。这是一种有用的方式,可以探索您可能希望从脚本访问但无法从 Photoshop DOM 访问的参数。 static void PrintCurrentLayer(Application ps)
{
var action = new ActionReference();
action.PutEnumerated(ps.CharIDToTypeID("Lyr "), ps.CharIDToTypeID("Ordn"), ps.CharIDToTypeID("Trgt"));
var desc = ps.ExecuteActionGet(action);//.GetObjectValue(ps.StringIDToTypeID("layerEffects"));//.getObjectValue(ps.StringIDToTypeID('dropShadow'));
ActionPrinter(desc);
}
static void ActionPrinter(ActionDescriptor action)
{
for (int i = 0; i < action.Count; i++)
{
var key = action.GetKey(i);
if (action.HasKey(key))
{
//var charId = action.Application.TypeIDToCharID((int)key);
//Debug.WriteLine(charId);
switch (action.GetType(key))
{
case PsDescValueType.psIntegerType:
Debug.WriteLine("{0}: {1}", (PSConstants)key, action.GetInteger(key));
break;
case PsDescValueType.psStringType:
Debug.WriteLine("{0}: \"{1}\"", (PSConstants)key, action.GetString(key));
break;
case PsDescValueType.psBooleanType:
Debug.WriteLine("{0}: {1}", (PSConstants)key, action.GetBoolean(key));
break;
case PsDescValueType.psDoubleType:
Debug.WriteLine("{0}: {1}", (PSConstants)key, action.GetDouble(key));
break;
case PsDescValueType.psUnitDoubleType:
Debug.WriteLine("{0}: {1} {2}", (PSConstants)key, action.GetUnitDoubleValue(key), (PSConstants)action.GetUnitDoubleType(key));
break;
case PsDescValueType.psEnumeratedType:
Debug.WriteLine("{0}: {1} {2}", (PSConstants)key, (PSConstants)action.GetEnumerationType(key), (PSConstants)action.GetEnumerationValue(key));
break;
case PsDescValueType.psObjectType:
Debug.WriteLine($"{(PSConstants)key}: {(PSConstants)action.GetObjectType(key)} ");
Debug.Indent();
ActionPrinter(action.GetObjectValue(key));
Debug.Unindent();
break;
case PsDescValueType.psListType:
var list = action.GetList(key);
Debug.WriteLine($"{(PSConstants)key}: List of {list.Count} Items");
Debug.Indent();
for (int count = 0; count < list.Count; count++)
{
var type = list.GetType(count);
Debug.WriteLine($"{count}: {type} ");
Debug.Indent();
switch (type)
{
case PsDescValueType.psObjectType:
ActionPrinter(list.GetObjectValue(count));
break;
case PsDescValueType.psReferenceType:
var reference = list.GetReference(count);
Debug.WriteLine(" Reference to a {0}", (PSConstants)reference.GetDesiredClass());
break;
case PsDescValueType.psEnumeratedType:
Debug.WriteLine(" {0} {1}", (PSConstants)list.GetEnumerationType(count), (PSConstants)list.GetEnumerationValue(count));
break;
default:
Debug.WriteLine($"UNHANDLED LIST TYPE {type}");
break;
}
Debug.Unindent();
}
Debug.Unindent();
break;
default:
Debug.WriteLine($"{(PSConstants)key} UNHANDLED TYPE {action.GetType(key)}");
break;
}
}
}
}