Replace the string with the formatted text

Hello all - I'm back to my beloved project...

I want to replace a string by a TextSelction (formatted text) and began with the famous feature of Jang FindAndReplaceString.
Since my replacement comes from another document (sourceDoc), I edited to targetDoc activeDoc and introduced a second document (sourceDoc).
The replacePara actually comes from a stone where he had been placed to avoid switch backwards between the documents in a book (where to find and replace) and source documents. In another function, I learned that information on the table requires the sourceDoc must remain open.

  • Of course, everything works fine until I want to insert the replacelement:
    erase line 26 is the string
  • Given that I do not insert a string, I skip lines 28 and 29 and try try line 30
  • On line 30 DocumentSource is Document object and replacePare object TextSelection. However, sourceDoc.replacePara is not set and
  • (as a result?) line 31 past the current contents of the Clipboard.

Of course, there is a fog around me... and I need some sunshine.

function FindAndReplacePara (targetDoc, findString, sourceDoc, replacePara, loopMax) {
  var tr = new TextRange();
  var restoreTR, frame = 0, loopCounter = 0, replacementCounter = 0;
  var findParams = new PropVals();
  var firstPgf = targetDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
  
  tr.beg.obj = tr.end.obj = firstPgf;             //  set up the starting text range as the very beginning
  tr.beg.offset = tr.end.offset = 0;              // of the flow. We'll move straight from beginning to end.
  trSaved = tr                                    // to come back after work

  findParams = AllocatePropVals(2);
  
  findParams[0].propIdent.num = Constants.FS_FindText;
  findParams[0].propVal.valType = Constants.FT_String;
  findParams[0].propVal.sval = findString;
  
  findParams[1].propIdent.num = Constants.FS_FindCustomizationFlags;
  findParams[1].propVal.valType = Constants.FT_Integer;
  findParams[1].propVal.ival = Constants.FF_FIND_CONSIDER_CASE;

  FA_errno = Constants.FE_Success;                // errno global, to be used to track the progress of the find and replace
  tr = targetDoc.Find(tr.beg, findParams);        // and do an initial find to get started.
  
  while(FA_errno === Constants.FE_Success && loopCounter++ < 2*loopMax) { //find and replace loop as long as we keep finding
    targetDoc.TextSelection = tr;                 // set up the text range to clear the original text
    targetDoc.Clear(0);                           // clear it
    
//    targetDoc.AddText(tr.beg, replacePara);       // insert the new text at the original beginning of the text range
//    tr.beg.offset += replacePara.length;          //  lets jimmy the text range in memory to place it directly after
    targetDoc.TextSelection = sourceDoc.replacePara;        // paste the whole replacement paragraph
    targetDoc.Paste (0);                          // <-- Current contents of clipboard is pasted !!!!
    if(FA_errno === Constants.FE_Success) {       // increment our return counter
      replacementCounter++;
    }
    FA_errno = Constants.FE_Success;              // ...  find the next instance. We'll reset FA_errno again just in case
    tr = targetDoc.Find(tr.beg, findParams);      // something screwy happened while we were replacing text.
  }
  targetDoc.ScrollToText(trSaved);                // we're done. Restore the document to it's original area of display
  return replacementCounter;
} // --- end FindAndReplacePara

Hi Klaus,

Thanks for the explanation. I remember something like that GetTabRange of the way back. You have been quite patient and persistent with this project, indeed.

So, as we are dealing with ranges of text here, I think that the only simple approach is to perform a copy and paste. There is no way to save a 'formatted' in a variable. The only super precise way would be to get a data structure of each text range TextItems in the sourceDoc, then meticulously recreate every element of the targetDoc. It would be very complicated, I think, so copy and paste seems the most logical. I wonder, though, if Miss me something, because I think that maybe you would have tried already so yes (?)

In any case, I would do something like that, from line 30 of your original code sample (code untested here):

App. ActiveDoc = sourceDoc;

sourceDoc.TextSelection = replacePara;

sourceDoc.Copy (0);

App. ActiveDoc = targetDoc;

targetDoc.Paste (0);

... etc.

Does make sense, or am I barking the wrong tree, as they say?

Russ

Tags: Adobe FrameMaker

Similar Questions

  • Replace the selected text with other content TextFrame

    Hello

    I am changing a text selected in something new, involving the movement of text and the paragraph style using a jsx script. At the present time, everything works beautifully:

    • I entered the select text
    • I have create a new temporary TextFrame
    • I build my new paragraphs and apply styles to them in the new TextFrame

    What I was not able to reach still is to replace the original selected text by temporary TextFrame content.

    Any help would be more than welcome

    A part of my script:

    myText = app.selection[0].contents;

     

    ... do some stuff


    var myDocument = app.documents.item(0);

    var myPage = myDocument.pages.item(0);

    var myTextFrame = myPage.textFrames.add();


    myTextFrame.geometricBounds = [0, -70, 150, 70];

    myTextFrame.contents = "Paragraph1\rParagraph2...";


    myTextFrame.paragraphs[0].appliedParagraphStyle = pStyleGroup.paragraphStyles.itemByName('Style1');

    myTextFrame.paragraphs[1].appliedParagraphStyle = pStyleGroup.paragraphStyles.itemByName('Style2');

    And now, in myTextFrame, I have my new paragraph formatted, and I would like to replace the original selected text with the contents of my TextFrame (keeping the paragraph styles).

    Hello

    Keep the logic of the code and edit utilities:

    var
        mSourceIdx = app.selection[0].index,
        mStory = app.selection[0].parentStory,
        mReplaceStuff = {
            elements: [
                ["Paragraph_1\r",  "Style_1"],
                ["Paragraph_2\r",  "Style_2"],
                ["Paragraph_X\r",  "Style_X"]
                ]},
        mTarget, cElement, cText, cParaStyle;
    
    while (cElement = mReplaceStuff.elements.pop()) {
        cText = cElement[0];
        cParaStyle = app.activeDocument.paragraphStyles.item(cElement[1]);    // modify if styleGroups present in a structure
      mTarget = mStory.insertionPoints.item(mSourceIdx);
        mTarget.contents = cText;
        mTarget.paragraphs[0].appliedParagraphStyle = cParaStyle;
         }
    
    app.selection[0].contents = "";
    

    MReplaceStuff allows to prepare stuff to replace

    Jarek

  • Replace the JQuery text is all the text in the webapp manufacture

    Hello, I hope someone could give me a hand!

    On this home page: www.largemouthfrog.net I am running a Web application called "Testimonials" which produces a string of words/phrases on the basis of the selected check box. "They come in the page as: < li >... <div class= 'testimony-commentaires1' >awesome! Excellent! really good < /div >... < /li >

    For each < li > there is a separate set of words or phrases separated by a comma.

    I want to remove the comma and replace < br >

    I have the following JQuery (see below) which replaces the comma with < br > BUT it must be the first instance of < li > of

    "<div class= 'testimony-commentaires1" > and it repeats again and again for all other < li > ' s. " In other words:
    "great!, great!, really good" is repeated several times.

    I tried to put the JQuery inside available to the Web application list, but does the same thing.

    < script >

    {$(document) .ready (function ()}

    var str = $(".testimonial-comments1").html () replace (/, / g, '< br / >');

    $(".testimonial-comments1").html (str);

    });;

    < /script >

    Any help would be appreciated!

    Hi Wayne,

    Your code is a bit too simplistic and it fails because it is not really

    loop through all elements of web application and instead, it captures the content of the

    first one defines the rest of them with this content. I have created some

    code that will help you get started. Here it is:

    $(".testimonial-comments1").each (function (index) {var tags_text =

    $(this) .text (); var split_text = tags_text.split(',');

    Console.log (split_text); });

    You can see here http://mgtrain.worldsecuresystems.com/tags

    My class is simply called "label" and my layout of the list looks like this:

    {tag_name}

    {tag_tags}

    Basically, this code creates an array of strings for each iteration.
    All you have to do now is to browse table and Add.
    "to each.

    point, join the elements in a string, then set $(this) .text () of this new

    value.

    That said, I recommend you to build a form UL these options in this

    case. It's a bit more semantic to me.

    I can actually make this my first blog at www.twoblokeswithapostie.com

    See you soon,.

    Mario

  • Legend of failure to replace the caption text

    Hello

    How would I be able to achieve the following in Captivate 5:

    Location:

    I have an image, a clickbox on it and a text caption requiring the learner to click the clickbox. If someone clicks on the clickbox, a legend of the failure appears.

    I'm looking for:

    Currently, the legend of failure shows for the duration of the slide (3 seconds), then he disappears and returns to the text caption. However, I want the legend of failure to replace the text of the caption completely.

    Can anyone advise me on what I should do?

    Thank you!!

    Hello BettinaK,

    Welcome to the Adobe forums.

    You can set the timing for the legend text in its properties lets say 3 seconds. After 3 seconds, it will disappear.

    Now if the user clicks the clickbox, you will get 'type text of failure here', you can click on it and set the ignition for it, like the rest of the slide.

    Here are the screenshots

    Step 1 > your slide is something like this (I'm sorry to not use any image of the slide)

    Step 2 > now you can set the timing for the text of the legend (click here). Here I put it for only 3 seconds, so it will disappear after 3 seconds

    Step 3 > now click on 'Failure Type here text' and adjust the ignition in his properties as well

    By doin this failure of Type here text appears for the duration that you want and it will take the place of the legend text

    I hope that helps!

    Vishal

  • How to replace a string with asterisks? This is related to my previous post

    I guess I now replace the middle segment of which is recovered by asterisks.

    Thus, the string in the middle of "99999988" should be replaced by ' *'. Basically, I'm trying to hide the average advertising channel. The length of the original string is not known, but the first segment is 6 characters and 3 segment is 4 characters. Intermediate gum can be between 5 to 10 characters. In the example below, its 8 characters.

    Can I use functions REPLACE or TRANSALE here?
      select substr('456712999999881234', 1, 6) a,
             substr('456712999999881234', 7, length('456712999999881234') - 10) b,
             substr('456712999999881234', -4) c
      from      dual;
    Thank you

    Hello

    So, you want a chain of n - 10 b *, where n is the length of the string:

    SELECT  SUBSTR (txt, 1,  6)               AS segment_1
    ,       RPAD ('*', LENGTH (txt) - 10, '*')     AS segment_2
    ,     SUBSTR (txt, -4)                             AS segment_3
    FROM     table_x;
    

    It doesn't matter what were these characters, so you can't use TRANSLATE.

  • in the format text for variables

    I'm a quiz of vocabulary in flash application design, and it draws to determine the definition of a Word when it is used in the context. I have the code to communicate with php and mySql that returns my question 3 variables work.
    question_start / / the text of the sentence after the word vocab
    target_word / / the word
    question_end / / the rest of the sentence

    Here's the line of code that assigns this to my text field:
    [code]
    question_txt. Text = variables.question_start.concat ("", variables.target_word, "", variables.question_end);
    [/ code]

    It works fine, but I want variables.target_word is displayed differently than the rest, either in italics, bold, different color or whatever. I tried to change the database:

    < i > < /i > Word
    the italic tags are not interpreted, they come with him. I think not (using AS3 and php5) how to get only one word in italics.

    I know that I can create a text field for just this word that has italic set to true, or put another text field that says that "the definition of < Word > is:" above my radio group, but I really would prefer to find a way to incorporate the italics in the sentence. "

    Thanks to anyone who can help
    p.s.: I was looking for the right tag display the code, but have not yet found

    I have not yet took the leap to AS3, but in AS2 I would convert it the TextField to a htmlText field, then you can apply tags to style, I think it would still be viable in AS3, use the html button, after selecting the domain and then code something like:

    PS. (you must use the button attach the Code in the edit box)

  • Rapports--deuxieme page generator is replaces the overflowed text of 1 pg

    My report model is quite complex. I have an option where a second logical page will print if necessary. This optional page should always be on its own page. What is happening is that it's overwhelming the lines that go beyond the first page.

    The first page by repeating the image overflows to the second page. The second page is composed of two executives extensible, surrounded by a static image. I tried various combinations of attributes and the second image of the page, i.e. the child to parent repeating chassis anchor. I also tried anchor on the chassis of stastic autour parent repeating frame. Nothing works properly.

    I have passed several daze about it and am at my wits end. Any suggestions?

    The second page is composed of two executives extensible, surrounded by a static image.

    Change the following properties for the static image that is on the second page:

    Impression of objects on: last Page
    Basic printing on: anchor object

    and are also used to front page by repeating the image in a static image with the following properties

    Page break after: Yes
    Vertical elasticity: Variable or expand

    Impression of objects on: first Page
    Print base on: enclosing object

    I hope this helps.

  • Acrobat pro XI: how to accept a comment, and then replace the old text?

    My Office Manager began a PDF for review through four managers and sent me the PDF commented to change.  In WORD, there is a button I accept and changes are corrected in the original doc.

    I see all kinds of information on the management of comments, print them etc, but none on the execution of this function which makes of the WORD.

    I try to cut and paste all (271) comments in a word doc so I don't have to do this again.

    Any suggestions before I lose half of my day?

    Hi stephens78119216,

    I'm sorry, but unlike word, there no function in Acrobat to accept changes made in the document.

    Although you can follow reviews added in the PDF file.

    Ref: Acrobat Help. Follow-up and management of PDF comments on

    Kind regards

    Ana Maria

  • Replace a string with a textBox Word key

    I think no doubt about it the wrong way. My goal is to create a textField in a position of a key word in a textField and update the position based on that keyword

    Example: The planet RESPONSE is the 3rd away from the Sun. (I want the ANSWER keyword to generate a text field in the posion even in the question).

    My problem is trying to find a coherent solution to a dynamic list of questions.

    My code so far:

    var str:String = "Hi"it is an example RESPONSE.";

    var theText:TextField = new TextField();

    Answer.Text = str;

    addChild (theText);

    theText.y = answer.y;

    //!!!! my place of disorder! //

    theText.x = (answer.x + theText.text.length) + str.indexOf ("ANSWER");

    Thanks for any help or suggestion.

    You are welcome.

    and you're right: the tf should be added to the screen before their references are crushed and the tf of entry must use and Event.CHANGE, Event.TEXT_INPUT or TextEvent.TEXT_INPUT:

    function keywordF(questionS:String,keywordS:String,x:int,y:int):void {}

    var nextX:int = x;

    var a: Array = questionS.split (keywordS);

    var tf:TextField = new TextField();

    addChild (tf);

    TF.x = nextX;

    TF.y = y;

    TF. Multiline = false;

    TF. Text = a [0];

    tf.autoSize = "left";

    nextX += tf.width + 5;

    TF = new TextField();

    addChild (tf);

    tf.addEventListener (Event.CHANGE, textchangeF);  Create your textchangeF to check user input.

    TF. Multiline = false;

    TF. Text = keywords;

    TF. Border = true;

    TF.type = "Input";

    tf.autoSize = "left";

    TF.x = nextX;

    TF.y = y;

    nextX += tf.width + 5;

    TF = new TextField();

    addChild (tf);

    TF.x = nextX;

    TF.y = y;

    TF. Multiline = false;

    TF. Text = a [2];

    tf.autoSize = "left";

    }

  • Search and replace the string formatting

    Hello

    I try to do a search and replace the formatting of a string.

    In the example, I'm looking for the string 'SUCCESSFUL', but it must also begin by usbflash and some number + PASSED.

    I can't get the format to have a number between 1 and 99. The number of replacements should add up to 6 in this case. I tried with \d for any number, and I also tried [1-99].

    Make a right-click on the function search and replace the string.  There is an option to use regular Expressions.  Then give it a try.

    EDIT: You need to set the entry replace all to TRUE.

  • How to replace the close on af:dialog icon

    Hi all

    How to replace the icon close [X] in af:dialog with NARROW text link.

    I know there is a way to hide the icon via css by setting af:dialog - close - region:display: no

    But how to replace the CLOSE text icon.

    Use Jdev version 11.1.1.5.

    Use this:

    AF | dialogue: closing-icon-style.

    AF | dialogue: closing-icon-style: hover,.
    AF | dialogue: closing-icon-style: development,.

    AF | dialogue: closing-icon,.

    AF | dialogue: closing-icon: hover,.
    AF | dialogue: closing-icon: update

    {- tr - inhibit: background-image;}   content: 'CLOSE' ;}

  • CS6: create a simple extension: how to copy the selected text in the extension?

    Hello

    with this tutorial http://www.DWfaq.com/Tutorials/Extensions/simple_object.asp

    I created a very simple extensions in Dreamweaver CS6.

    But I can't find out how to get the code/selected text "in" this extension.

    I want to reformat the selection with the javascript code for the extension and replace the selected text.

    Thank you!

    mtemp

    Thank you very much for your answer!

    I didn't know the difference between these two methods - my google search for 'extension' led me directly to the old tutorial mentioned...

    And, Yes, I had to search long enough to find the 'object' extension on the fly on the menu...

    Now, I adapted the code referred to in the dreamweaver_cs5_extending.pdf for the creation of such an extension of command - and, wow, it works... with 'copy' the text selected in the extension form.

    So, thanks again! Now I'm on the right track

  • Any way to make the default text caption stick?

    Hello

    Is it possible to change the legend of default text in a specific font and size.  When I record, it works very well, Captivate keeps my 18-black police.  But when I manually add text captions, the size goes back to another font size of 10.

    Thank you.

    Hello

    Sorry to be a little late, I work with Captivate 5 all the time now, almost forgotten some features in CP4.

    The default layout for the text captions that you chose, is possible for text captions that appear during capture. I think you point to editing, preferences, default record?

    When you manually add text captions, there is not such a value by default (as it is now with the object to CP5 styles) but you can achieve your goal in two ways:

    1. Change the TC first you want, CP has a memory and all following captions that you add will have the same layout. This function even memory when you open a new project, the last remembered formatting will be applied.
    2. If you want to change the layout of all the existing legends (but this does not always work perfectly), try the feature "apply to all".
    3. Create a template with properly formatted text captions and use it for your projects
    4. Apply a design template.

    Lilybiri

  • How to apply/generalize the same text of failure in all Failure_Caption in the project in order to avoid manually change in each legend of failure?

    How to apply/generalize the same text of failure in all Failure_Caption in the project in order to avoid manually change in each legend of failure?

    For example the 'wrong' text in all the legend of failure

    You can set the default text that appears in all the legends of failure for the quiz via the parameters for the Quiz questions.  However, after you have made changes here that will affect quiz slides that you add AFTER that, change.  There is no way to change the text in all the legends of defect EXISTING at the same time.  You will have to select each one and replace the current text manually.  If you firmly believe that you will need to do this more than once, you might consider using a user Variable that displays as the value in the legends of the failure.  Then you can edit them while changing just the value of the user variable.

  • Replace the text with formatting

    I need to replace every occurrence of the word with impatience! with forward! in italics. I have not found a way to do... Any ideas?

    Thank you

    JackL

    Captivate 7 - Windows 7

    I have the answer for those who are interested. Captivate (7) lets you export captions and subtitles to Word. Once in Word, simply replace the text sought by the text in the layout you want, save, and then re-import the Captivate projects. Works perfectly, with a caveat. If you use bullets (standard or numbers), the hyphen and the bullet formatting to these legends may require some manual adjustments after importation.

    In any case, this process has saved me a lot, a lot, a lot of hours!

    Jack Loganbill

Maybe you are looking for

  • It is close to the app tool?

    When sometimes I want to get out of the app I can't because there is no tool for this... You must fix this too.

  • printer want offline 4500 series

    MY printer was working fine steeple, but today it says it is offline and I can't find a way to fix. I unplugged the printer, rebooted several times, reconnected to the wi - fi connection. Both my computer and my iphone does not. How do I get it onlin

  • Crush: A text message can be sent: computer to my cell phone

    Y at - it no add-on software from stand-alone for my computer to send text messages to cell phones?

  • get "the wizard was interrupted before Acrobat Pro XI...

    A ran two cleaners.As an admin.Order Symantec Endpoint ProtectionMsconfig to kill startup itemsWindows 7 SP1 Enterprise x 64

  • Conditional Script error map FDM

    Hi all We can import the data of EBS to HFM however ERPI using FDM. We used conditional Basic scripts of the ebs to FDM data import. This scripts used in FDM for PEAK dimension between the logic of script.script conditional mapping is a particular ac