如何在Javascript中创建圆形或椭圆形选区以便在Photoshop中使用?

时间:2016-02-05 23:18:47

标签: javascript photoshop ellipse photoshop-script

所以我的最终目标是在角落处创建4个圆形选择,但在浏览文档并多次搜索之后,我找不到除矩形选区之外的任何信息。我相信应该是一个解决方案,但我真的不能想到任何不涉及为一个圆圈设置大量边界像素位置的东西(我甚至不确定会工作,因为我对Photoshop脚本及其工作原理相当新。)

非常感谢!

1 个答案:

答案 0 :(得分:1)

Photoshop脚本API未完成,有时您会遇到尝试完成某些任务的困难。处理这个问题的一个很好的工具是Adobe自己的ScriptListener插件。需要一点时间来弄清楚它吐出的代码,但这将有助于填补脚本的漏洞。下面是我用来进行循环选择的函数:



function makeCircle(left,top,right,bottom,antiAlias){

var circleSelection = charIDToTypeID( "setd" );
    var descriptor = new ActionDescriptor();
    var id71 = charIDToTypeID( "null" );
        var ref5 = new ActionReference();
        var id72 = charIDToTypeID( "Chnl" );
        var id73 = charIDToTypeID( "fsel" );
        ref5.putProperty( id72, id73 );
    descriptor.putReference( id71, ref5 );
    var id74 = charIDToTypeID( "T   " );
        var desc12 = new ActionDescriptor();

        var top1 = charIDToTypeID( "Top " );
        var top2 = charIDToTypeID( "#Pxl" );
        desc12.putUnitDouble( top1, top2, top );

        var left1 = charIDToTypeID( "Left" );
        var left2 = charIDToTypeID( "#Pxl" );
        desc12.putUnitDouble( left1, left2, left );

        var bottom1 = charIDToTypeID( "Btom" );
        var bottom2 = charIDToTypeID( "#Pxl" );
        desc12.putUnitDouble( bottom1, bottom2, bottom );

        var right1 = charIDToTypeID( "Rght" );
        var right2 = charIDToTypeID( "#Pxl" );
        desc12.putUnitDouble( right1, right2, right );

    var id83 = charIDToTypeID( "Elps" );
    descriptor.putObject( id74, id83, desc12 );
    var id84 = charIDToTypeID( "AntA" );
    descriptor.putBoolean( id84, antiAlias );
executeAction( circleSelection, descriptor, DialogModes.NO );
}