9 Replies Latest reply on Sep 4, 2009 8:11 AM by klaus musset

    AlternatingFills -> VBA

    klaus musset

      Hello,

      I am using the script of the turorial for alternating rows and get an Error.

      I use:

          myTable.alternatingFills = idAlternatingFillsTypes.idAlternatingRows
          myTable.startRowFillColor = myDocument.swatches.Item("DGC1_446a")    <- here is the Error
          myTable.startRowFillTint = 60
          myTable.endRowFillColor = myDocument.swatches.Item("DGC1_446b")
          myTable.endRowFillTint = 50

       

      and get the message: Error 13, Type mismatch.

       

      if I iterate thru the rows with the following code, everything works fine, it's just slow:

           For k = 1 To myTable.Rows.Count

              If k Mod 2 = 0 Then
                  myTable.Rows.Item(k).FillColor = myDocument.Swatches.Item("DGC1_446a")
                  myTable.Rows.Item(k).FillTint = 40
              End If

           next k

       

      Where is the problem

      Thanx for helping

      Klaus

        • 1. Re: AlternatingFills -> VBA
          Harbs. Level 6

          What happens if you first create a reference  to the swatch?

           

          Harbs

          http://www.in-tools.com

          Innovations in Automation

          • 2. Re: AlternatingFills -> VBA
            klaus musset Level 1

            Hi Harbs,

            thanx for the answer.

            Do you mean:

             

                myAddColor myDocument, "DGC1_446a", idColorModel.idProcess, Array(0, 100, 0, 50)
                myAddColor myDocument, "DGC1_446b", idColorModel.idProcess, Array(100, 0, 50, 0)

             

            thats done.

            VBA doesn't seem to accept this value -> idColorModel.idProcess

             

            By the way, I'm just starting to script ID. It's hard to get any documentation about it.

            Just the sample script from Adobe.

            A lot of stuff is not explained.

            There is no reference, so it's more a hit and miss situation.

             

            By the way:

            How do you adjust a textframe to the table in the textframe?

            I did it by calculation or is there a shortcut to it?

             

            Thanx again

            Klaus

            • 3. Re: AlternatingFills -> VBA
              Steven.. Level 3

              If you are using VBA and not VBS then you can't use

               

              myTable.alternatingFills = idAlternatingFillsTypes.idAlternatingRows
              

               

              you would have to use the value of the enum

               

              myTable.alternatingFills = 1097618039
              

               

               

              Steven

              • 4. Re: AlternatingFills -> VBA
                klaus musset Level 1

                Thanx Steve.

                I tried it. That is not the problem, that works fine.

                The error is created in the line after:

                -> myTable.StartRowFillColor = myDocument.Swatches.Item("DGC1_446a")

                -> Run-time error '13': Type mismatch

                I my script it works on 1 line on the other it doesn't (see below). The swatches are all on CMYK.

                 

                I used the code from the sample script: AlternatingRows.vbs

                This script is not running too?!?

                I guess there is a problem with the colormodel -> RGB vs. CMYK.

                I didn't find any info about that.

                 

                Thanks for helping

                Klaus

                 

                This is the complete part of my script:

                    myAddColor myDocument, "RewaldFarbe", idColorModel.idProcess, Array(19.45, 1.68, 0, 0)

                 

                    myAddColor myDocument, "DGC1_446a", idColorModel.idProcess, Array(0, 100, 0, 50)
                    myAddColor myDocument, "DGC1_446b", idColorModel.idProcess, Array(100, 0, 50, 0)

                 

                    If myTable.Rows.Item(1).RowType <> idRowTypes.idHeaderRow Then
                        myTable.Rows.Item(1).RowType = idRowTypes.idHeaderRow
                    End If
                    For k = 1 To myTable.Rows.Count
                        myTable.Rows.Item(k).MinimumHeight = 2.2
                        myTable.Rows.Item(k).LeftInset = 0
                        myTable.Rows.Item(k).RightInset = 0
                        myTable.Rows.Item(k).TopInset = 0.9
                        myTable.Rows.Item(k).BottomInset = 1
                        If k Mod 2 = 0 Then
                            myTable.Rows.Item(k).FillColor = myDocument.Swatches.Item("RewaldFarbe")  -> This works
                            myTable.Rows.Item(k).FillTint = 100
                        End If
                    Next k
                    myTable.AlternatingFills = 1097618039
                    myTable.StartRowFillColor = myDocument.Swatches.Item("DGC1_446a") -> Here it stops with error
                    myTable.StartRowFillTint = 60
                    myTable.EndRowFillColor = myDocument.Swatches.Item("DGC1_446b")
                    myTable.EndRowFillTint = 50

                • 5. Re: AlternatingFills -> VBA
                  Harbs. Level 6

                  Create a referrence to myDocument.Swatches.Item("DGC1_446a") in a variable "mySwatch" and then try:

                   

                  myTable.StartRowFillColor = mySwatch

                  • 6. Re: AlternatingFills -> VBA
                    Steven.. Level 3

                    I don't know the issue, it works for me. Follow harbs advice so you can break down the error one more step

                    One interesting thing is that startRowFillColor takes a swatch

                    Property StartRowFillColor As Swatch
                        Member of InDesign.TableStyle
                        The fill color, specified as a swatch (color, gradient, tint, or mixed ink), of rows in the first alternating fills group. Note: Valid when alternating fills are defined for table rows. 
                    
                    

                     

                    while FillColor takes a variant

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

                     

                     

                    Not that it should make a difference

                    • 7. Re: AlternatingFills -> VBA
                      klaus musset Level 1

                      Thanks, you're actually pinpointing the problem:

                       

                      typeName(myDocument.Swatches.Item("None")) 

                      return 'Swatch'

                       

                      All other items in the swatch panel fx:

                      typeName(myDocument.Swatches.Item("Black")) 

                      return 'Color' or 'Gradient' - depending on how the swatch is designed.

                      Means:

                      myTable.StartRowFillColor = typeName(myDocument.Swatches.Item("None"))

                      Works fine, but

                       

                      Dim mySwatch as InDesign.Swatches
                      set mySwatch = typeName(myDocument.Swatches.Item("Black")) 

                       

                      Returns an error because an object is expected.

                      This is strange because 'Swatches.Item("Whatever")' should be a swatch, shouldn't it ?!?

                      The only item in my swatch collection I found to be a swatch was

                       

                      myDocument.Swatches.Item("None")

                       

                      How can you see in the swatch panel, what is a swatch and what isn't?

                      I didn't find a way to add any other items in the swatch panel to the swatch collection.

                      Is there a bug or is there any other way to solve that mystery.

                      By the way: I'm working with the German installation of CS4, but that shouldn't make a difference?!?

                      Thanks for your help

                      Klaus

                      • 8. Re: AlternatingFills -> VBA
                        Harbs. Level 6

                        You don't add swatches. You add colors. Once a named color is added it 

                        is a swatch. Kind of confusing, but that's how it works...

                         

                        Harbs

                        • 9. Re: AlternatingFills -> VBA
                          klaus musset Level 1

                          But here seems to be the problem

                           

                          Dim mySwatch1 As InDesign.Swatch
                          Set mySwatch1 = myDocument.Swatches.Item("Black")
                          

                          creates the error 13: Type mismatch

                          Checking

                          typename(myDocument.Swatches.Item("Black")

                          I get 'Color'

                          But as Steven stated

                           

                          Property StartRowFillColor As Swatch
                              Member of InDesign.TableStyle
                              The fill color, specified as a swatch (color, gradient, tint, or mixed ink), of rows in the first alternating fills group. Note: Valid when alternating fills are defined for table rows. 

                           

                           

                          myTable.StartRowFillColor = myDocument.Swatches.Item("Black")
                          

                           

                          Doesn't get accepted.

                          As it says: 'The fill color, specified as a swatch'

                          Q: How do you specify fx: 'myDocument.Swatches.Item("Black")' as a swatch?

                          Thanx

                          Klaus