tijlcarrein
Programmer
Is ther a way to Serach and Replace the filename of an image that is inserted as text in a table?
This is the script I use for replacing the names of the images with the place method and the real filepath and filename.
REM Start of Script -----------------------------------
Dim myCounter, myFoundCounter, myStartIndex, myEndIndex
Rem Enter the path to the folder containing the images you want to place.
myPath = "C:\test\img\press\1\"
Dim i, j, k, start, start2, MyDoc, idNothing, MyFind, Found
Set myInDesign = CreateObject("InDesign.application.CS")
Rem Clear the find/change preferences.
' clears find preferences
myindesign.FindPreferences = idNothing
myindesign.ChangePreferences = idNothing
Set myDocument = myInDesign.ActiveDocument
myDocument.save("c:\test\Test.indd")
Rem Work through the document story-by-story.
For myCounter = 1 To myDocument.Stories.Count
Set myStory = myDocument.Stories.Item(myCounter)
Rem Create an object containing references to all instances of
Rem the "start tag" string ("[~" in this example).
Set myStartItems = myStory.Search("[~")
If myStartItems.Count > 0 Then
Rem Create an object containing references to all instances of
Rem the "end tag" string ("~]" in this example).
Set myEndItems = myStory.Search("~]")
If myStartItems.Count = myEndItems.Count Then
Rem Iterate through the found items backwards to avoid invalidating
Rem text object references preceding them in the story.
For myFoundItemCounter = myStartItems.Count To 1 Step -1
Set myStartItem = myStartItems.Item(myFoundItemCounter)
myStartIndex = myStartItem.Characters.Item(1).Index
Rem Get the corresponding "end" tag.
Set myEndItem = myEndItems.Item(myFoundItemCounter)
myEndIndex = myEndItem.Characters.Item(-1).Index
Rem Get a reference to the first character in the "start" tag.
Set myStartCharacter = myStory.Characters.Item(myStartIndex)
Rem Get a reference to the first character in the "end" tag.
Set myEndCharacter = myStory.Characters.Item(myEndIndex)
Rem Use the ItemByRange method to get a reference to the entire tag.
Set myFoundTag = myStory.Texts.ItemByRange(myStartCharacter, myEndCharacter).Item(1)
Rem Replace the text of the tag with the specified graphic.
myFileName = Mid(myFoundTag.Contents, 3, Len(myFoundTag.Contents) - 4)
myFoundTag.InsertionPoints.Item.Place myPath & myFileName
Rem myFoundTag.item(1).fit idFitOptions.idCenter-Content
Rem msgBox myFoundTag.contents
Next
Else
Rem We have a mismatched tag somewhere.
MsgBox "One of the stories contains a mismatched tag."
Exit For
End If
End If
Next
msgBox "Done Updating Graphics."
REM End of Script -----------------------------------
The problem is that the place method doesn't seem to work when the name is placed in a table.
Can anybody help me?
Txs,
Tijl
This is the script I use for replacing the names of the images with the place method and the real filepath and filename.
REM Start of Script -----------------------------------
Dim myCounter, myFoundCounter, myStartIndex, myEndIndex
Rem Enter the path to the folder containing the images you want to place.
myPath = "C:\test\img\press\1\"
Dim i, j, k, start, start2, MyDoc, idNothing, MyFind, Found
Set myInDesign = CreateObject("InDesign.application.CS")
Rem Clear the find/change preferences.
' clears find preferences
myindesign.FindPreferences = idNothing
myindesign.ChangePreferences = idNothing
Set myDocument = myInDesign.ActiveDocument
myDocument.save("c:\test\Test.indd")
Rem Work through the document story-by-story.
For myCounter = 1 To myDocument.Stories.Count
Set myStory = myDocument.Stories.Item(myCounter)
Rem Create an object containing references to all instances of
Rem the "start tag" string ("[~" in this example).
Set myStartItems = myStory.Search("[~")
If myStartItems.Count > 0 Then
Rem Create an object containing references to all instances of
Rem the "end tag" string ("~]" in this example).
Set myEndItems = myStory.Search("~]")
If myStartItems.Count = myEndItems.Count Then
Rem Iterate through the found items backwards to avoid invalidating
Rem text object references preceding them in the story.
For myFoundItemCounter = myStartItems.Count To 1 Step -1
Set myStartItem = myStartItems.Item(myFoundItemCounter)
myStartIndex = myStartItem.Characters.Item(1).Index
Rem Get the corresponding "end" tag.
Set myEndItem = myEndItems.Item(myFoundItemCounter)
myEndIndex = myEndItem.Characters.Item(-1).Index
Rem Get a reference to the first character in the "start" tag.
Set myStartCharacter = myStory.Characters.Item(myStartIndex)
Rem Get a reference to the first character in the "end" tag.
Set myEndCharacter = myStory.Characters.Item(myEndIndex)
Rem Use the ItemByRange method to get a reference to the entire tag.
Set myFoundTag = myStory.Texts.ItemByRange(myStartCharacter, myEndCharacter).Item(1)
Rem Replace the text of the tag with the specified graphic.
myFileName = Mid(myFoundTag.Contents, 3, Len(myFoundTag.Contents) - 4)
myFoundTag.InsertionPoints.Item.Place myPath & myFileName
Rem myFoundTag.item(1).fit idFitOptions.idCenter-Content
Rem msgBox myFoundTag.contents
Next
Else
Rem We have a mismatched tag somewhere.
MsgBox "One of the stories contains a mismatched tag."
Exit For
End If
End If
Next
msgBox "Done Updating Graphics."
REM End of Script -----------------------------------
The problem is that the place method doesn't seem to work when the name is placed in a table.
Can anybody help me?
Txs,
Tijl