forked from moluapple/ExtendScripts4AI-ID
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathID_makeClippingMask.jsx
46 lines (40 loc) · 1.4 KB
/
ID_makeClippingMask.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#targetengine 'MakeClipplingMask'
var mcmTitle = '建立剪切蒙版';
// 主进程
// -----------------------------------------------
function MCM() {
var oGroup = app.activeDocument.groups.add(app.selection),
clippingPath = oGroup.allPageItems[0].duplicate(oGroup.itemLayer);
clippingPath.bringToFront(oGroup);
oGroup.allPageItems[0].remove();
oGroup.select();
app.cut();
clippingPath.select();
app.pasteInto();
}
var mcmHandlers = {
'beforeDisplay' : function (ev) {
ev.target.enabled = (app.documents.length > 0 && app.selection.length > 1);
},
'onInvoke' : function () {
app.doScript(MCM.toSource() + '();', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.entireScript);
}
};
// 菜单创建
// -----------------------------------------------
var mcmMenuInstaller = mcmMenuInstaller ||
(function (mnuTitle, mnuHandlers) {
// 1. Create the script menu action
var mnuAction = app.scriptMenuActions.add(mnuTitle),
editMenu = app.menus.item('$ID/Main').submenus.item('$ID/&Edit'),
layoutMenu = app.menus[5],
ev;
// 2. Attach the event listener
for (ev in mnuHandlers) {
mnuAction.eventListeners.add(ev, mnuHandlers[ev]);
}
// 3. Create the menu item
editMenu.menuItems.add(mnuAction, LocationOptions.after, editMenu.menuItems.itemByID(274));
layoutMenu.menuItems.add(mnuAction, LocationOptions.after, layoutMenu.menuItems.itemByID(274));
return true;
})(mcmTitle, mcmHandlers);