打印

[作品] 能重复执行N遍选定动作的脚本~~~ (2.22更新,修正了两个Bug)



一个单步的动作,用了这个脚本,就可以重复执行100遍1000遍。
上面就是一个路径描边100遍的效果,吼吼~ 不知道大家明白用处没有?

(以前老是困惑不停地去点动作,点个几十次来重复一个任务)




不容易啊。这次这个脚本前面的函数都是抄袭的,
一些是抄ps自带的脚本,
还有一个建立快照是这里的 http://www.ps-scripts.com/bb/vie ... ;highlight=snapshot 。感谢老外  


再次谢谢XYBLUEIDEA 斑竹和其他朋友的支持鼓励!

--------------- 应作者要求帮忙更新,修正如下:
1、当前没有打开文档的时候,不建立快照,避免因此出错。
2、原本执行次数为 N+1 次,这次作了修正。

                                                ------- mzbx8888字 2.22

[ 本帖最后由 mzbx8888 于 2008-2-22 09:08 编辑 ]
附件: 您所在的用户组无法下载或查看附件,您需要注册/登录后才能查看!
本帖最近评分记录
  • wonton 威望 +3 很实用~ 2008-3-8 09:41

贴出代码,方便指正优化~

操作对象:
任何录制好的动作;

操作结果:
对选定的动作,重复执行指定次数;(效果要靠动作本身实现)

用法:
把解压出来的 “执行N遍动作.jsx” 文件复制到 “ps安装目录\预置\脚本” 下,重新打开ps以后就可以在~
[菜单- 文件-脚本] 里面找到 “执行N遍动作”
或者解压出来,在开着ps的情况下,直接双击也可以用。

备注:
执行操作前可以先建立快照,如果对操作结果不满意,可以通过快照返回。
(不过如果是多个文件、保存关闭之类的操作就别选了,恐怕会出错
复制内容到剪贴板
代码:
#target photoshop
app.bringToFront();
// 重复执行N遍选中的动作
///////////////////////////////////////////////////////////////////////////////
// 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:'重复执行选定动作',\
        group: Group{orientation: 'column',alignChildren:'left',\
                corrdination: Panel { orientation: 'row', \
                        text: '选择动作', \
                                cla: Group { orientation: 'row', \
                                        d: DropDownList {  alignment:'left' },\
                                        }\
                                act: Group { orientation: 'row', \
                                        d: DropDownList {  alignment:'left' },\
                                        }\
                                },  \
                num: Group { orientation: 'row', \
                                    s: StaticText { text:'执行次数:' }, \
                                    e: EditText { preferredSize: [50, 20] } ,\
                                    }, \
                Snapshot:Group{ orientation: 'row', \
                                    c: Checkbox { preferredSize: [16, 16]} ,\
                                    s: StaticText {text:'建立快照(根据动作内容适当选择)'},\
                                    }, \
                },\
        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 ('-_-!!! 至少得运行一次吧?')
        win.group.num.e.text='1';
        g=1
    }else {
        var b=win.group.Snapshot.c.value;        
        if(b && app.documents.length) {CreateSnapshot(g+"遍动作执行前");} //安全起见,建立快照
        for(i=0;i<g;i++){
        doAction(ddAction.selection,ddSet.selection) //执行选择的动作
        }
        this.parent.parent.close();
    }
}
win.center();
win.show();
[ 本帖最后由 mzbx8888 于 2008-2-22 09:02 编辑 ]


有点理解

稍稍试了一下...
附件: 您所在的用户组无法下载或查看附件,您需要注册/登录后才能查看!

TOP

认证您的手机,获得手机认证图标, 更多手机认证的好处
很方便啊,对动作稍懂一点,对脚本是一窍不通.看那些代码好像看天书!
我行我素!
嘿嘿,恭喜你,第二个脚本又诞生了,测试OK
技术+创意+审美+细心=设计成功的法宝

TOP

谢谢大家,再来两个简单的例子,希望有所启发





实话说,几个调用的函数都看不大懂,尤其是那个建立快照,更是不知所云。唉 ~

[ 本帖最后由 xiexienila 于 2008-2-22 09:30 编辑 ]
附件: 您所在的用户组无法下载或查看附件,您需要注册/登录后才能查看!

TOP

非常不错的东东,收藏了。谢谢楼主。
溜溜拍:66pai.net

TOP

这个好东西 要感谢楼主! 顺便100遍啊100遍。。。
前略,这是一个密码:fg684p

TOP

提示说cs3才能用

TOP

看着很不错,我也装进去了,为什么提示说错误呢

TOP

  可能只有高版本的才能用吧

TOP

怎么能做出渐变的描边的效果呢,自己琢磨半天也弄不出来

TOP

在PS7.0中找不到预置\ 脚本。
通常情况下做一个动作后,按一下只能执行一次动作。如果没有脚本的情况下,可把动作复制N个选定后执行。一个笨办法!

TOP

回复 #13 yangning 的帖子

7.0 据说也不能用这个脚本
发帖前请搜索,回帖前请仔细看清楼上每一层。大家的批评意见要虚心接受。有错误要积极承认。 论坛的交流气氛要和谐!内容重复和无实际意义的帖子要少发。

TOP

我太崇拜你了!

TOP

怎么会提示错误啊?

TOP

楼主您太牛了,小弟领教了.

TOP

太牛了,我可能暂时还学不会

TOP

pS越来越强大了
因为专业,所以选择..技术群:11162579

TOP