• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Stacked Fractions

New Here ,
Jan 11, 2019 Jan 11, 2019

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

506

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2019 Jan 11, 2019

Copy link to clipboard

Copied

Are you sure you want this in the After Effects forum? Here is a link to After Effects Scripting forum which I believe is more suitable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2019 Jan 11, 2019

Copy link to clipboard

Copied

LATEST

Thanks, I'm going to ask them too, but i'm not sure if there was an existing tool that does that for me, I think it would be better if there was.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines