14 Replies Latest reply on Nov 21, 2008 11:11 AM by (Olav_Kvern)

    Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?

      Hello Script buddies,

      Here is my script and I want to place data into the frames which I set up already in the inDesign template which loads correctly but unable to place the data into the frames, please refer to comments and if anyone can help me I will be very grateful.

      strFile = "C:\Users\dean.brooks\Documents\PoolSigns.xlsx"
      Set objExcel = CreateObject("Excel.Application")
      objExcel.Workbooks.Open strFile

      intRow = 2

      Set objSheet = objExcel.ActiveWorkbook.WorkSheets(1)

      ' Cycle through cells in Pool Sign Schedule to retreive data
      Do Until objSheet.Cells(intRow, 3).Value = ""
      PoolSignScheduleSignNo = Trim(objSheet.Cells(intRow, 1).Value)
      PoolSignScheduleTemplate = Trim(objSheet.Cells(intRow, 3).Value)
      PoolSignScheduleDepth = Trim(objSheet.Cells(intRow, 5).Value)
      PoolSignScheduleWarningFile = Trim(objSheet.Cells(intRow, 7).Value)
      PoolSignScheduleWarningText = Trim(objSheet.Cells(intRow, 8).Value)
      PoolSignScheduleRegFile = Trim(objSheet.Cells(intRow, 10).Value)
      PoolSignScheduleRegText = Trim(objSheet.Cells(intRow, 11).Value)

      ' Open InDesign Template that corresponds to PoolSignScheduleTemplate
      Set myInDesign = CreateObject("InDesign.Application.CS3")
      Set myDocument = myInDesign.Open(PoolSignScheduleTemplate)


      'Frames, these commands won't work, can someone please help??

      Set DepthMarker = myDocument.Textframes.Item
      DepthMarker.Contents = PoolSignScheduleDepth
      Set WarningText = myDocument.Textframes.Item
      WarningText.Contents = PoolSignScheduleWarningText
      Set WarningSymbol = myDocument.Graphicframes.Item
      WarningSymbol.Contents = PoolSignScheduleWarningFile
      Set RegText = myDocument.Textframes.Item
      RegText.Contents= PoolSignScheduleRegText


      ' Save InDesign File to C:\ to be moved manually later to appropriate location
      myDocument.Save("C:\Pools\PoolSign\PoolSignScheduleSignNo.indd")
      myDocument.Close

      intRow = intRow + 1
      Loop

      objExcel.Quit

      WScript.Quit
        • 1. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
          Level 1
          Hi Robert,

          Your problem starts here:

          Set DepthMarker = myDocument.Textframes.Item
          

          ...which item? Item takes either an integer (the index of the item) or a string (the contents of the label property, if any).

          Next, however, is that you should be more specific about *where* the text frame is in the document. What page or spread is it on? Let's say that the frame "DepthMarker" is on page 1:

          Set DepthMarker = myDocument.Pages.Item(1).TextFrames.Item(1)
          

          If there's only one frame on that page, you're in great shape. If not, you need to come up with some way to differentiate one frame from another. Script labels are a great way to do this. Let's say you've used the Script Label panel to add the label "DepthMarker" to the relevant frame on page 1, and added the label "WarningText" to another frame. In that case, you'd use something like this:

          Set DepthMarker = myDocument.Pages.Item(1).TextFrames.Item("DepthMarker")(0)
          
          Set WarningText = myDocument.Pages.Item(1).TextFrames.Item("WarningText")(0)

          ...When you use a string to refer to a page item by its label, InDesign returns an array, so you need to get the first item in the array (assuming that there's only one page item on the page with that label).

          Hope this makes sense! I'm typing it off the top of my head because I have to go speak at a conference tomorrow and am short on time--but it should get you pointed in the right direction.

          Thanks,

          Ole
          • 2. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
            Level 1
            Thanks Ole,

            But there is 4 frames on one page and I labeled them with the script label, and I tried your advice but it still doesn't work.
            Can you please tell me the how I could use, these commands with 4 frames all on one page as I tried, (see below) but it didnt work??

            Set DepthMarker = myDocument.Pages.Item(1).Textframes.Item("DepthMarker")(0)
            DepthMarker.Contents = PoolSignScheduleDepth
            Set WarningText = myDocument.Pages.Item(1).Textframes.Item("WarningText")(0)
            WarningText.Contents = PoolSignScheduleWarningText
            Set WarningSymbol = myDocument.Pages.Item(1).Graphicframes.Item("WarningSymbol")(0)
            WarningSymbol.Contents = PoolSignScheduleWarningFile
            Set RegText = myDocument.Pages.Item(1).Textframes.Item("RegText")(0)
            RegText.Contents= PoolSignScheduleRegText

            Thanks mate
            • 3. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
              (Simon_Paterson) Level 1
              I'm not entirely sure, Robert, because I'm not a VBScript guy, but just something you could try in case it is simple: remove the (0) from the end of your 'Item' call. If there is only 1 item with that label, then perhaps VBScript (like Javascript) is returning a single item rather than an array, which makes the '(0)' unnecessary.

              And please, NO SHOUTING :)
              • 4. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
                Level 1
                Thanks Simon that actually worked for the Text Frames, but not the graphic frame.

                Got any ideas how I can fix this graphic frame??

                Set WarningSymbol = myDocument.Pages.Item(1).Graphicframes.Item("WarningSymbol")
                WarningSymbol.Contents = PoolSignScheduleWarningFile
                • 5. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
                  (Simon_Paterson) Level 1
                  I'm not actually a VBScript guy, so I can't say for sure, but I don't think there is a Graphicsframes object? There doesn't appear to be in Javascript. You may need to refer to this page item as a rectangle or something like that.

                  Run the following piece of Javascript while you have the item "WarningSymbol" selected:

                  >var myItem = app.documents[0].selection[0];
                  alert("Page item type: " + myItem.constructor.name);

                  If you get "Rectangle" as the type, then you'll probably need to change the line to read:

                  >Set WarningSymbol = myDocument.Pages.Item(1).Rectangles.Item("WarningSymbol")

                  As far as I know, you can't set the contents of a graphic frame to a picture file, you have to 'place' it. So the command would be something like:

                  >WarningSymbol.Place(PoolSignScheduleWarningFile)

                  Please excuse me if I've got the actual VBScript snippets wrong. But hopefully this will point you in the right direction.

                  Good luck.
                  • 6. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
                    Level 1
                    Thanks Simon, that actually worked and pasted the picture onto the frame.

                    But I am still getting an error message, 'The requested member of the collection does not exist'
                    Code: 800A770B
                    Source: C:\Program Files\Adobe\Adobe InDesign CS3\InDesign.exe

                    How do I make it go away?

                    P.S
                    I really appreciate your support thanks again Simon & Olav

                    Cheers
                    • 7. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
                      (Simon_Paterson) Level 1
                      I'm glad that I could help, but unfortunately I have to admit that I'm out of my depth with this one. I don't know about VBScript error messages so I'm unsure as to what it could be.

                      Do you have the ability for line-by-line code execution? Can you see exactly what line this is happening on?

                      If not, can you edit the script to just do one or two operations at a time and keep adding until the error message appears?
                      • 8. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
                        Level 1
                        Set RegText = myDocument.Pages.Item(1).Textframes.Item("RegText")
                        RegText.Contents = PoolSignScheduleRegText
                        Set RegSymbol =
                        myDocument.Pages.Item(1).Rectangles.Item("RegSymbol")
                        RegSymbol.Place(PoolSignScheduleRegFile)

                        It says line 34 char 2 so either one of these commands, but I have no idea why that error message is coming up as the commands look right, and its weird because the script generates the document,
                        Do you know why that error message is coming up??

                        Cheers
                        • 9. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
                          (Simon_Paterson) Level 1
                          Just out of curiosity, is the 'Set RegSymbol = myDocument...' set on one line? Does whitespace matter with VBScript? If there is a return after the equal sign in that line then remove it and see if this gets rid of the error.

                          To be honest, I'm reaching here, so if any body has some more knowledge of VBScript and they can help Robert, I think his problem is almost solved.
                          • 10. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
                            Level 1
                            Yes it is set on one line, I just couldn't fit all that text on one line.
                            I have no idea why that error message is appearing??

                            Thank you
                            • 11. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
                              Level 1
                              The script is creating pool signs and there are four frames and some of the templates only use 2 frames, could it be when these templates are called that are not using all 4 frames, are contributing to this error??

                              When the script is passing data to 4 frames to templates that only have 2 frames, it wont allow it.

                              Is there a command that can allow this??

                              Cheers
                              • 12. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
                                Level 1
                                I tested it and that was the reason, I don't want to create multiple scripts is there a command that can allow this exemption to disregard the additional frames if its calling templates not using all 4 frames??
                                • 13. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
                                  Level 1
                                  Case closed I used an If statement, and the script is working without any bugs.
                                  Thank you Simon and Olav and all this Adobe Forum,

                                  I am very proud to be using the Adobe CS suit

                                  Cheers
                                  • 14. Re: Adding Data into text and graphic frames - PLEASE CAN SOMEONE HELP?
                                    Level 1
                                    Hi Robert,

                                    Glad it's working for you--sorry I was out of town and couldn't help get it figured out. Thanks, Simon for stepping in!

                                    Just a note about VBScript/JS differences--overall, the models are the same. Capitalization is different (it matters in JS, but VBScript doesn't care), and the JS "remove" method is "delete" in VBScript. The only other thing is that JS arrays and collections start at 0; in VBScript, collections start at 1 and arrays start at 0.

                                    Thanks,

                                    Ole