6 Replies Latest reply on May 8, 2017 4:00 PM by Rich.D

    Formatting only newly placed text

    Rich.D Level 1

      I currently have a script that is placing the contents of a document at the cursor insertion point, and then goes on to apply some formatting to the TextFrame it was inserted into. This works situationally, but I need to find a way to reference only the text that was brought in by the Place so that I can format it without changing the whole TextFrame. Alternatively, is it possible to create a temporary frame to hold placed text, format it, and then move the formatted text to the insertion point?

      Set myTextFrame = myDocument.TextFrames.Item("MyFrame")
      Select Case TypeName(myIndesign.Selection.Item(1))
           Case "InsertionPoint"
                myIndesign.Selection.Item(1).Place "R:\mid\text\!MID FINAL.doc"
           End Select

      myTextFrame.ParentStory.Texts.Item(1).ApplyParagraphStyle myParagraphStyle, True

        • 1. Re: Formatting only newly placed text
          Loic.Aigon Adobe Community Professional


          I think all you have to do is applying the style before you actually place the text.

          In JS that would be:


          var sel = app.selection[0];
          var initialStyle = sel.appliedCharacterStyle;
          sel.appliedCharacterStyle = app.activeDocument.characterStyles.itemByName ("new");
          sel.contents = "That's new for sure !";
          app.selection[0].appliedCharacterStyle = initialStyle;






          1 person found this helpful
          • 2. Re: Formatting only newly placed text
            Rich.D Level 1

            I was not aware that applying the styles first would determine the style for the imported text.  That will be helpful in some circumstances. Unfortunately it will not solve them all.  They are also applying some formatting that is not a style, for example some grep functions. Currently they are being applied to TextFrame or Document wide, and we need to limit it to only applying to the newly imported text.


            These are the two ideas that Ive had so far, but not been able to get either to work:

            Set importedText = app.Selection.Item(1).Place "R:\mid\text\!MID FINAL.doc" 
            //apply formatting to importedText 


            set tempFrame = app.Documents.Item(1).TextFrames.Add() 
            tempFrame.Place "R:\mid\text\!MID FINAL.doc" 
            //apply formatting to tempFrame 
            app.Selection.Item(1).Place tempFrame.Contents 


            Third possible option:

            Set startChar = PreviousItem(app.Selection.Item(1).Characters.Item(1))
            Set endChar = NextItem(app.Selection.Item(1).Characters.Item(2))
            app.Selection.Item(1).Place "R:\mid\text\!MID FINAL.doc"
            Set importedText = app.Selection.Item(1).TextFrames.Item(1).Texts.ItemByRange(startChar,endChar)
            //apply formatting to importedText
            • 3. Re: Formatting only newly placed text
              Loic.Aigon Adobe Community Professional

              What do you mean by grep functions attached to a text frame or document ?

              If you mean that the text to be imported might override  a style where grep style is specified, you can change the style overriding policy to preserve the existing one.

              I can't see why the style switch wouldn't work but feel to show me why I am wrong


              1 person found this helpful
              • 4. Re: Formatting only newly placed text
                Rich.D Level 1

                She is using functions like:





                Currently the functions are being applied to the entire frame or story, and she needs to be able to apply it only to the imported text in case there is existing formatting that should not be cleared on the preexisting text.



                I think I may have found a solution. Im going to combine your suggestion for the paragraph styles and character styles.


                Set startChar = app.Selection.Item(1)
                Set endChar = app.Selection.Item(1).ParentStory.Characters.NextItem(startChar)
                app.Selection.Item(1).Place "R:\mid\text\!MID FINAL.doc"  
                Set importedText = startChar.ParentStory.Texts.ItemByRange(startChar,endChar)  
                • 5. Re: Formatting only newly placed text
                  Loic.Aigon Adobe Community Professional

                  ah ok now it makes sense


                  then passing through a temporary frame may be the easiest way

                  1 person found this helpful
                  • 6. Re: Formatting only newly placed text
                    Rich.D Level 1

                    Yes, I agree. and I discovered how to do it in case anyone is interested in the future.


                    Select Case TypeName(app.Selection.Item(1))
                         Case "InsertionPoint"
                              docPath = "R:\mid\text\!MID FINAL.doc"
                              dim tempFrame
                              If docPath <> "" Then
                                   set tempFrame = app.Documents.Item(1).TextFrames.Add()
                                   tempFrame.Place docPath
                              End If
                              REM Call formatting functions on tempFrame
                              tempFrame.paragraphs.item(1).pointSize = 24
                              if docPath <> "" Then
                                   tempFrame.ParentStory.duplicate idLocationOptions.idAfter,  app.Selection.Item(1).ParentStory.insertionPoints.item(-1)
                              End If           
                         End Select