2 Replies Latest reply on May 16, 2008 3:02 PM by (Archie_Tucker)

    VB CS3 Placing Images On Multiple Pages

      The script below works correctly on the first page, but not on pages after that. The script looks for "[place=" to get the file name, removes the text, but not the next frame character, and places the image file. I have not been able to find the error in my ways, any help would be greatly appreciated.
      Thanks,
      Archie

      Rem PLACE GRAPHICS
      Rem --------------
      Function myPlaceGraphics (myDocument)

      For I = 1 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 myGraphic = myDocument.Pages.Item(1).Place (myFile)
      Set myGraphic = myGraphic.Item(1)
      Set myRectangle = myGraphic.Parent
      myGraphicBounds = myRectangle.GeometricBounds
      myGraphicWidth = myGraphicBounds(3) - myGraphicBounds(1)
      myGraphicHeight = myGraphicBounds(2) - myGraphicBounds(0)
      Set myLastCharacter = myCurrentFrame.Characters.Item(7 + Len(myFile) + 1)
      myCurrentFrame.Texts.ItemByRange (1,myLastCharacter).Item(1).Contents=""
      myFrameBounds = myCurrentFrame.GeometricBounds
      myFrameWidth = myFrameBounds(3) - myFrameBounds(1)
      myFrameHeight = myFrameBounds(2) - myFrameBounds(0)
      myRectangle.GeometricBounds = myFrameBounds
      myRectangle.StrokeWeight = 0
      myRectangle.FillColor = myDocument.Swatches.Item("None")
      If myGraphicWidth > myFrameWidth or myGraphicHeight > myFrameHeight Then
      myRectangle.Fit (idFitOptions.idContentToFrame)
      myRectangle.Fit (idFitOptions.idProportionally)
      End If
      myRectangle.Fit (idFitOptions.idCenterContent)
      myRectangle.SendToBack
      End If
      End If

      Next
        • 1. Re: VB CS3 Placing Images On Multiple Pages
          Level 1
          Hi Archie,

          It looks to me like you're placing all of the graphics on the first page:

          Set myGraphic = myDocument.Pages.Item(1).Place (myFile)

          I think what you want is to get the page containing the relevant text frame, then tell that page to place the graphic. As long as the text frame is not within a group, pasted into text as an inline/anchored frame, or inside another page item, the parent of the text frame will be the page. If that's the case, then something like this will work:

          Rem Given a text frame "myTextFrame"
          Set myPage = myTextFrame.Parent

          ...and then you should be good to go.

          Thanks,

          Ole
          • 2. Re: VB CS3 Placing Images On Multiple Pages
            Level 1
            Thanks! Below is what I have now, it seems to work correctly, not sure if it's exactly what you intended. I have another page related question.

            How would I find the last page of placed text in a document (treaded text frames) so that I can use it to set the page range in print perferences? The document has 20 pages of frames, but each time it's used, the number of pages with data can be different. If I should start a new post of this please let me know.
            Thanks,
            Archie

            Rem PLACE GRAPHICS
            Rem --------------
            Function myPlaceGraphics (myDocument)

            For I = 1 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=""
            Set myGraphic = myCurrentFrame.Parent.Place (myFile)
            Set myGraphic = myGraphic.Item(1)
            Set myRectangle = myGraphic.Parent
            myGraphicBounds = myRectangle.GeometricBounds
            myGraphicWidth = myGraphicBounds(3) - myGraphicBounds(1)
            myGraphicHeight = myGraphicBounds(2) - myGraphicBounds(0)

            myFrameBounds = myCurrentFrame.GeometricBounds
            myFrameWidth = myFrameBounds(3) - myFrameBounds(1)
            myFrameHeight = myFrameBounds(2) - myFrameBounds(0)
            myRectangle.GeometricBounds = myFrameBounds
            myRectangle.StrokeWeight = 0
            myRectangle.FillColor = myDocument.Swatches.Item("None")
            If myGraphicWidth > myFrameWidth or myGraphicHeight > myFrameHeight Then
            myRectangle.Fit (idFitOptions.idContentToFrame)
            myRectangle.Fit (idFitOptions.idProportionally)
            End If
            myRectangle.Fit (idFitOptions.idCenterContent)
            myRectangle.SendToBack
            End If
            End If

            Next

            End Function