0 Replies Latest reply on Mar 28, 2011 1:12 PM by JoeAtGBF

    Need help with a numbering script

    JoeAtGBF

      I'm somewhat new to scripts. Where I work we have a script that does consecutive numbering. It is for funning checks. So the numbering gets placed in usually 4 different text boxes already set up in our templates, so number 0001 would be on page 1 4 times, and page 2 would get number 0002, and so on, depending on how many we need to print. I select the 4 boxes then run the script, being prompted to enter in starting number and number of forms and some other additional details that currently still work, its just that it goes so slow. The person working here prior to myself set up our current scripts back when CS2 was new. Well his scripts haven't worked properly with CS3, CS4, or CS5. It will do the numbering, but it goes very slow. So we are stuck back on CS2 for InDesign for this reason. Can anyone help me out in how to speed it up? In CS2 it wouldn't update the screen with every new additional page and number, but it seems to do that in CS5. If I minimize it while it is going then it goes about twice as fast, but still only at about half the speed of CS2 running the same thing. The current script is written in vbs. I have pasted it below. Any help in optimizing this would be great. We are currently using CS5 only as a trial right now. I've tried reading through the guides Adobe provides on their website, but it's been awhile since I've taken any kind of programming class. Thank you in advance for any help or attempts at helping.

       

      Rem Laser Check Numbering
      Set myInDesign = CreateObject("InDesign.Application.CS5")
      myInDesign.Activate
      Set myDocument = myInDesign.ActiveDocument
      Rem Select all objects on page 1
      Set mySelection = myInDesign.Selection
      If mySelection.Count = 0 then
          Msgbox "You need to select at least one text box to continue."
      Else
          If myDocument.Pages.Count > 1 then
              Msgbox "To properly execute this script your document must contain only 1 page."
          Else
          Set myDialog = myInDesign.Dialogs.Add
          myDialog.CanCancel = True
          myDialog.Name = "Check Auto Numbering"
            Rem Create a dialog column.
            Set myDialogColumn = myDialog.DialogColumns.Add
              Rem Create a border panel.
              Set myBorderPanel = myDialogColumn.BorderPanels.Add
                Rem Create a dialog column inside the border panel.
                Set myTempDialogColumn = myBorderPanel.DialogColumns.Add
                  Set myStaticText = myTempDialogColumn.StaticTexts.Add
                  myStaticText.StaticLabel = "Starting Number:"
                  Set myStaticText = myTempDialogColumn.StaticTexts.Add
                  myStaticText.StaticLabel = "No. of Checks:"
                Rem Create another dialog column inside the border panel.
                Set myTempDialogColumn = myBorderPanel.DialogColumns.Add
                Set myStartNumberField = myTempDialogColumn.RealEditboxes.Add
                myStartNumberField.EditValue = 1000
                myStartNumberField.MinWidth = 100
                Set myTotNumberField = myTempDialogColumn.RealEditboxes.Add
                myTotNumberField.EditValue = 1000
                myTotNumberField.MinWidth = 100
              Rem Create another border panel.
              Set myBorderPanel = myDialogColumn.BorderPanels.Add
                Rem Create a dialog column inside the border panel.
                Set myTempDialogColumn = myBorderPanel.DialogColumns.Add
                  Set myNumSpaceBox = myTempDialogColumn.CheckboxControls.Add
                  myNumSpaceBox.StaticLabel = "Set Numbering Spaces:"
                  Set myDescValBox = myTempDialogColumn.CheckboxControls.Add
                  myDescValBox.StaticLabel = "Reverse Collate (Face Down)"
                Rem Create another dialog column inside the border panel.
                Set myTempDialogColumn = myBorderPanel.DialogColumns.Add
                  Set mySpacingField = myTempDialogColumn.RealEditboxes.Add
                  mySpacingField.MinWidth = 50
                  mySpacingField.EditValue = 6
          If myDialog.Show = True Then
              Rem Get the values from the dialog box controls.
              myStartNumber = myStartNumberField.EditValue
              myTotNumber = myTotNumberField.EditValue
              mySetSpaces = myNumSpaceBox.CheckedState
              If mySetSpaces then
                  mySpacing = mySpacingField.EditValue
              Else
                  mySpacing = 0
              End If
              If myDescValBox.CheckedState Then
                  myIncrement = -1
                  i = myStartNumber + myTotNumber - 1
                  myEndingNumber = myStartNumber - 1
              Else
                  myIncrement = 1
                  i = myStartNumber
                  myEndingNumber = myStartNumber + myTotNumber
              End If
              Rem Remove the dialog box from memory.
              myDialog.Destroy
          End If
          myPageNum = 0
          Set mySelection = myInDesign.Selection
          Rem Loop once for each check
          do until myPageNum = myTotNumber
              myPageNum = myPageNum + 1
              if myPageNum <> 1 then
                  myDocument.Pages.Add
              End If
              j = 0
              Rem Loop once for each selected text box
              do until j = mySelection.Count
                  Set myOriginal = mySelection(j+1)
                  if myPageNum = 1 then
                      Set myTextFrame = myOriginal
                  else
                      set myTextFrame = myDocument.Pages.Item(myPageNum).TextFrames.Add
                      myTextFrame.GeometricBounds = myOriginal.GeometricBounds
                      myTextFrame.Texts.Item(1).PointSize = myOriginal.Texts.Item(1).Pointsize
                      myTextFrame.Texts.Item(1).AppliedFont = myOriginal.Texts.Item(1).AppliedFont
                      myTextFrame.Texts.Item(1).Tracking = myOriginal.Texts.Item(1).Tracking
                      myTextFrame.Texts.Item(1).FillColor = myOriginal.Texts.Item(1).FillColor
                      myTextFrame.Texts.Item(1).FillTint = myOriginal.Texts.Item(1).FillTint
                      myTextFrame.Texts.Item(1).Justification = myOriginal.Texts.Item(1).Justification
                      myTextFrame.Texts.Item(1).StrokeWeight = myOriginal.Texts.Item(1).StrokeWeight
                      myTextFrame.Texts.Item(1).StrokeColor = myOriginal.Texts.Item(1).StrokeColor
                      myTextFrame.Texts.Item(1).StrokeTint = myOriginal.Texts.Item(1).StrokeTint
                  End If
                  Rem Check which type of font is in the current text box
                  if myTextFrame.Texts.Item(1).AppliedFont = "MICR Medium" then
                      myTextFrame.Contents = formatText(cstr(i), 6)
                  Else
                      myTextFrame.Contents = formatText(cstr(i), mySpacing)
                  End If
                  j = j + 1
              Loop
              i = i + myIncrement
          Loop
      End If
      End If
      Rem This function formats a string to a specific length with left leading zeros
      function formatText(myString, myLength)
          if (myLength = 0) or (len(myString) >= myLength) then
              formatText = myString
          else
              myReturnStr = ""
              for counter = 1 to (myLength - len(myString))
                  myReturnStr = myReturnStr + "0"
              next
              myReturnStr = myReturnStr + myString
              formatText = myReturnStr
          end if
      end function