Script to determine number of lines of text in a paragraph?

I'm revisiting an issue I first posted here last summer, thanks to all who offered help, but I've not been able to sort it out.
http://forums.adobe.com/thread/455526?tstart=0
What I'm after is  a 'search function' to insert into a FindChangeByList.
Jongware suggested the following - but when inserted into my list I can't get it to do anything - it doesn't throw up a Javascript error.
app.findTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedParagraphStyle = "Callout_3";
foundItems = app.activeDocument.findText();
for (var i=foundItems.length-1; i>=0; i--)
  if (foundItems[i].paragraphs[0].lines == 2)
    foundItems[i].paragraphs[0].appliedParagraphStyle = "Callout_2";
  if (foundItems[i].paragraphs[0].lines == 1)
    foundItems[i].paragraphs[0].appliedParagraphStyle = "Callout_1";
I regularly receive a 'word' document on which I run a 'FindChangeByList' which cleans up and formats the text with a number of GREP/text searches.
One of the search lines converts a particluar string of text to a paragraph style "Callout_3" (the most common occurence of Callouts).
This style applies a paragraph rule, above and below the line, to create a coloured block/band out of which said text is reveresed.
The problem that I have is that the style (because of the paragraph rules), only works correctly if the paragraph has x3 lines of text.
I have styles set up for every other eventuality - Callout_1 (for single line of text), Callout_2 (for x2 lines of text) etc.
What I'm looking for is a script that can count the number of lines in the paragraph (once the "Callout_3" style has been applied) and then change the style accordingly to the number of lines in each paragraph/Callout.
Any further thoughts?
Steve

Hi Steve!
Well, I said it was untested ... Found two major errors. First one is also visible when you manually search for the style "Callout_3". Rather than marking each and every paragraph on its own, InDesign gathers as much as possible. Hence, just testing paragraph[0] would miss out all other paragraphs. Explicitly looping over all paragraphs per "found item" does work.
The other one is sort of a "syntax" error. Merely testing "lines == 2" does not work -- but it doesn't give an error either! Apparently, it's okay to compare an object ("lines") to a number, even though it doesn't work. The property to check is "lines.length" -- that returns the number of lines for a paragraph.
Putting it all together results in this script.
'And now I shall test it,' said Wen. This time he twisted it gently to and fro. 'That si-si-si That simple-ple, eh eheh simple, eh?'
... And I tested it.
app.findTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedParagraphStyle = "Callout_3";
foundItems = app.activeDocument.findText();
for (var i=foundItems.length-1; i>=0; i--)
for (var j=0; j<foundItems[i].paragraphs.length; j++)
  if (foundItems[i].paragraphs[j].lines.length == 2)
   foundItems[i].paragraphs[j].appliedParagraphStyle = "Callout_2";
  if (foundItems[i].paragraphs[j].lines.length == 1)
   foundItems[i].paragraphs[j].appliedParagraphStyle = "Callout_1";

Similar Messages

  • Set maximum number of line in text area

    Hi !
    I need to limit my text area to 3 lines. How do I do this ?
    I was thinking about character limitation but if the user
    press "enter" 3 times, I'm screwed since it is only 3 characters
    but it bust my 3 lines limit.
    Thx guys !

    You should never limit them to a set number of lines. Go for
    character limitation and test the input value before allowing them
    to submit the form.

  • Determining number of lines in a File without loading it to memory

    hello guys,
    I'm just wondering if there is a way to know the number of lines in a file without having to load the file entirely into memory and count the lines.
    in my project i have a restriction that says that i'm not allowed to load into memory more than 10 KB. i have to read the file block by block, say ten lines at a time.
    I actually did the second point which is reading the file 10 lines at a time, but still the total number of lines is still hard coded.
    thank you for your help !
    I

    ralfph wrote:
    hello guys,
    I'm just wondering if there is a way to know the number of lines in a file without having to load the file entirely into memory and count the lines.
    in my project i have a restriction that says that i'm not allowed to load into memory more than 10 KB. i have to read the file block by block, say ten lines at a time.
    I actually did the second point which is reading the file 10 lines at a time, but still the total number of lines is still hard coded.
    thank you for your help !
    ISo just read a line at a time, increase a counter, and don't save the line. As long as no one line is longer than 10 kB, you're fine.
    If it's possible for a line to be longer than 10 kB, then you'll have to read into a byte[] or char[] and iterate over it looking for end of line characters.

  • Determine number of lines of multiline container in ccBPM

    Hi guys,
    during my process a loop over a multiline element and send each entry to SAP backend.
    After shipment of the message the process waits for some time, to prevent problems caused by parallel messages in the backend.
    At the moment I use a block in the "for each" mode. But with this solution the wait step is executed unnecessary, after sending the last message of the multiline container variable.
    Is there a possibility to check the number of entries and solve this issue with a normal loop step and preventing the process for unnecessary wait step?
    I search SDN for some information relating this issue, but without success.
    Any help appreciated, thanks in advance
    Kind regards
    Jochen

    Hi Shabarish,
    thanks for helping.
    You are right I want to know how many entries are in the multiline container.
    I also thought about an export parameter in the transformation step where the multiline message is created.
    In this parameter I could return the number of entries.
    Maybe this would be an adequate approach for this issue.
    Unfortunately I wasn´t able to evaluate such a export parameter, when I tried it last time.
    I mentioned the issue in this [thread|;.
    maybe you know how to solve this issue..?
    kind regards
    Jochen

  • To display few lines of texts in a paragraph in bold in chinese

    Hi,
    I have a requirement to display smartform output in English and Chinese.In a paragraph few lines have to be displayed in bold in chinese.
    I have created a standard text in chinese languge to diplay this text.In the standard text,few lines have to displayed in bold.How to achieve this?

    Dear Hema,
    To me, I think you create a text node to put your chinese in it and create a character node in smartstyles for bold some paragraph.
    please check
    regards,

  • Determine the number of lines of textfield or floating field

    Hi,
    Is there a way to determine the number of lines of text in a textfield or in a floatingfield.
    My problem is that I'm creating a form with three tables(made of subforms) underneed each other that needs to be set to hidden when the total of rows is greater than 25.
    Now it would be easy to just count the rows but these rows can exist of multiple lines of text.
    The fields of my row are floating fields so when the text is bigger than the displayable width the text continous on a new line in the same row. So I need to know when this happens because now I can show only 24 rows.
    I tried counting the characters but this doesn't work, when there are a lot of 'i,j,l' or other small characters I can place 40 characters in my textfield, but when there are a lot of 'm,w' characters I can place only 22 characters in my field.
    I also tried to use xfa.layout.h(TextField1,"cm") to determine the height of the field, but it always retuns the value -1. I get the same -1 with the y or x - position.
    Does anybody have an idea how to solve this problem?
    Thanks in advance,
    RonnyR

    oops ... i got it thanks.
    code below -----
    for(var i=0; i <= s.length-1; i++)
    sCurrentLetter = s.substring(i,i+1);
    if (s.charCodeAt(i) == 13)
    // this is a line break

  • Number of lines in a Field of type Text with Javascript

    Hi,
    I have a form where I need to dynamically retrieve the number of lines in a Field of type Text.
    When I use getField(), I'm returned an object of type Field. I can see such properties as rect, but nothing concerning the number of lines of text in the field.
    Any idea (other than getting the Field height and dividing that by the height of a line) ?
    Regards,
    Karl.

    Hi,
    You can use below function to calculate the no of lines in the Text field dynamically.
    import mx.controls.textClasses.TextRange;
        import flash.text.TextField;
        private function calculateNoOfLines():int
          var tr2:TextRange = new TextRange(_text, true, 0,_text.text.length-1);
          tr2.text = _text.text;
          _text.invalidateSize();
          _text.invalidateDisplayList();
          _text.invalidateProperties();
          var contentTextField:TextField = _text.mx_internal::getTextField();                           
                  var nLines:int = contentTextField.numLines;
                  var lineMetrics:TextLineMetrics = _text.getLineMetrics(0);
                  // This is to calculate the total text height
                  var _textHeight:Number = lineMetrics.height * nLines;
         return nLines;    
    Call the above function in the KeyUp event of the Text field.
    Here in the above field _text is the Text field.
    <mx:Text id="_text" />
    If this post answers your question or helps, please kindly mark it as such.
    Thanks,
    Bhasker Chari

  • Set the number of lines allowed in multi-line text field

    Hi,
    I am designing a form where I have some multi-line text fields where I only want the user to be able to enter a maximum of say 5 lines. I know I could do this by enabling the "Limit Length to Visible Area" option, however, this option is ignored by Reader 7 and the field scrolls, hiding any text that spills beyond the visible area from printouts. It works great in 8 though. To avoid this bug/feature in Reader 7, is there some script that I can use to limit the number of lines allowed in a text field?
    Thanks

    I ran into similar issues switching between Acrobat/Reader. Here is the prominent code that works for me when I use this in "Enter" event of the textField.
    var aSOM=this.somExpression.substr(15,this.somExpression.length - 1);
    var acroField = event.target.getField(aSOM);
    acroField.doNotScroll = true;
    I chose Allow Multiple Lines alone and noting else.
    Good Luck,
    SekharN

  • How to find number of lines in the text content?

    Hello All,
    I have a multi line text item. I want to know the number of lines in a text item? How can I do that?
    Note that every lines end with the shift+enter.
    Example,
    This is a
    sample.
    After line This is a there is (Shift + Enter).
    Thanks for any help.

    Whenever the user inputs Shift-Enter, Photoshop inserts an [EOT] (End Of Text) control character (\x03 or \u0003) in the string.
    Also, in order to split the text according to multiple separators in only one call, it is necessary to use a regular expression instead of a string.
    Try replacing:
    var theArray = theText.split("\r");
    with:
    var theArray = theText.split(/[\u0003\r]/);
    BTW, you can improve performance by explicitely requesting the textKey property of the current layer object.
    Try using:
       ref.putProperty( charIDToTypeID("Prpr"), stringIDToTypeID("textKey") );
       ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    instead of:
       ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    HTH...

  • How can I find out the number of lines in a text file?

    How can I find out the number of lines in a text file?

    java.io.BufferedReader in = new java.io.BufferedReader( new java.io.FileReader( "YourFile.txt" ) );
    int lineCount = 0;
    while( in.readLine() != null )
    lineCount ++;
    System.out.println( "Line Count = " + lineCount );

  • Limit number of lines in a text editor

    Hello.
    In my program, i'm creating a text zone and i need to limit the data users will put in this zone.
    To create that, i'm using the object cl_gui_textedit. I've looked in the methods of this object but i wasn't able to find one that will limit the number of lines of the text editor.
    Did i miss it ? Does anybody knows how i can for example limit the input zone to 5 lines ?
    Thanks for your help.
    Here's my code
      IF g_editor IS INITIAL.
    *   Instanciation du container pour la zone de texte
        CREATE OBJECT g_textedit_custom_container
            EXPORTING
                container_name = 'TEXTEDITOR'
            EXCEPTIONS
                cntl_error = 1
                cntl_system_error = 2
                create_error = 3
                lifetime_error = 4
                lifetime_dynpro_dynpro_link = 5.
        IF sy-subrc NE 0.
    *      add your handling
        ENDIF.
    *   Création de la zone d'édition du texte
        CREATE OBJECT g_editor
          EXPORTING
            parent        = g_textedit_custom_container
            wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
            wordwrap_position          = 68
            wordwrap_to_linebreak_mode = cl_gui_textedit=>true.
      ENDIF.

    I just notice there is a method SET_HEIGHT but this one is implemented in CL_GUI_CONTROL.
    I tried this :
            CALL METHOD g_editor->set_height
                    EXPORTING height = w_height.
    But in fact, i never enter the method.
    Do i have to create a CL_GUI_CONTROL object ? If yes, how do i link it to the CL_GUI_TEXTEDIT.
    Sorry if some questions mays seem obvious. It's my first object abap program.

  • Counting number of lines in a text/csv file using xquery/xslt.

    Hi,
    I have a CSV file, I need to count the total number of lines in that file. This I have to use in OSB. My requirement is I have to count total no of lines in the $body file (CSV/flat file) and subtract header and footer lines from it.
    EX:
    header,1, @total_no_of_detal@
    detail,1
    detail,2
    detail,3
    detail,n
    footer, 1
    If suppose i have 10 detail lines, and I am getting body of the file as shown above,
    then in the final file, I have to change the body of the file as:
    header,1, *10*
    detail,1
    detail,2
    detail,3
    detail,n
    footer, 1
    Please advice how to do this in OSB.
    Edited by: user12679330 on Aug 2, 2011 2:34 AM

    I would suggest you to use MFL to convert the file into XML when you read it and then you can count the detail elements within the XML and update the values in Header element before writing the file again in flat file format again using MFL.
    You can read the documentation of Format Builder utility which is used to define MFL here:
    http://download.oracle.com/docs/cd/E21764_01/doc.1111/e15866/part_fb.htm
    Alternatively, another approach is the read the whole flat file as a text string and then doing needed manipulations to get what you need. If you want to do it like this then you will need to consider following things:
    1. Is the file in DOS format or Unix format? (To know the End of line character in use)
    2. Does the file contain an end of line at the end of file? (whether there is an end of line char at the end of data of footer record)
    Once you know above, you can try an xquery like following:
    let $intermediateXML :=
    <Root>
    for $a in (tokenize($in, 'EOL'))
    return
    if (string-length($a) > 0)
    then
    <record>{$a}</record>
    else ()
    </Root>
    let $count := count($intermediateXML/record)
    let $outXML :=
    <OutRoot>
    for $i in 1 to $count
    return
    if (data($i) = 1)
    then
    <Record>{concat($out, $intermediateXML/record[$i]/text(), ',Count=',($count)-2)}</Record>
    else
    <Record>{concat($out, $intermediateXML/record[$i]/text())}</Record>
    </OutRoot>
    return op:concatenate($outXML/Record/text(), 'EOL')In Above XQuery, replace EOL with the end of line character which for unix wound be "&#xA ;" (remove quotes and space between the A and ; ) and for DOS would be "&#xD ;&#xA ;" (remove quotes and space between the A and ; and D ; )

  • SAP-Script - Draw Table (Boxes) with variable number of lines

    Hello,
    I want to create a Table with Frames in a SAP-Script Form. First of all I don´t know the position of the table in the window main. It can be page 2 or 3 on top or in the middle. But i have to describe a position like
    POSITION YORIGIN '12.95' CM.  How can i position the table in a variable way?
    And i don´t know the number of lines of the table. How can I manage to draw the correct numbers of boxes as numbers of lines exist?
    Kind Regards
    Carsten Fuchs

    Hi carsten,
    1. Drawing GRID (just like excel, matrix)
       is very cumbersome in sapscript layout.
      (either dynamically, or hardcoded)
    2. Moreover, the final look,
       may or maynot appear as requried,.
      ie. exactly with proper alignment and grid lines.
    3. If the font size is required to change,
      then the dynamic position also changes.
    4. If the grid is supposed to go to the next page,
      again the calculation and logic becomes tougher.
    5. To use grid, its better to use smartform,
       which provided FINE CONTROL of the grid
      and its lines and width, height, style etc.
    6. In sapsctip, at most we can use
       UNDERLINE (_) and PIPE (|)
    regards,
    amit m.

  • How to number lines of text?

    I would like to number lines of text continously throughout the book. I am trying to make lines of text easier to find when my class is having discussions about the book.

    It seems to me that you are either using the wrong tool for the job or your book is too wordy for this type of presentation.
    1. If it is extremely wordy then use an application on the Mac such as iText Pro that can number lines and then export or Print to pdf with the numbered lines in place.
    2. If it is not so wordy then simple description or location should be sufficient to find anything or you use lists that hone the student down to the exact subject point.
    Isn't "15.9.11" close enough for even those that need to follow the text with their fingers?
    Peter

  • How to determine the length of a line of text in a multi line text control

    I am working on a simple widget to compare two snippets of text.  The string controls are side by side with a colum of square bools in between
    the two string controls.
    The Bools line up with the lines of text in each string control.  The Bools are used as a quick indicator that at that line point there is a difference
    between the two string controls.
     There is a slider that allows the user to scroll up and down,  the slider scrolls both string controls simutaneously.
    As the string controls are scrolled I will be comparing the left and right lines of text and reflecting the match status in the Bool Colum.
    The reason I need to know the length of the line of text is so each line can be compared against one another.  It is not as simple as counting the
    col width of the string control and parsing the text because if there is a line return the text will word wrap before before it extends all the way accross the string control, which will cause parsing discrepencies.
    Any suggestions on obtaining the multi line string control text character length would be much appreciated.
    Best Regards
    Tim C. 
    1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!

    Front panel of widget....
    1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!
    Attachments:
    One.vi ‏27 KB

Maybe you are looking for

  • Macbook Pro Mini Displayport to HDMI problem Please Help!

    I just bought a new Macbook Pro Core i7 15" and have it connected to a [URL="http://www.amazon.com/Samsung-P2370HD-23-Inch-1080p-Monitor/dp/B002DHS398 "]Samsung P2370HD[/URL] via a [URL="http://www.kanexlive.com/products/item-id-3689.html"]Kanex Mini

  • DW CS3 not importing entire site cache from DW8

    Hi; I upgraded to the CS3 web premium suite from studio 8. My site caches were imported but the log on info for each was not. Is there a fix for this ? Thanks; Pat

  • Apple ID conflict

    I tried several times to update iphoto to the latest version but it tells me this is an update only available for a different apple ID. I have only used one apple ID to purchase anything I've ever bought or installed on my Mac so it doesn't make sens

  • Q How can I tell when my Red nano is charging

    The screen on my nano doesn't show any change to the battery symbol so how do I know it's charging?

  • How to enable kde 4 theme into libreoffice-fresh ?

    Some time ago I installed libreoffice-fresh and the file dialogs and icons are "libreoffice-style" rather than "kde-style", i have installed "kdelibs" for KDE desktop integration .. but no result. Any ideas?, any advice ? Regards.