3 Replies Latest reply on Jun 13, 2014 5:54 AM by Jump_Over

    Paragraph to textFrame or Rectangle text


      Please help, I am really stuck. I have a bunch of classified ads (each is a Paragraph) in three columns (each is a textFrame). I have no control over the foregoing. For each paragraph starting with "##", I need to remove the "##" (this part is easy) and cause the background color of an imaginary rectangle behind the paragraph to be yellow. I get stuck because I do not know how to get the position and height of the paragraph so that I could create a rectangle or a textFrame. An additional requirement is that the Editor (working in InDesign) be able to move the paragraph around along with its yellow background as a single object. Any help would be appreciated.

        • 1. Re: Paragraph to textFrame or Rectangle text
          Jump_Over Level 5



          What about a workaround like this:

          • find paragraph starting with "##"
          • remove "##"
          • convert it to a table (1 row / 1 column)
          • add properties like stroke, fillColor, insetSpacing ==> to set a proper format.



          • 2. Re: Paragraph to textFrame or Rectangle text
            Ungaro Level 1

            Thanks for replying, Jarek. Could you pls send a link on how to convert the paragraph to a table? Can I insert the table into the paragraph's parent textFrame so that the table inherits things like insetSpacing, etc.?

            • 3. Re: Re: Paragraph to textFrame or Rectangle text
              Jump_Over Level 5



              Exam this code:


              // BEFORE start ==> place cursor inside target textFrame or select this textFrame
                mDoc = app.activeDocument,
                mStory = app.selection[0].parentStory,
                paraStyleToTable = mDoc.paragraphStyles.item(0),     //     basicPara for now or modify
                mStrokeColor = mDoc.swatches.item(3),     //     3 - is an index, name of swatch can be used as well
                mFillColor = mDoc.swatches.item(6);
                app.findGrepPreferences = app.changeGrepPreferences = null;
                app.findGrepPreferences.findWhat = "^##";
                mFound = mStory.findGrep(),
                len = mFound.length,
                currPara, currTable;
              while (len-->0) {
                currPara = mFound[len].paragraphs[0].characters.itemByRange(0,-2).texts[0];
                currTable = currPara.convertToTable()[0];
                currTable.cells[0].contents = currTable.cells[0].contents.replace(/^##/,"");
                currTable.storyOffset.appliedParagraphStyle = paraStyleToTable;
              app.findGrepPreferences = app.changeGrepPreferences = null;
              // modify existing properties or add a new one to specify
              function mFormat (thisTable) {
                with (thisTable.cells[0]) {
                bottomEdgeStrokeColor = mStrokeColor;
                leftEdgeStrokeColor = mStrokeColor;
                topEdgeStrokeColor = mStrokeColor;
                rightEdgeStrokeColor = mStrokeColor;
                bottomEdgeStrokeWeight = 0.5;     //    cell's strokeWeight to modify
                leftEdgeStrokeWeight = 0.5;
                topEdgeStrokeWeight = 0.5;
                rightEdgeStrokeWeight = 0.5;
                bottomInset = 2;
                leftInset += 0;    //    cell's left/right inset inherited from parent para 
                topInset = 2;
                rightInset += 0;
                fillColor = mFillColor;
                fillTint = 30;     // tint to modify