5 Replies Latest reply on Jun 3, 2010 4:27 AM by Kasyan Servetsky

    Determining if a label exists


      Hey all.

      I'm new to InDesign, so please bear with me if my teminology is wrong or if I'm just generally an idiot. I'm not new to OOP or programming in general, but the object model for InDesign is a bit of a mystery to me.




      I'm trying to write a script that goes through an indesign file page by page and exports the text from various textframes based on their labels. If i understand the way it's organized, I believe the label is a child of the textframe. There are like 4 or 5 labels that I am interested in, but not all labels exist on all pages.


      I have it all working more or less perfectly, except that if a textframe with the specified label doesn't appear on a given page, the script will crash. I'm looking for a way to do a conditional statement that will only execute if a textframe the label exists, but I can't seem to figure out how I can test for that. Is there a built-in method that i'm missing?


      I'm working in VBScript, and it's indesign cs3.


      Can anyone help me out here?

        • 1. Re: Determining if a label exists
          Harbs. Level 6

          If you give us a code snippet of what yiou currently have, we could help with the conditional statement...



          • 2. Re: Determining if a label exists
            jerk22 Level 1

            Hi Harbs.


            Basically what I have is something like this:




            frameType = "abc"


            If Not (page.TextFrames.Item(frameType) is Nothing) Then
               page.TextFrames.Item(frameType).ParentStory.Export idExportFormat.idTaggedText, "C:\" & frameType & "_output.txt"
               Else msgBox "frame " & frameType & " doesn't exist."
            End If





            So I'm looking for a TextFrame with the label "abc" and then outputting it to a text file.


            The problem is getting the If statement to work properly. If i omit the if statement altogether, the code works fine to do what i want as long as a TextFrame with label "abc" exists. However, if no such TextFrame exists, it'll fail.


            I've tried several variations on the If statement and nothing has worked so far.

            • 3. Re: Determining if a label exists
              Harbs. Level 6

              If you are using CS4 or CS5, you can use (in js syntax):



              // do your stuff



              If you are using CS3 or lower, you'll need to wrap it in a try/catch.



              • 5. Re: Determining if a label exists
                Kasyan Servetsky Level 5

                Let's assume you have a single text frame selected:

                Set myInDesign = CreateObject("InDesign.Application.CS3")
                Set mySelection = myInDesign.Selection(1)
                If mySelection.Label = "" Then
                  MsgBox("The selected object has no label")
                  MsgBox("The selected object has label: " & mySelection.Label)
                End If