Rounded Rectangle Mask via Scripting
Hey Guys,
I am creating a script that applies a round rectangle mask to any layer that is selected. I have written the following code.
My question is, how do I make the vertices scale correctly to the size of any given comp? For example the code below has the vertices hard coded for a compostion of 1920x1080. How can I make this dynamic so it would work the same on an 8k comp for example.
Thanks,
Liam
btnMaskRoudRect.onClick = function() {
if(app.project.activeItem == undefined || app.project.activeItem == null) {
alert("Please Select a Composition.");
return false;
}
if(app.project.activeItem.selectedLayers.length < 1) {
alert("Please Select a Layer.");
}
else {
maskRoudRect(app.project.activeItem.selectedLayers);
}
function maskRoudRect() {
for(var i = 0; i < app.project.activeItem.selectedLayers.length; i++) {
app.beginUndoGroup("Undo Rounded Rectangle Mask");
myLayer = app.project.activeItem.selectedLayers[i];
comp = app.project.activeItem;
newMask = myLayer.Masks.addProperty("ADBE Mask Atom");
newMask.maskMode = MaskMode.ADD;
myProperty = newMask.property("ADBE Mask Shape");
myShape = myProperty.value;
myShape.vertices = [[1900, 0],[20, 0],[0, 20],[0, 1060],[20, 1080],[1900, 1080],[1920, 1060],[1920, 20]];
myShape.inTangents = [[11.045654296875,0],[0,0],[0,-11.457153320312],[0,0],[-11.457153320312,0],[0,0],[0,11.045654296875],[0,0]];
myShape.outTangents = [[0,0],[-11.457153320312,0],[0,0],[0,11.045654296875],[0,0],[11.045654296875,0],[0,0],[0,-11.457153320312]];
myShape.closed = true;
myProperty.setValue(myShape);
app.endUndoGroup();
}
}
