/* AR_MasksToFusionPolygons Author: Arttu Rautio (aturtur) Website: http://aturtur.com/ Name-US: AR_MasksToFusionPolygons Description-US: Creates Fusion polygon nodes from selected layer's masks. Exports only path, not feather, opacity or expansion. Warning: 'Allow Script to Write Files and Access Network' has to be checked, since this script creates a file to temp folder. Written for Adobe After Effects CC 2019 (Version 16.0.1 Build 48) */ //@target aftereffects function rangeMap(value, minInput, maxInput, minOutput, maxOutput) { var remapped = (value - minInput) * (maxOutput - minOutput) / (maxInput - minInput) + minOutput return remapped } var comp = app.project.activeItem; var maskLayer = comp.selectedLayers[0]; var maskGroup = maskLayer.property("ADBE Mask Parade"); var frameRate = 1 / comp.frameDuration; var duration = (maskLayer.outPoint-maskLayer.inPoint)*frameRate; var width = comp.width; var height = comp.height; var pixelAspect = 1.0; var mask, maskPath, vertices; var tempFolder = Folder.temp.fsName; // Get temp folder path var theFile = new File(tempFolder+"\\createdFusionPolygons.txt"); // Create temp text file var re = new RegExp('[^0-9a-zA-Z_]+','g'); if (theFile != null) { // If there is file theFile.open("w","TEXT","????"); theFile.encoding = "UTF-8"; // Encode theFile.writeln("{"); theFile.writeln("\tTools = ordered() {"); for (var m=1; m<=maskGroup.numProperties; m++) { var mask, maskPath, vertices, maskName; for (var m=1; m<=maskGroup.numProperties; m++) { mask = maskGroup.property(m); maskName = mask.name; maskName = maskName.replace(re, '_'); maskPath = mask.property("ADBE Mask Shape"); theFile.writeln("\t\t"+maskName+" = PolylineMask {"); theFile.writeln("\t\t\tDrawMode = \"ModifyOnly\","); theFile.writeln("\t\t\tDrawMode2 = \"InsertAndModify\","); theFile.writeln("\t\t\tCtrlWZoom = false,"); theFile.writeln("\t\t\tInputs = {"); theFile.writeln("\t\t\t\tOutputSize = Input { Value = FuID { \"Custom\" }, },"); theFile.writeln("\t\t\t\tMaskWidth = Input { Value = "+width+", },"); theFile.writeln("\t\t\t\tMaskHeight = Input { Value = "+height+", },"); theFile.writeln("\t\t\t\tPixelAspect = Input { Value = { 1, 1 }, },"); theFile.writeln("\t\t\t\tClippingMode = Input { Value = FuID { \"None\" }, },"); theFile.writeln("\t\t\t\tPolyline = Input {"); theFile.writeln("\t\t\t\t\tSourceOp = \"Polygon"+m+"Polyline\","); theFile.writeln("\t\t\t\t\tSource = \"Value\","); theFile.writeln("\t\t\t\t},"); theFile.writeln("\t\t\t\tPolyline2 = Input {"); theFile.writeln("\t\t\t\t\tValue = Polyline {"); theFile.writeln("\t\t\t\t\t},"); theFile.writeln("\t\t\t\t\tDisabled = true,"); theFile.writeln("\t\t\t\t},"); theFile.writeln("\t\t\t},"); theFile.writeln("\t\t\tViewInfo = OperatorInfo { Pos = { 0, "+m*parseInt(50)+" } },"); theFile.writeln("\t\t},"); theFile.writeln("\t\tPolygon"+m+"Polyline = BezierSpline {"); theFile.writeln("\t\t\tSplineColor = { Red = 173, Green = 255, Blue = 47 },"); theFile.writeln("\t\t\tNameSet = true,"); theFile.writeln("\t\t\tKeyFrames = {"); for (var f=0; f