3 Replies Latest reply on Feb 9, 2015 3:05 AM by Stamm

    Find a Tab, duplicate its textFrame and delete the overflowing content?

    Stamm Level 1

      Hey guys,

       

      I have a textFrame where we use Tabs to have some kind of table. The content is floated to the left and on the right. There are linebreaks and sometimes single lines are used to it's full width. I need to markup these with xml. This is no problem. The problem is, in xml I need two text-areas, because I can't have a "text-align: right" and "text-align: left" in one single xml element. My approach to this is the following:

       

      function findTab(object){

          app.findTextPreferences.findWhat = "^t";

          theText = object.findText();

          position = new Array(theText.length);

          for(ta = 0 ; ta<theText.length; ta++){

              position[ta] = new Array();

          }

          for(ta = 0; ta < theText.length; ta++){

              position[ta][0] = ta;

              position[ta][1] = object.paragraphs.item(ta).contents.indexOf(theText[ta].contents);

              tc = ta;

              while(position[ta][1] === -1){

                  tc++;

                  position[ta][0] = tc;

                  position[ta][1] = object.paragraphs.item(tc).contents.indexOf(theText[ta].contents);

              }

          }

          if(position[0].length > 0)

              return position;

      }

       

      function markUpTab(object) {

          findTab(object);

          myDup = object.duplicate();

          for(vf = 0; vf < position.length ; vf++){

              myDup.paragraphs.item(position[vf][0]).characters.itemByRange(position[vf][1], myDup.paragraphs.item(position[vf][0]).characters.length-1).texts[0].remove();

              object.paragraphs.item(position[vf][0]).characters.itemByRange(0, position[vf][1]-1).texts[0].remove();

          }

      }

       

      position[i][0] is the index of the paragraphs where there is a tab. Position[i][1] is the position of the first character after the tab in this paragraph. With the "markUpTab" I need to duplicate this frame, delete all texts which are on the left in one frame and all which are on the right in the other frame. For this I'm using the for-loop. Now it happens, that one "left" text has right align on it, because someone didn't design it properly. So when it deletes the "right" content, the "left" content is floated to the right and sometimes even adds a linebreak. Then it can also happen, that this line is overflowing to the 2. line, so all paragraphs are basically one lower than before and the code breaks.

       

      I hope I could explain this neatly, as it can be quite confusing. Does anyone know how I can properly keep the formatting of my textFrames, while deleting the unnecessary contents?

       

      Thank you in advance!