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
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
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
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:
- Set importedText = app.Selection.Item(1).Place "R:\mid\text\!MID FINAL.doc"
- //apply formatting to importedText
OR
- 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
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
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
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
Copy link to clipboard
Copied
ah ok now it makes sense
then passing through a temporary frame may be the easiest way
Copy link to clipboard
Copied
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