Copy link to clipboard
Copied
Hi, y'all
There is a way to reach the command "Make/Release Clipping Mask" in the Layer window via script?
What I'm trying to achieve is to create a rectangle using the size of my artboard, name it "CLIP", put it on the top of my active Layer and set it as my mask.
Example bellow:
Any help will be appreciated.
Hi, check this:
.../* to make sure the desired layer(let's say layers[0]) been selected in the layers panel:
app.selection = null;
activeDocument.layers[0].hasSelectedArtwork = true;
*/
var actionStr =
'''
/name [ 1 73]
/actionCount 1
/action-1 {
/name [ 1 61]
/eventCount 1
/event-1 {
/internalName (ai_plugin_Layer)
/parameterCount 1
/parameter-1 {
/key 1836411236
/type (integer)
/value
Copy link to clipboard
Copied
Hi, check this:
/* to make sure the desired layer(let's say layers[0]) been selected in the layers panel:
app.selection = null;
activeDocument.layers[0].hasSelectedArtwork = true;
*/
var actionStr =
'''
/name [ 1 73]
/actionCount 1
/action-1 {
/name [ 1 61]
/eventCount 1
/event-1 {
/internalName (ai_plugin_Layer)
/parameterCount 1
/parameter-1 {
/key 1836411236
/type (integer)
/value 18
}
}
}
''';
createAction(actionStr, 's');
app.doScript('a', 's');
app.unloadAction('s', '');
function createAction(str, set) {
var f = File(set + '.aia');
f.open('w');
f.write(str);
f.close();
app.loadAction(f);
f.remove();
}
Copy link to clipboard
Copied
thank you very much. that totally solves my problem. ❤️
Copy link to clipboard
Copied
just one last question about it... how do you achieved the values in actions? there's a documentation of it? a way to "debug" the steps of actions? it would be very helpful on my learning curve.
Copy link to clipboard
Copied
No documentation an all. Just record the action manually in UI, export the action set, open it with a text editor and you will get it.(Note that my sample code had simplified the contents of the action string, it's not necessary.)
Copy link to clipboard
Copied
Great.
Your Script worked just fine in Illustrator running under Windows, but in Mac it didn't.
I will try to follow this steps in order to fix the problem on Mac.
Many thanks.
Copy link to clipboard
Copied
Sorry for raising this question again, but I can't make it work on mac.
Here my code based on the mac action:
// cria retangulo do tamanho do artboard
var win = new Window ('dialog',"Clip Artboard");
win.alignChildren = 'left';
win.spacing = 2;
var chk = win.add('checkbox',undefined,"Clip content?");
var aviso = win.add('panel');
aviso.alignChildren = 'left';
aviso.add('statictext',undefined,"This will create a rectangle to clip");
aviso.add('statictext',undefined,"the content in this layer based in artboard.");
var btns = win.add('group');
btns.alignChildren = 'center';
btns.margins = [0,10,0,0];
var ok = btns.add('button',undefined,"OK");
var cancel = btns.add('button',undefined,"Cancel");
var actionStr =
'''
/name [ 1 73]
/actionCount 1
/action-1 {
/name [ 1 61]
/eventCount 1
/event-1 {
/internalName (ai_plugin_Layer)
/parameterCount 1
/parameter-1 {
/key 1836411236
/type (integer)
/value 18
}
}
}
''';
cancel.onClick = function(){
win.close();
}
ok.onClick = function(){
draw(0,"CLIP");
if(chk.value == true){
createAction(actionStr, 's');
app.doScript('a', 's');
app.unloadAction('s', '');
}
win.close();
}
win.show();
function draw(bleed,name){
// create rectangle
var docRef = app.activeDocument;
var artboardRef = docRef.artboards;
for(i=0;i<artboardRef.length;i++){
var top=artboardRef.artboardRect[1];
var left=artboardRef.artboardRect[0];
var width=artboardRef.artboardRect[2]-artboardRef.artboardRect[0];
var height=artboardRef.artboardRect[1]-artboardRef.artboardRect[3];
var rect = docRef.pathItems.rectangle (top, left, width, height);
rect.fillColor = rect.strokeColor = new NoColor();
rect.name = name;
docRef.activeLayer.clipping = true;
}
//
}
//create action to clip content
function createAction(str, set) {
var f = File(set + '.aia');
f.open('w');
f.write(str);
f.close();
app.loadAction(f);
f.remove();
}
Copy link to clipboard
Copied
So what's the error info?
Copy link to clipboard
Copied
I bet it's not letting him write the file! Let's see.
Copy link to clipboard
Copied
I'm not in front of the mac right now, but the Error is something like "Wrong Version".
The script creates the rectangle named "CLIP", but it can't create the action that would clip the layer.
Silly-V : you suspect the problem could be about permissions?
Thanks in advance.
Copy link to clipboard
Copied
Oh , no I don't think that's the case - I just recorded my own action which does this and the very first line says "/version 3"
Maybe it's really necessary for Macs?
Copy link to clipboard
Copied
Even beggining with "/version 3" on top of the script it didn't worked.
Copy link to clipboard
Copied
So what is the exact text of the .aia you export manually from the Actions panel, for study?
Copy link to clipboard
Copied
/version 3
/name [ 4
6d696e65
]
/isOpen 1
/actionCount 1
/action-1 {
/name [ 4
434c4950
]
/keyIndex 0
/colorIndex 0
/isOpen 0
/eventCount 1
/event-1 {
/useRulersIn1stQuadrant 0
/internalName (ai_plugin_Layer)
/localizedName [ 5
4c61796572
]
/isOpen 1
/isOn 1
/hasDialog 0
/parameterCount 2
/parameter-1 {
/key 1836411236
/showInPalette 4294967295
/type (integer)
/value 18
}
/parameter-2 {
/key 1851878757
/showInPalette 4294967295
/type (ustring)
/value [ 26
4d616b652f52656c6561736520436c697070696e67204d61736b
]
}
}
}
Copy link to clipboard
Copied
So when you save this file manually, then load it in later, it works? If it works with manual usage, the same should work through a script as well.