论坛帮助 |
社区圈子 |
日历事件 |
2018-10-10, 14:06 | #1 | ||
|
|||
正式会员
等级: 三袋长老
|
var theSelect = doc.selection; var objGBCheck = false; //几何边界与可视边界 切换 //true //false if (theSelect.length > 0) { for (i = theSelect.length - 1; i > -1; i--) { var bound = NO_CLIP_BOUNDS(theSelect[i]); doc.artboards.add(bound);//转换为画板 }doc.artboards.remove(0); } else { alert("唉吆!\n必须先选择物件哦!!", "错误提示"); } 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]; } var GV_Bounds = objGBCheck ? "true": "false"; switch (GV_Bounds) { case "true": 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]; break; case "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]; break; } 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; } |
||
2018-10-10, 21:00 | 只看该作者 #4 | |||
|
||||
正式会员
等级: 四袋长老
|
引用:
具体偏移数值是否准确,可能需改变 var objGBCheck = false; 值的真假 代码:
var doc = app.activeDocument; var theSelect = doc.selection; var objGBCheck = false; //几何边界与可视边界 切换 //true //false var Offset = 7*(72/25.4);//偏移距离mm 负值加-符号 if (theSelect.length > 0) { for (i = theSelect.length - 1; i > -1; i--) { var bound = NO_CLIP_BOUNDS(theSelect[i]); doc.artboards.add(bound);//转换为画板 }doc.artboards.remove(0); } else { alert("唉吆!\n必须先选择物件哦!!", "错误提示"); } 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]- Offset; v_left[i] = NO_CLIP_OBJECTS_AND_MASKS[i].visibleBounds[0] - Offset; g_top[i] = NO_CLIP_OBJECTS_AND_MASKS[i].geometricBounds[1] + Offset; v_top[i] = NO_CLIP_OBJECTS_AND_MASKS[i].visibleBounds[1] + Offset; g_right[i] = NO_CLIP_OBJECTS_AND_MASKS[i].geometricBounds[2] + Offset; v_right[i] = NO_CLIP_OBJECTS_AND_MASKS[i].visibleBounds[2] + Offset; g_bottom[i] = NO_CLIP_OBJECTS_AND_MASKS[i].geometricBounds[3] - Offset; v_bottom[i] = NO_CLIP_OBJECTS_AND_MASKS[i].visibleBounds[3] - Offset; } var GV_Bounds = objGBCheck ? "true": "false"; switch (GV_Bounds) { case "true": 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]; break; case "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]; break; } 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; } 此帖于 2018-10-10 21:23 被 dhow 编辑. |
|||
右列会员因为此帖价值甚高向 dhow 表示感谢: |
栾绍帅 (2018-10-11)
|