• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Formatting only newly placed text

Explorer ,
May 08, 2017 May 08, 2017

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

426

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , May 08, 2017 May 08, 2017

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 d

...

Votes

Translate

Translate
People's Champ ,
May 08, 2017 May 08, 2017

Copy link to clipboard

Copied

Hi,

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;

HTH

Loic

www.ozalto.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 08, 2017 May 08, 2017

Copy link to clipboard

Copied

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:

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

OR

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

Edit:

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 08, 2017 May 08, 2017

Copy link to clipboard

Copied

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

Loic

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 08, 2017 May 08, 2017

Copy link to clipboard

Copied

She is using functions like:

myStory.ChangeGrep

AND

myTextFrame.ParentStory.Texts.Item(1).ClearOverrides()

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.

Edit:

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) 

importedText.ClearOverrides()

importedText.ChangeGrep

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 08, 2017 May 08, 2017

Copy link to clipboard

Copied

ah ok now it makes sense

then passing through a temporary frame may be the easiest way

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 08, 2017 May 08, 2017

Copy link to clipboard

Copied

LATEST

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)

               tempFrame.Delete

          End If          

     End Select

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines