Skip navigation
Currently Being Moderated

Is there is any automated way to make fraction.

Jul 17, 2012 4:54 AM

Hi all,

 

We just got a project which has lots of (1/2, 1/20, 1/300) etc.., the requirement is to change it to fraction.

 

Picture-2.gif

Any script is available to convert 1/2 to Division/Fraction.

 

Shaji

 
Replies
  • Currently Being Moderated
    Jul 17, 2012 9:32 AM   in reply to M V SHAJI

    Hi Shaji,

     

    I am a fresher  in script. But i try to give idea.

     

     

    Can you know how many elements will come like (1/2, 1/20, 1/300, 1/4, 1/8 etc..)

     

    If you know means:

     

    1. using Glyps  findout all the occurences

     

    2. Put all your output requirement Division/Fraction for 1/2, 1/20 etc fix in the library elements (i think its around 10 occurences only)

     

     

    I hope below script will help you. I didn't check it. Can you edit depends upon your requirement.

     

     

    var myDoc = app.documents[0];

    var myLib = app.libraries[0];

    app.findGlypsPreferences = NothingEnum.nothing;

    app.changeGlypsPreferences = NothingEnum.nothing;

     

    app.findTextPreferences.findGlyps = "1/2 or give unicode value";

    app.changeTextPreferences.changeTo = "";

    anchoricons("1/2 lib name", "1/2 obj style");

    app.documents.item(0).changeText();

     

    function anchoricons(libName, objStyle)

    {

        myFind = myDoc.findText(true);

        var myCount=0;

        for (i=0; i<myFind.length; i++)

        {

            myText = myLib.assets.item (libName).placeAsset (myFind[i].insertionPoints[-1])[0];

            myText.appliedObjectStyle = myDoc.objectStyles.item (objStyle);

            myCount++;

        }

     

    }

     

     

    Screen Shot 2012-07-17 at 10.00.34 PM.png

     

    3. its same like find and replace

     

    Can you check it shaaji?

     

    Thanks

    Learner_X

     
    |
    Mark as:
  • Techi Panda
    207 posts
    Apr 5, 2009
    Currently Being Moderated
    Jul 18, 2012 5:57 AM   in reply to M V SHAJI
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 18, 2012 2:34 PM   in reply to M V SHAJI

    Maybe you should first explain how you are making these nut fractions manually (as they are commonly known). Then someone might be able to help you automate it.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 19, 2012 5:36 AM   in reply to M V SHAJI

    Hi,

     

    this is a roughly approach scripting what you do manually.

    table-, cell-, and objectstyles must exist! tables aren't allowed to have left or right strokes.

     

    First a Grep-Search for 'Number(s) + Slash + Number(s)' is startet.

    ->anchored Textframe is inserted at insertionpoint 0 of searchresult (the objectstyle is mostly for applying your anchored settings)

    -> searchresult moved into tf

    ->converted to table

     

    This works in my little test, but there'll be plenty of circumstances it'll won't work as inspected  ...

     

    Happy testing ;-)

     

    var theDoc = app.activeDocument;

     

    var myTableStyle = "tableStyle"; //MUST  be set!!

    var myCellStyle = "cellStyle"//MUST  be set!!

    var myObjectStyle = "objectStyle"//MUST  be set!!

     

    app.findGrepPreferences = null;  

    app.findGrepPreferences.findWhat = "\\d+/\\d+";   //should find all occurrences of number(s) + / + numbers(s)

    var searchResults = theDoc.findGrep();  

     

    for(var i = searchResults.length -1; i >= 0; i--)

    {

    var foundFraction = searchResults[i];

    var newTextFrame = foundFraction.insertionPoints[0].textFrames.add({geometricBounds: [0,0,foundFraction.leading, foundFraction.parentTextFrames[0].geometricBounds[3] - foundFraction.parentTextFrames[0].geometricBounds[1]], appliedObjectStyle:theDoc.objectStyles.itemByName(myObjectStyle)});

    var tmpDest = foundFraction.move(LocationOptions.AT_BEGINNING, newTextFrame);

    var fractionTable= tmpDest.convertToTable('\r', '/', 1);

    fractionTable.appliedTableStyle = "tableStyle"

    setTableWidth(fractionTable);

    newTextFrame.fit(FitOptions.FRAME_TO_CONTENT);

            }

     

    function setTableWidth(fractionTable){

        var widthArray = [];

            var allCells = fractionTable.cells;

       for(var c = 0; c < fractionTable.cells.length; c++){

            var aCell = fractionTable.cells[c];

                    aCell.appliedCellStyle = "cellStyle"

    widthArray.push((aCell.texts[0].endHorizontalOffset - aCell.texts[0].horizontalOffset) + aCell.leftInset + aCell.rightInset)

        }

    widthArray.sort(Numsort);

    fractionTable.width = widthArray[widthArray.length-1]

    }

     

    function Numsort(a,b){return a - b}

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 19, 2012 6:41 AM   in reply to M V SHAJI

    ScreenShot043.pngScreenShot044.png

    It's easy to script

     

    one needs to set up 3 object styles

    two for text frames that will include the top (23) and bottom (57) numbers and one for the middle line

     

    insert as an inline anchored object at the insertion point a text frame, for simplicity I'll call this the main text frame.

     

    In the main text frame insert the top and bottom number text frames and the line, i.e. 3 custom anchored objects.

     

     

    The top and bottom text frames should to the anchored setting like this

    ScreenShot045.png

    and

    ScreenShot046.png

     

     

    For the line object style set both the reference point to the middle

    Make sure to set up the paragraph styles properly

     

    All this can be done without scripting one setup you can just copy and paste the main text frame and change the numbers as needed.

     

    Of course scripting it with a keyboard shortcut would be much easier for you.

     

    Best to have 2 scripts 1 for inserting the main text frame so you can enter the numbers and another for after you have entered the number to adjust the geometricBounds (dimensions in this case) of the line top, bottom and main text frames according to the width of the numbers you entered.

     

    Trevor

     

    Note: in the top screenshot I was not careful on the size of the top and bottom text frames so the line comes to close to the 57. With a bit of care it would look good.

     

    Message was edited by: ~ Trevor ~

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 19, 2012 6:47 AM   in reply to -hans-

    Just wanted to add that I didn't see Hans script when I posted my above post.

    Not that it makes a difference.

     

    Trevor

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points