10 Replies Latest reply on Jul 20, 2012 2:27 AM by M V SHAJI

    Is there is any automated way to make fraction.

    M V SHAJI

      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

        • 1. Re: Is there is any automated way to make fraction.
          Learner X Level 1

          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

          • 2. Re: Is there is any automated way to make fraction.
            M V SHAJI Level 1

            Hi,

             

            Thank u so much for your valuable suggestion.

             

            Our document has more combinations, to create a library is a tedious process, since its around 40 to 50 combinations in this book.

             

            Moreover its not unicode single character set.

             

            What ever the combinations, that should be converted to division.

             

            1/300, 1/2, 200/10....

             

            Once again thanks...

             

            Shaji

            • 4. Re: Is there is any automated way to make fraction.
              M V SHAJI Level 1

              Hi,

               

              Thanks for the link.

               

              Our requirement is to convert it to division.

               

              Like this:

              Picture-2.gif

              • 5. Re: Is there is any automated way to make fraction.
                [Jongware] Most Valuable Participant

                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.

                • 6. Re: Is there is any automated way to make fraction.
                  M V SHAJI Level 1

                  Presently we are doing it manually.

                  Using table cell.

                  We insert 2 row and 1 column table and copy and paste the content above and below.

                  With the help of stroke we apply the line in between.

                   

                  Shaji

                  • 7. Re: Is there is any automated way to make fraction.
                    -hans- Level 4

                    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}

                    • 8. Re: Is there is any automated way to make fraction.
                      Trevorׅ Adobe Community Professional

                      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 ~

                      • 9. Re: Is there is any automated way to make fraction.
                        Trevorׅ Adobe Community Professional

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

                        Not that it makes a difference.

                         

                        Trevor

                        • 10. Re: Is there is any automated way to make fraction.
                          M V SHAJI Level 1

                          Thank u so much for the valuable suggestion.

                           

                          Shaji