te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - How to select active layer? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to select active layer? - Stack Overflow

programmeradmin4浏览0评论

It appears that in order to resize the layer it has to be selected(from UI perspective) and active from API perspective. Otherwise I get error on any function call that this function is not supported.

So before resizing I do

var a = doc.artLayers.getByName("iPad");
app.activeDocument.activeLayer = a;

This doesn't visually change selected layer hence calling resize function fails after that. The only way to get it work, manually click on layer(any layer), then it works. What is the proper way to resize layer without user interaction?

It appears that in order to resize the layer it has to be selected(from UI perspective) and active from API perspective. Otherwise I get error on any function call that this function is not supported.

So before resizing I do

var a = doc.artLayers.getByName("iPad");
app.activeDocument.activeLayer = a;

This doesn't visually change selected layer hence calling resize function fails after that. The only way to get it work, manually click on layer(any layer), then it works. What is the proper way to resize layer without user interaction?

Share Improve this question asked Mar 9, 2013 at 15:16 PabloPablo 29.5k37 gold badges134 silver badges225 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

You just need to amend your code:

var doc = app.activeDocument;
doc.activeLayer = doc.artLayers.getByName("iPad");

This will set the active layer to the one named "ipad". This is a standard way of selecting a layer (by name) to then further process the image, in your case resizing it. Obviously I don't know what else in in the PSD in terms of layers to pick or ignore. Another way would be to iterate through all layers and process them all.

Here are two useful functions: One will select the layer mask is there is one, the other will deselect the layer mask and go back to the bitmap layer

// FUNCTION DESELECT LAYER MASK AND SELECT IMAGE LAYER
// --------------------------------------------------------
function deselectLayerMaskAndSelectImageLayer()
{
  // =======================================================
  var id248 = charIDToTypeID( "slct" );
  var desc48 = new ActionDescriptor();
  var id249 = charIDToTypeID( "null" );
  var ref36 = new ActionReference();
  var id250 = charIDToTypeID( "Chnl" );
  var id251 = charIDToTypeID( "Chnl" );
  var id252 = charIDToTypeID( "RGB " );
  ref36.putEnumerated( id250, id251, id252 );
  desc48.putReference( id249, ref36 );
  var id253 = charIDToTypeID( "MkVs" );
  desc48.putBoolean( id253, false );
  executeAction( id248, desc48, DialogModes.NO );
}


// FUNCTION SELECT MASK
// --------------------------------------------------------
function selectMask(LayerName)
{
  try
  {
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Msk ') );
    ref.putName( charIDToTypeID('Lyr '), LayerName );
    desc.putReference( charIDToTypeID('null'), ref );
    desc.putBoolean( charIDToTypeID('MkVs'), true );
    executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );

    // =======================================================
    var id1083 = charIDToTypeID( "setd" );
    var desc238 = new ActionDescriptor();
    var id1084 = charIDToTypeID( "null" );
    var ref161 = new ActionReference();
    var id1085 = charIDToTypeID( "Chnl" );
    var id1086 = charIDToTypeID( "fsel" );
    ref161.putProperty( id1085, id1086 );
    desc238.putReference( id1084, ref161 );
    var id1087 = charIDToTypeID( "T   " );
    var ref162 = new ActionReference();
    var id1088 = charIDToTypeID( "Chnl" );
    var id1089 = charIDToTypeID( "Ordn" );
    var id1090 = charIDToTypeID( "Trgt" );
    ref162.putEnumerated( id1088, id1089, id1090 );
    desc238.putReference( id1087, ref162 );
    executeAction( id1083, desc238, DialogModes.NO );
  }
  catch(e)
  {
  //alert(e)
  //alert( "This layer has NO layer mask!" );
  activeDocument.selection.deselect();
  }
} //end function

You can find it in the Data Browser view from extendscript:

var doc = app.activeDocument;

// set active layer
doc.activeLayer = doc.layers.getByName("Layer Name Here");
发布评论

评论列表(0)

  1. 暂无评论