4 Replies Latest reply on Sep 29, 2008 4:54 PM by (Archie_Tucker)

    Change Graphic Color using VBscript

      How do you change the color of a graphic (Using InDesign it requires the Direct Selection Tool)? I have found examples for changing the color for text (fillcolor, strokecolor), but that doesn't work with a graphic.
      Thanks,
      Archie
        • 1. Re: Change Graphic Color using VBscript
          Level 1
          for Rectangle:

          Property FillColor As Variant
          Member of InDesign.Rectangle
          The swatch (color, gradient, tint, or mixed ink) applied to the to fill the Rectangle. as Swatch or String

          and

          myRect.FillColor = myDoc.Colors.Item("Red")

          or

          myRect.FillColor = myDoc.Swatches.Item("Red")

          or

          myRect.FillColor = myDoc.Tints.Item("Red 50")

          or

          myRect.FillColor = myDoc.Gradients.Item("Red-Blue")

          robin

          --
          www.adobescripts.com
          • 2. Re: Change Graphic Color using VBscript
            Level 1
            Hi Robin,
            The FillColor changes the color of the background in the rectangle, instead of the graphic (tiff file). Is there a different property to just change the color of the graphic?
            Thanks,
            Archie
            • 3. Re: Change Graphic Color using VBscript
              Level 1
              sorry - I misunderstand you :)

              you can change only color of bitmap graphics - B/W - not CMYK/RGB/LAB

              Property FillColor As Variant
              Member of InDesign.Image
              The swatch (color, gradient, tint, or mixed ink) applied to the to fill the Image. as Swatch or String

              I can't test this right now, but try this (I don't know if you will get error message for images other than B/W bitmap):

              myRect.AllGraphics.FillColor = myDoc.Swatches.Item("Red")

              robin

              --
              www.adobescripts.com
              • 4. Re: Change Graphic Color using VBscript
                Level 1
                Hi Robin,
                I don't know why this works now, but I changed my test script to place the image in the script, then change the color and it works (which is more like the way I'm going to use it in production). With my first test I was trying to change the color of the tif file that I had manually placed on the page.
                Thanks,
                Archie

                Below is test script that works.

                Rem ColorTest.vbs

                Set myInDesign = CreateObject("InDesign.Application.CS3")
                Set myDocument = MyInDesign.ActiveDocument

                myFile = "X:\SCANNED_ART\1659418-100.tif"

                Rem Get Color of Text
                Set myTextFrame = myDocument.textFrames.item("text")
                myTextContents = myTextFrame.Texts.Item(1).Contents
                myTextColor = myTextFrame.Texts.Item(1).fillColor

                Rem Place Graphic
                Set myGraphic = myDocument.Pages.Item(1).Place (myFile)
                Set myGraphic = myGraphic.Item(1)
                MsgBox "Graphic Placed"

                Rem Set Color
                myGraphic.fillColor = myDocument.Colors.Item(myTextColor)