论坛帮助 |
社区圈子 |
日历事件 |
2021-01-04, 12:57 | #1 | ||
|
|||
正式会员
等级: 六袋长老
|
var doc=app.activeDocument; var items=doc.selection; var i = items.length; var nodes = selection[0]; while (i--) { var item = items[i]; var node = nodes.duplicate(item, ElementPlacement.PLACEBEFORE); var bound = NO_CLIP_BOUNDS(item); it_left=bound[0]; it_top=bound[1]; it_width=bound[2]-bound[0]; it_height=bound[1]-bound[3]; var n_bound = NO_CLIP_BOUNDS(node); nd_left=n_bound[0]; nd_top=n_bound[1]; nd_width=n_bound[2]-n_bound[0]; nd_height=n_bound[1]-n_bound[3]; node.top = it_top + (nd_height - it_height) / 2; node.left = it_left - (nd_width - it_width) / 2; } function NO_CLIP_BOUNDS(the_obj) {//蒙版支持 var NO_CLIP_OBJECTS_AND_MASKS = new Array(); GET_NO_CLIP_OBJECTS_AND_MASKS(the_obj); var v_left = new Array(); var g_left = new Array(); var v_top = new Array(); var g_top = new Array(); var v_right = new Array(); var g_right = new Array(); var v_bottom = new Array(); var g_bottom = new Array(); for (var i = 0; i < NO_CLIP_OBJECTS_AND_MASKS.length; i += 1) { g_left[i] = NO_CLIP_OBJECTS_AND_MASKS[i].geometricBounds[0]; v_left[i] = NO_CLIP_OBJECTS_AND_MASKS[i].visibleBounds[0]; g_top[i] = NO_CLIP_OBJECTS_AND_MASKS[i].geometricBounds[1]; v_top[i] = NO_CLIP_OBJECTS_AND_MASKS[i].visibleBounds[1]; g_right[i] = NO_CLIP_OBJECTS_AND_MASKS[i].geometricBounds[2]; v_right[i] = NO_CLIP_OBJECTS_AND_MASKS[i].visibleBounds[2]; g_bottom[i] = NO_CLIP_OBJECTS_AND_MASKS[i].geometricBounds[3]; v_bottom[i] = NO_CLIP_OBJECTS_AND_MASKS[i].visibleBounds[3]; } //if (ignoreStroke.value == false){//可视边界 // var v_L = MIN_IN_ARRAY(v_left); // var v_T = MAX_IN_ARRAY(v_top); // var v_R = MAX_IN_ARRAY(v_right); // var v_B = MIN_IN_ARRAY(v_bottom); // return [v_L, v_T, v_R, v_B]; //} else { var g_L = MIN_IN_ARRAY(g_left); var g_T = MAX_IN_ARRAY(g_top); var g_R = MAX_IN_ARRAY(g_right); var g_B = MIN_IN_ARRAY(g_bottom); return [g_L, g_T, g_R, g_B]; //} function GET_NO_CLIP_OBJECTS_AND_MASKS(the_obj) { if (IS_CLIP(the_obj)) { NO_CLIP_OBJECTS_AND_MASKS.push(the_obj.pageItems[0]); return; } if (the_obj.constructor.name == "GroupItem") { try { var N_sub_obj = the_obj.pageItems.length; for (var i = 0; i < N_sub_obj; i += 1) { GET_NO_CLIP_OBJECTS_AND_MASKS(the_obj.pageItems[i]); } } catch(error) { } return; } NO_CLIP_OBJECTS_AND_MASKS.push(the_obj); return; } } function IS_CLIP(the_obj) { try { if (the_obj.constructor.name == "GroupItem") { if (the_obj.clipped) { return true; } } } catch(error) { } return false; } function MAX_IN_ARRAY(the_array) { var MAX = the_array[0]; for (var i = 0; i < the_array.length; i += 1) { if (the_array[i] > MAX) { MAX = the_array[i] } } return MAX; } function MIN_IN_ARRAY(the_array) { var MIN = the_array[0]; for (var i = 0; i < the_array.length; i += 1) { if (the_array[i] < MIN) { MIN = the_array[i] } } return MIN; } 奇怪在于,alert显示其中的node.top、node.left值(即替换对象后的xy值)又是正确的,如果用和蒙版一样大小的普通对象,替换后也是正确的。有懂jsx脚本的大神知道如何解决吗? |
||