-
The function stops working as soon as I put it in the UI button
Hi all. Tell me what I’m doing wrong. I want my smet() function to work via a button click. A window appears with the input of the number of masks, after pressing this number is inserted into the code and cuts the layer by this number of masks. By itself, the smet() function works correctly, but as soon as I paste it into a button, After Effects freezes.
var nW = new Window(“palette”,”Разрезы”,undefined);
var nSlice = nW.add("edittext",undefined,"");
var ok = nW.add("button",undefined, "Ok");
nW.size = [200,100];
nSlice.size = [50,20];
nW.show();
nW.center();
ok.onClick = function() {
var numSl = parseInt(nSlice.text)
smet();
nW.hide();
}
function smet(){
var comp = app.project.activeItem;
var selectedLayers = comp.selectedLayers[0];
var ind = selectedLayers.index;
var nm = selectedLayers.name;
var textSourceRect = selectedLayers.sourceRectAtTime(comp.time, false);
app.beginUndoGroup("123")
var preWidth = parseInt(textSourceRect.width);
var preHeight = parseInt(textSourceRect.height);
var selLPos = selectedLayers.property("Position").setValue([preWidth/2,preHeight/2]);
var precomp = comp.layers.precompose([ind], nm, true);
precomp.width = preWidth;
precomp.height = preHeight;
precomp.name = nm
for (var i=0; i<numSl-1;i++) {
var copy = app.executeCommand(app.findMenuCommandId("Duplicate"))
var down = app.executeCommand(app.findMenuCommandId("Send Layer Backward"))
}
var comp = app.project.activeItem
for (var i = 0; i<=numSl;i++){
var selM = comp.layer(i+1);
var newMask = selM.Masks.addProperty("ADBE Mask Atom");
newMask.maskMode = MaskMode.ADD;
var myProp = newMask.property("ADBE Mask Shape");
myShape = myProp.value
var hPos = preHeight/numSl
myShape.vertices = [[0,i*hPos],[preWidth,i*hPos],[preWidth,i*hPos+hPos],[0,i*hPos+hPos]]
myShape.closed = true;
myProp.setValue(myShape);
}
app.endUndoGroup();
}