PS中執(zhí)行N遍選定動(dòng)作的腳本

一個(gè)單步的動(dòng)作,用了這個(gè)腳本,就可以重復(fù)執(zhí)行100遍1000遍。
上面就是一個(gè)路徑描邊100遍的效果,吼吼~ 不知道大家明白用處沒(méi)有?(以前老是困惑不停地去點(diǎn)動(dòng)作,點(diǎn)個(gè)幾十次來(lái)重復(fù)一個(gè)任務(wù))

不容易啊。這次這個(gè)腳本前面的函數(shù)都是抄襲的,一些是抄ps自帶的腳本,還有一個(gè)建立快照是這里的:http://www.ps-scripts.com/bb/vie ... ;highlight=snapshot 感謝老外。再次謝謝XYBLUEIDEA 斑竹和其他朋友的支持鼓勵(lì)!
貼出代碼,方便指正優(yōu)化
操作對(duì)象:
任何錄制好的動(dòng)作;
操作結(jié)果:
對(duì)選定的動(dòng)作,重復(fù)執(zhí)行指定次數(shù);(效果要靠動(dòng)作本身實(shí)現(xiàn))
用法:
把解壓出來(lái)的 “執(zhí)行N遍動(dòng)作.jsx” 文件復(fù)制到 “ps安裝目錄\預(yù)置\腳本” 下,重新打開(kāi)ps以后就可以在~
[菜單- 文件-腳本] 里面找到 “執(zhí)行N遍動(dòng)作”
或者解壓出來(lái),在開(kāi)著ps的情況下,直接雙擊也可以用。
備注:
執(zhí)行操作前可以先建立快照,如果對(duì)操作結(jié)果不滿意,可以通過(guò)快照返回。
(不過(guò)如果是多個(gè)文件、保存關(guān)閉之類的操作就別選了,恐怕會(huì)出錯(cuò) )
#target photoshop
app.bringToFront();
// 重復(fù)執(zhí)行N遍選中的動(dòng)作
/////////////////////////////////////////////////////////////////////
// Function: GlobalVariables
// Usage: global action items that are reused
// Input: <none>
// Return: <none>
/////////////////////////////////////////////////////////////////////
function GlobalVariables() {
gClassActionSet = charIDToTypeID( 'ASet' );
gClassAction = charIDToTypeID( 'Actn' );
gKeyName = charIDToTypeID( 'Nm ' );
gKeyNumberOfChildren = charIDToTypeID( 'NmbC' );
}
/////////////////////////////////////////////////////////////////////
// Function: GetActionSetInfo
// Usage: walk all the items in the action palette and record the action set
// names and all the action children
// Input: <none>
// Return: the array of all the ActionData
// Note: This will throw an error during a normal execution. There is a bug
// in Photoshop that makes it impossible to get an acurate count of the number
// of action sets.
/////////////////////////////////////////////////////////////////////
function GetActionSetInfo() {
var actionSetInfo = new Array();
var setCounter = 1;
while ( true ) {
var ref = new ActionReference();
ref.putIndex( gClassActionSet, setCounter );
var desc = undefined;
try { desc = executeActionGet( ref ); }
catch( e ) { break; }
var actionData = new ActionData();
if ( desc.hasKey( gKeyName ) ) {
actionData.name = desc.getString( gKeyName );
}
var numberChildren = 0;
if ( desc.hasKey( gKeyNumberOfChildren ) ) {
numberChildren = desc.getInteger( gKeyNumberOfChildren );
}
if ( numberChildren ) {
actionData.children = GetActionInfo( setCounter, numberChildren );
actionSetInfo.push( actionData );
}
setCounter++;
}
return actionSetInfo;
}
/////////////////////////////////////////////////////////////////////
// Function: GetActionInfo
// Usage: used when walking through all the actions in the action set
// Input: action set index, number of actions in this action set
// Return: true or false, true if file or folder is to be displayed
/////////////////////////////////////////////////////////////////////
function GetActionInfo( setIndex, numChildren ) {
var actionInfo = new Array();
for ( var i = 1; i <= numChildren; i++ ) {
var ref = new ActionReference();
ref.putIndex( gClassAction, i );
ref.putIndex( gClassActionSet, setIndex );
var desc = undefined;
desc = executeActionGet( ref );
var actionData = new ActionData();
if ( desc.hasKey( gKeyName ) ) {
actionData.name = desc.getString( gKeyName );
}
var numberChildren = 0;
if ( desc.hasKey( gKeyNumberOfChildren ) ) {
numberChildren = desc.getInteger( gKeyNumberOfChildren );
}
actionInfo.push( actionData );
}
return actionInfo;
}
/////////////////////////////////////////////////////////////////////
// Function: ActionData
// Usage: this could be an action set or an action
// Input: <none>
// Return: a new Object of ActionData
/////////////////////////////////////////////////////////////////////
function ActionData() {
this.name = "";
this.children = undefined;
this.toString = function () {
var strTemp = this.name;
if ( undefined != this.children ) {
for ( var i = 0; i < this.children.length; i++ ) {
strTemp += " " + this.children[i].toString();
}
}
return strTemp;
}
}
//////////
function CreateSnapshot(name) {
function cTID(s) { return app.charIDToTypeID(s); };
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( cTID('SnpS') );
desc.putReference( cTID('null'), ref );
var ref1 = new ActionReference();
ref1.putProperty( cTID('HstS'), cTID('CrnH') );
desc.putReference( cTID('From'), ref1 );
desc.putString( cTID('Nm '), name);
desc.putEnumerated( cTID('Usng'), cTID('HstS'), cTID('FllD') );
executeAction( cTID('Mk '), desc, DialogModes.NO );
}
//////////
res ="dialog { \
text:'重復(fù)執(zhí)行選定動(dòng)作',\
group: Group{orientation: 'column',alignChildren:'left',\
corrdination: Panel { orientation: 'row', \
text: '選擇動(dòng)作', \
cla: Group { orientation: 'row', \
d: DropDownList { alignment:'left' },\
}\
act: Group { orientation: 'row', \
d: DropDownList { alignment:'left' },\
}\
}, \
num: Group { orientation: 'row', \
s: StaticText { text:'執(zhí)行次數(shù):' }, \
e: EditText { preferredSize: [50, 20] } ,\
}, \
Snapshot:Group{ orientation: 'row', \
c: Checkbox { preferredSize: [16, 16]} ,\
s: StaticText {text:'建立快照(根據(jù)動(dòng)作內(nèi)容適當(dāng)選擇)'},\
}, \
},\
buttons: Group { orientation: 'row', alignment: 'right',\
Btnok: Button { text:'確定', properties:{name:'ok'} }, \
Btncancel: Button { text:'取消', properties:{name:'cancel'} } \
} \
}";
win = new Window (res);
GlobalVariables();
var actionInfo = GetActionSetInfo();
var ddSet=win.group.corrdination.cla.d;
var ddAction=win.group.corrdination.act.d;
if ( actionInfo.length > 0 ) {
for ( var i = 0; i < actionInfo.length; i++ ) {
ddSet.add( "item", actionInfo[i].name );
}
ddSet.items[0].selected = true;
ddSet.onChange = function() {
ddAction.removeAll();
for ( var i = 0; i < actionInfo[ this.selection.index ].children.length; i++ ) {
ddAction.add( "item", actionInfo[ this.selection.index ].children[ i ].name );
}
if ( ddAction.items.length > 0 ) {
ddAction.items[0].selected = true;
}
ddSet.helpTip = ddSet.items[ ddSet.selection.index ].toString();
}
ddSet.onChange();
} else {
ddSet.enabled = false;
ddAction.enabled = false;
}
ddAction.onChange = function() {
ddAction.helpTip = ddAction.items[ ddAction.selection.index ].toString();
}
win.buttons.Btncancel.onClick = function () {
this.parent.parent.close();
}
win.buttons.Btnok.onClick = function () {
g=Number(win.group.num.e.text);
if(g<1){
alert ('-_-!!! 至少得運(yùn)行一次吧?')
win.group.num.e.text='1';
g=1
}else {
var b=win.group.Snapshot.c.value;
if(b && app.documents.length) {CreateSnapshot(g+"遍動(dòng)作執(zhí)行前");} //安全起見(jiàn),建立快照
for(i=0;i<g;i++){
doAction(ddAction.selection,ddSet.selection) //執(zhí)行選擇的動(dòng)作
}
this.parent.parent.close();
}
}
win.center();
win.show();
相關(guān)文章
PS不能完成命令,因?yàn)闆](méi)有足夠內(nèi)存(RAM)的解決方案
photoshop無(wú)疑是一款非常好用的圖像編輯軟件,對(duì)于電腦小白來(lái)說(shuō)操作非常困難,比如提示“不能完成命令,因?yàn)闆](méi)有足夠內(nèi)存(RAM)”要怎么辦呢?下面就來(lái)看看小編為大家提供2025-05-16
縱享絲滑的修圖體驗(yàn)! 10個(gè)Photoshop性能優(yōu)化小技巧
ps提供了豐富的自定義選項(xiàng),只要根據(jù)你的硬件配置和項(xiàng)目需求,合理調(diào)整內(nèi)存、緩存等核心參數(shù),只要幾個(gè)小步驟,小白用戶也能讓運(yùn)行效率加倍2025-04-24
psd文件用什么打開(kāi)? 沒(méi)有Photoshop的情況下打開(kāi)psd文件的四種方法
收到了psd文件,但是電腦沒(méi)有安裝ps,該怎么解決這個(gè)問(wèn)題呢?下面我們就來(lái)看看這個(gè)問(wèn)題的解決辦法2025-05-07
ps一直閃退是什么原因? Photoshop閃退原因及解決方案
在使用過(guò)程中,Photoshop總是會(huì)無(wú)緣無(wú)故地自動(dòng)退出,這不僅打斷了工作流程,還可能導(dǎo)致未保存的更改丟失,令人頭疼不已,本文將深入剖析Photoshop自動(dòng)退出的原因,并提供相2024-07-04
怎么優(yōu)化PSD文件? 有效防止Photoshop崩潰卡死的技巧奧
明就幾個(gè)圖層,并沒(méi)有引入什么大型圖片,但是 PSD 文件卻異常巨大,而且用起來(lái)經(jīng)??D?下面我們就來(lái)看看pds文件優(yōu)化方法2024-05-25
將多個(gè)圖層合并為一個(gè)圖層,但作為設(shè)計(jì)師你需要了解一下合并圖層是有破壞性的,下面我們就來(lái)詳細(xì)介紹一下2024-05-25
通常是因?yàn)镻hotoshop使用的暫存盤空間不足,導(dǎo)致無(wú)法正常工作,那么,如何解決這一問(wèn)題呢?本文將為您提供詳細(xì)的解決方案2024-05-25
PS存儲(chǔ)和存儲(chǔ)為有什么區(qū)別? 理解存儲(chǔ)與存儲(chǔ)為的重要性
ps導(dǎo)出文件的時(shí)候,可以直接存儲(chǔ),也可以另存存儲(chǔ)為,這兩個(gè)操作有區(qū)別嗎?新手該怎么保存文件呢?詳細(xì)請(qǐng)看下文介紹2024-03-28
ps beta ai顯示高峰需求進(jìn)不去怎么辦? psai高峰期需求用不了解決辦法
PSBetaAI2023加入了AI的功能,在使用過(guò)程中,有時(shí)會(huì)遇到一個(gè)令人煩惱的問(wèn)題,那就是PhotoshopBetaAI提示我們正在面臨高峰需求,請(qǐng)稍候再試,針對(duì)這個(gè)問(wèn)題,本文為大家整理2024-03-28
ps段落兩端對(duì)齊不能用怎么辦? ps文字排版不能對(duì)齊的修復(fù)技巧
PS進(jìn)行設(shè)計(jì)時(shí),段落兩端對(duì)齊是一個(gè)常用的排版功能,它能讓文本看起來(lái)更加整潔和專業(yè),然而,許多用戶在使用PS時(shí)可能會(huì)遇到一個(gè)令人頭疼的問(wèn)題:段落兩端對(duì)齊功能似乎不起作2024-03-09







