文章目录
- 1.简介
- 2.动作相关概念
- 2.1.ActionDescriptor
- 2.2.ActionList
- 2.3.ActionReference
- 3.范例
- 3.1.加载动作
- 3.2.执行动作
- 3.3.非加载执行动作文件中动作
- 3.4.删除动作集
- 3.5.删除动作
- 4.作者寄语
1.简介
PS动作是什么?是一组操作步骤的组合,多个步骤集合成一两步操作完成复杂的操作。在PS内,是通过动作面板进行管理,录制,编辑,加载和执行。如下图所示:
2.动作相关概念
2.1.ActionDescriptor
该对象提供了一种字典式的机制,用于将数据存储为键值对。 它可用于对 Photoshop 的低级访问。许多配置文件使用序列化操作描述符来表示其数据。 例如,用于在 Application.playbackParameters 中封装播放选项,并由Application.getCustomOptions()。
2.2.ActionList
该对象提供了一种用于存储数据的数组式机制。 它可用于对 Photoshop 的低级访问。当存储相同类型的数据时,这个对象是理想的。 列表中的所有项目必须属于同一类型。 您可以使用诸如 putBoolean() 之类的“put”方法来附加新元素,并且可以使用 clear() 清除整个列表,但不能以其他方式修改列表。注意:ActionList 对象是 Action Manager 功能的一部分。 有关使用动作管理器的详细信息,请参阅 Photoshop CC 脚本指南。
2.3.ActionReference
此对象提供有关操作所指内容的信息。 例如,当提到某物的名称时,您可能会使用 keyName。 引用还需要知道您指的是什么名称。 在这种情况下,您可以使用 classDocument 作为文档名称或使用 classLayer 作为图层名称。 它可用于对 Photoshop 的低级访问。包含与 ActionDescriptor 关联的数据。
3.范例
3.1.加载动作
将动作文件加载至面板,代码如下所示:
app.load(File("C:\\2.atn"));
3.2.执行动作
调用函数执行对应组和对应名称函数,代码如下所示:
play_action("默认动作", "四分颜色");
//play_action("默认动作", "四分颜色") // Perform the whole action// 执行整个动作
//play_action("默认动作", "四分颜色", 4, true) // Complete all from the beginning of the command number 4// 从命令编号4 的开头全部完成
//play_action("默认动作", "四分颜色", 5, false) // Will execute only command number 5// 仅执行命令编号5
//cmd_number - the index of the command, ( starts from 1 )
function play_action(set, action, cmd_number, allow_continue)
{try{var d = new ActionDescriptor();var r = new ActionReference();if (typeof(cmd_number) == "number") r.putIndex( charIDToTypeID( "Cmnd" ), cmd_number );r.putName( charIDToTypeID( "Actn" ), action );r.putName( charIDToTypeID( "ASet" ), set );d.putReference( charIDToTypeID( "null" ), r );if (typeof(allow_continue) == "boolean") d.putBoolean( charIDToTypeID( "Cntn" ), allow_continue );executeAction( charIDToTypeID( "Ply " ), d, DialogModes.NO );}catch(e){alert(e);}
}
3.3.非加载执行动作文件中动作
通过非加载方式,执行动作文件中的动作,代码流程较长,有专门博文介绍。https://anjingzhi.blog.csdn.net/article/details/121544253
3.4.删除动作集
通过名称删除动作集。代码如下:
delete_actionset("组 1");
function delete_actionset(set)
{try{var idDlt = charIDToTypeID( "Dlt " );var desc24 = new ActionDescriptor();var idnull = charIDToTypeID( "null" );var ref5 = new ActionReference();var idASet = charIDToTypeID( "ASet" );ref5.putName( idASet, set );desc24.putReference( idnull, ref5 );executeAction( idDlt, desc24, DialogModes.NO );}catch(e){alert(e);}
}
3.5.删除动作
通过动作集和动作名称删除动作。代码如下:
delete_action("组 1","动作 1");
function delete_action(set,action)
{try{var idDlt = charIDToTypeID( "Dlt " );var desc6 = new ActionDescriptor();var idnull = charIDToTypeID( "null" );var ref3 = new ActionReference();var idActn = charIDToTypeID( "Actn" );ref3.putName( idActn, action );var idASet = charIDToTypeID( "ASet" );ref3.putName( idASet, set);desc6.putReference( idnull, ref3 );executeAction( idDlt, desc6, DialogModes.NO );}catch(e){alert(e);}
}
4.作者寄语
合理的脚本代码可以有效的提高工作效率,减少重复劳动。