0
Finding File Name And Using It To Place The Graphic Using VBscript
New Here
,
/t5/indesign-discussions/finding-file-name-and-using-it-to-place-the-graphic-using-vbscript/td-p/1142705
Mar 05, 2008
Mar 05, 2008
Copy link to clipboard
Copied
I'm trying to find a file name (example, <place:E:\logo.tif>) in each text frame if it's there, then remove the text from the frame and then place the file in the frame. This is to get around the feature missing from InDesign that is in PageMaker that allowed you to import inline graphics using tagged text. Below is what I have come up with so far. The file name is currently hard coded in the example below.
Thanks,
Archie
For I = 1 to cInt(myMountNumber)
Set myTextFrames = myDocument.TextFrames
Set myCurrentFrame = myTextFrames.Item(I)
If myCurrentFrame.Texts.ItemByRange (1,7).Contents = "<Place:" Then
Set myLastCharacter = myCurrentFrame.Characters.Item(-2)
myCurrentFrame.Texts.ItemByRange (1,myLastCharacter).Item(1).Contents = ""
myCurrentFrame.InsertionPoints.Item(1).Place ("E:\sxs\pm65\Sundco.jpg")
myCurrentFrame.Fit idFitOptions.idProportionally
End If
Next
Thanks,
Archie
For I = 1 to cInt(myMountNumber)
Set myTextFrames = myDocument.TextFrames
Set myCurrentFrame = myTextFrames.Item(I)
If myCurrentFrame.Texts.ItemByRange (1,7).Contents = "<Place:" Then
Set myLastCharacter = myCurrentFrame.Characters.Item(-2)
myCurrentFrame.Texts.ItemByRange (1,myLastCharacter).Item(1).Contents = ""
myCurrentFrame.InsertionPoints.Item(1).Place ("E:\sxs\pm65\Sundco.jpg")
myCurrentFrame.Fit idFitOptions.idProportionally
End If
Next
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Beginner
,
/t5/indesign-discussions/finding-file-name-and-using-it-to-place-the-graphic-using-vbscript/m-p/1142706#M339521
Mar 06, 2008
Mar 06, 2008
Copy link to clipboard
Copied
' For I = 1 to cInt(myMountNumber)<br />For I = 1 to myDoc.TextFrames.Counts<br />' I think your myMountNumber is equal to TextFramesCount<br /><br />' Set myTextFrames = myDocument.TextFrames<br />' Set myCurrentFrame = myTextFrames.Item(I)<br />' you don't need to get reference to ALL TextFrames in EACH iteration<br /><br />Set myCurrentFrame = myDocument.TextFrames.Item(I)<br />' get reference to Ith TextFrame in document<br /><br />' If myCurrentFrame.Texts.ItemByRange (1,7).Contents = "<Place:" Then<br />If left(myCurrentFrame.Texts.Item(1).Contents,7) = "<Place:" Then<br />' looks better and should be faster<br /><br /> ' Set myLastCharacter = myCurrentFrame.Characters.Item(-2)<br /> ' myCurrentFrame.Texts.ItemByRange (1,myLastCharacter).Item(1).Contents = ""<br /> ' you don't need these lines - you will delete contents in PLACE line<br /> <br /> ' myCurrentFrame.InsertionPoints.Item(1).Place ("E:\sxs\pm65\Sundco.jpg")<br /><br /> myFile = Mid(myCurrentFrame.Texts.Item(1),8)<br /> ' get all after "<Place:"<br /><br /> myFile = Split(myFile,">")(0) ' get all to ">"<br /> ' small trick 😉 when split - get array - but we can use (0) to refere to first element<br /><br /> myCurrentFrame.Texts.Item(1).Place(myFile)<br /> myCurrentFrame.Fit idFitOptions.idProportionally<br />End If<br /><br />Next<br /><br />and I don't think that iterating TextFrames collection is good way ...<br />you should iterate Stories collection and refer to first TextFrame - unles you are sure what you are doing 😉 and you have Stories where each TextFrame will have image inside ...<br /><br />robin<br /><br />-- <br />www.adobescripts.com
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Archie_Tucker_
AUTHOR
New Here
,
/t5/indesign-discussions/finding-file-name-and-using-it-to-place-the-graphic-using-vbscript/m-p/1142707#M339523
Mar 06, 2008
Mar 06, 2008
Copy link to clipboard
Copied
Hi Robin,
The reason for the myMountNumber is the script will need to only loop thru part of the document (the document will contain threaded frames for batch number, date, time, etc. in addition to the rubber stamps). Below is what I currently have after I added your changes, but the one problem is the graphic is also removing the next frame insert character that follows the file name. What would be the change to fix that issue?
Thanks,
Archie
Rem Graphic Test
Dim myInDesign
Set myInDesign = CreateObject("InDesign.Application.CS3")
Set FileSys = CreateObject("Scripting.FileSystemObject")
Rem SET VALUES
Rem ----------
Dim myMountSize
Dim myTemplateFolder
REM LINE:13
myMountNumber = "3"
Set myDocument = myInDesign.ActiveDocument
Rem LOOP
Rem ----
For I = 1 to cInt(myMountNumber)
Set myCurrentFrame = myDocument.TextFrames.Item(I)
MsgBox myCurrentFrame.Texts.Item(1).Contents
REM LINE: 26
If left(myCurrentFrame.Texts.Item(1).Contents,7) = "<place=" Then
myFile = Mid(myCurrentFrame.Texts.Item(1).Contents,8)
myFile = Split(myFile,">")(0)' get all to ">"
myCurrentFrame.Texts.Item(1).Place (myFile)
myCurrentFrame.Fit idFitOptions.idProportionally
End If
Next
MsgBox "Complete:"
The reason for the myMountNumber is the script will need to only loop thru part of the document (the document will contain threaded frames for batch number, date, time, etc. in addition to the rubber stamps). Below is what I currently have after I added your changes, but the one problem is the graphic is also removing the next frame insert character that follows the file name. What would be the change to fix that issue?
Thanks,
Archie
Rem Graphic Test
Dim myInDesign
Set myInDesign = CreateObject("InDesign.Application.CS3")
Set FileSys = CreateObject("Scripting.FileSystemObject")
Rem SET VALUES
Rem ----------
Dim myMountSize
Dim myTemplateFolder
REM LINE:13
myMountNumber = "3"
Set myDocument = myInDesign.ActiveDocument
Rem LOOP
Rem ----
For I = 1 to cInt(myMountNumber)
Set myCurrentFrame = myDocument.TextFrames.Item(I)
MsgBox myCurrentFrame.Texts.Item(1).Contents
REM LINE: 26
If left(myCurrentFrame.Texts.Item(1).Contents,7) = "<place=" Then
myFile = Mid(myCurrentFrame.Texts.Item(1).Contents,8)
myFile = Split(myFile,">")(0)' get all to ">"
myCurrentFrame.Texts.Item(1).Place (myFile)
myCurrentFrame.Fit idFitOptions.idProportionally
End If
Next
MsgBox "Complete:"
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explorer
,
/t5/indesign-discussions/finding-file-name-and-using-it-to-place-the-graphic-using-vbscript/m-p/1142708#M339525
Mar 06, 2008
Mar 06, 2008
Copy link to clipboard
Copied
Hi Archie,
You might want to take a look at the example script ReplaceTextWithGraphic.vbs that's in the archive of scripts that go with the Scripting Guide--you can find the archive at:
http://www.adobe.com/products/indesign/scripting/index.html
Click the Scripting Resources tab to get to the scripting info. The Zip archive associated with the Scripting Guide contains over 200 VBScript examples.
Thanks,
Ole
You might want to take a look at the example script ReplaceTextWithGraphic.vbs that's in the archive of scripts that go with the Scripting Guide--you can find the archive at:
http://www.adobe.com/products/indesign/scripting/index.html
Click the Scripting Resources tab to get to the scripting info. The Zip archive associated with the Scripting Guide contains over 200 VBScript examples.
Thanks,
Ole
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Archie_Tucker_
AUTHOR
New Here
,
/t5/indesign-discussions/finding-file-name-and-using-it-to-place-the-graphic-using-vbscript/m-p/1142709#M339527
Mar 06, 2008
Mar 06, 2008
Copy link to clipboard
Copied
Hi Ole,
I looked at that script, but I couldn't find what I was looking for. I made the changes below and now it is working, not sure if it's the best method. For the test I created 3 text frames, starting from the top of the page, then I created a thread, beginning with the frame at the top. When I put a message box in the loop I found out that it was starting from the last frame. How can I control the frame order when I create a template?
Thanks,
Archie
Rem Graphic Test
Dim myInDesign
Set myInDesign = CreateObject("InDesign.Application.CS3")
Set FileSys = CreateObject("Scripting.FileSystemObject")
Rem SET VALUES
Rem ----------
Dim myMountSize
Dim myTemplateFolder
myMountNumber = "3"
Set myDocument = myInDesign.ActiveDocument
Rem LOOP
Rem ----
For I = 1 to cInt(myMountNumber)
Set myCurrentFrame = myDocument.TextFrames.Item(I)
If left(myCurrentFrame.Texts.Item(1).Contents,7) = "<place=" Then
myFile = Mid(myCurrentFrame.Texts.Item(1).Contents,8)
myFile = Split(myFile,">")(0)' get all to ">"
Set myLastCharacter = myCurrentFrame.Characters.Item(-2)
MyCurrentFrame.Texts.ItemByRange (1,myLastCharacter).Item(1).Contents=""
myCurrentFrame.InsertionPoints.Item(1).Place (myFile)
myCurrentFrame.Fit idFitOptions.idProportionally
End If
Next
I looked at that script, but I couldn't find what I was looking for. I made the changes below and now it is working, not sure if it's the best method. For the test I created 3 text frames, starting from the top of the page, then I created a thread, beginning with the frame at the top. When I put a message box in the loop I found out that it was starting from the last frame. How can I control the frame order when I create a template?
Thanks,
Archie
Rem Graphic Test
Dim myInDesign
Set myInDesign = CreateObject("InDesign.Application.CS3")
Set FileSys = CreateObject("Scripting.FileSystemObject")
Rem SET VALUES
Rem ----------
Dim myMountSize
Dim myTemplateFolder
myMountNumber = "3"
Set myDocument = myInDesign.ActiveDocument
Rem LOOP
Rem ----
For I = 1 to cInt(myMountNumber)
Set myCurrentFrame = myDocument.TextFrames.Item(I)
If left(myCurrentFrame.Texts.Item(1).Contents,7) = "<place=" Then
myFile = Mid(myCurrentFrame.Texts.Item(1).Contents,8)
myFile = Split(myFile,">")(0)' get all to ">"
Set myLastCharacter = myCurrentFrame.Characters.Item(-2)
MyCurrentFrame.Texts.ItemByRange (1,myLastCharacter).Item(1).Contents=""
myCurrentFrame.InsertionPoints.Item(1).Place (myFile)
myCurrentFrame.Fit idFitOptions.idProportionally
End If
Next
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Beginner
,
/t5/indesign-discussions/finding-file-name-and-using-it-to-place-the-graphic-using-vbscript/m-p/1142710#M339529
Mar 06, 2008
Mar 06, 2008
Copy link to clipboard
Copied
change line:<br /><br /> Set myLastCharacter = myCurrentFrame.Characters.Item(-2)<br /><br />to:<br /><br /> Set myLastCharacter = myCurrentFrame.Characters.Item(7 + Len(myFile) + 1)<br /><br />7 - lenght of "<place="<br />1 - lenght of ">"<br /><br />robin<br /><br />-- <br />www.adobescripts.com
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Archie_Tucker_
AUTHOR
New Here
,
LATEST
/t5/indesign-discussions/finding-file-name-and-using-it-to-place-the-graphic-using-vbscript/m-p/1142711#M339531
Mar 07, 2008
Mar 07, 2008
Copy link to clipboard
Copied
Hi Robin,
Thanks for your help. I below is my current version. My next issues is if the graphic is larger than the frame. In this case I need the graphic to be reduced to fit in the frame. The fit commands do not seem to work, I do not have them in the correct format. If I make a frame contents set for a graphic (not using a script) I can use the fit commands on the menu to work correctly. Would it make sense to create a new frame (same size and position) set for graphic content and place the image in that frame?
Thanks,
Archie
Dim myInDesign
Set myInDesign = CreateObject("InDesign.Application.CS3")
Set FileSys = CreateObject("Scripting.FileSystemObject")
Rem SET VALUES
Rem ----------
Dim myMountSize
Dim myTemplateFolder
myMountNumber = "3"
Set myDocument = myInDesign.ActiveDocument
myPlaceGraphics myDocument, myMountNumber
MsgBox "Completed:"
Rem PLACE GRAPHICS
Rem --------------
Function myPlaceGraphics (myDocument, myMountNumber)
For I = 1 to cInt(myMountNumber)
REM For I = 4 to myDocument.TextFrames.Count
Set myCurrentFrame = myDocument.TextFrames.Item(I)
myCharacterCount = MyCurrentFrame.Characters.Count
If myCharacterCount > 0 Then
If left(myCurrentFrame.Texts.Item(1).Contents,7) = "[place=" Then
myFile = Mid(myCurrentFrame.Texts.Item(1).Contents,8)
myFile = Split(myFile,"]")(0)' get all to "]"
Set myLastCharacter = myCurrentFrame.Characters.Item(7 + Len(myFile) + 1)
myCurrentFrame.Texts.ItemByRange (1,myLastCharacter).Item(1).Contents=""
myCurrentFrame.InsertionPoints.Item(1).Place (myFile)
myCurrentFrame.Fit idFitOptions.idProportionally
myCurrentFrame.Fit idFitOptions.idContentToFrame
End If
End If
Next
End Function
Thanks for your help. I below is my current version. My next issues is if the graphic is larger than the frame. In this case I need the graphic to be reduced to fit in the frame. The fit commands do not seem to work, I do not have them in the correct format. If I make a frame contents set for a graphic (not using a script) I can use the fit commands on the menu to work correctly. Would it make sense to create a new frame (same size and position) set for graphic content and place the image in that frame?
Thanks,
Archie
Dim myInDesign
Set myInDesign = CreateObject("InDesign.Application.CS3")
Set FileSys = CreateObject("Scripting.FileSystemObject")
Rem SET VALUES
Rem ----------
Dim myMountSize
Dim myTemplateFolder
myMountNumber = "3"
Set myDocument = myInDesign.ActiveDocument
myPlaceGraphics myDocument, myMountNumber
MsgBox "Completed:"
Rem PLACE GRAPHICS
Rem --------------
Function myPlaceGraphics (myDocument, myMountNumber)
For I = 1 to cInt(myMountNumber)
REM For I = 4 to myDocument.TextFrames.Count
Set myCurrentFrame = myDocument.TextFrames.Item(I)
myCharacterCount = MyCurrentFrame.Characters.Count
If myCharacterCount > 0 Then
If left(myCurrentFrame.Texts.Item(1).Contents,7) = "[place=" Then
myFile = Mid(myCurrentFrame.Texts.Item(1).Contents,8)
myFile = Split(myFile,"]")(0)' get all to "]"
Set myLastCharacter = myCurrentFrame.Characters.Item(7 + Len(myFile) + 1)
myCurrentFrame.Texts.ItemByRange (1,myLastCharacter).Item(1).Contents=""
myCurrentFrame.InsertionPoints.Item(1).Place (myFile)
myCurrentFrame.Fit idFitOptions.idProportionally
myCurrentFrame.Fit idFitOptions.idContentToFrame
End If
End If
Next
End Function
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

