my friend and i are trying to start an educational math channel, which explains math in Arabic via animation, But we're having problems writing a stacked fraction (where the numerator and the denominator are in different lines, separated by a horizontal line) I could write it by hand, but it's not efficient to repeat this process over and over.
I tried to use my little knowledge of coding to write a script that does it for me, but I'm facing a couple of problems, I couldn't fix them, i need help, either with the script or if you could guide me to an existent tool that would be great..
var mainWindow = new Window ("palette", "Fractions", undefined);
var numeratorGroup = mainWindow.add("group"); numeratorGroup.add ("statictext", undefined, "Numerator:"); var myNumerator = numeratorGroup.add ("edittext", undefined, "1"); myNumerator.characters = 45;
var denominatorGroup = mainWindow.add("group"); denominatorGroup.add ("statictext", undefined, "Denominator:"); var myDenominator = denominatorGroup.add ("edittext", undefined, "2"); myDenominator.characters = 45;
var buttonGroup = mainWindow.add("group");
var startButton = buttonGroup.add ("button", undefined, "Write me a fraction");
var cancelButton = buttonGroup.add ("button", undefined, "Cancel");
startButton.onClick = function(){ app.beginUndoGroup("Fractions"); mainFunc(); app.endUndoGroup("Fractions"); }
cancelButton.onClick = function(){ mainWindow.close()}
mainWindow.show();
function mainFunc(){
var mainComp = app.project.activeItem; var numerator = mainComp.layers.addText(myNumerator.text); var denominator = mainComp.layers.addText(myDenominator.text); centerAnchorPoint(numerator); centerAnchorPoint(denominator); var lineWidth = mainComp.layer(1).sourceRectAtTime(mainComp.time, true).width; var line =mainComp.layers.addShape(); var contents = line.property("ADBE Root Vectors Group"); var shapeRect = contents.addProperty("ADBE Vector Shape - Rect"); var shapeFill = contents.addProperty("ADBE Vector Graphic - Fill"); shapeRect = contents.property("ADBE Vector Shape - Rect"); var rectSize = shapeRect.property("ADBE Vector Rect Size"); var rectPosition = shapeRect.property("ADBE Vector Rect Position"); var rectRoundness = shapeRect.property("ADBE Vector Rect Roundness"); rectSize.expression = "x = Math.max(thisComp.layer(2).sourceRectAtTime().width,thisComp.layer(3).sourceRectAtTime().width); [x, 10]"; rectColor = [1,1,1]; rectRoundness.setValue(0); numerator.position.expression = "posX = Math.max(transform.position[0],thisComp.layer(2).transform.position[0]);posY = transform.position[1] - 64; [posX, posY]"; line.position.expression ="x1 = Math.abs(thisComp.layer(3).transform.position[0]-thisComp.layer(2).transform.position[0]); y1 = Math.abs(thisComp.layer(3).transform.position[1]-thisComp.layer(2).transform.position[1]);posX = Math.max(thisComp.layer(3).transform.position[0], thisComp.layer(2).transform.position[0]) + x1;posY = Math.min(thisComp.layer(3).transform.position[1], thisComp.layer(2).transform.position[1])+ y1/2;[posX, posY]"; denominator.position.expression = "posX = Math.max(transform.position[0],thisComp.layer(3).transform.position[0]);posY = transform.position[1] + 64; [posX, posY]"; mainWindow.close(); }
the code works okay, until i need to add another layer then every thing goes crazy + is there a way to group these objects together without precomposing them?
*the centerAnchorPoint function is not mine, i took it from a web search