Search code examples
pythonadobe-indesign

Python script in InDesign - Index out of range


I'm trying out to run Python scripts in InDesign. Python script is triggered by either a .vbs or a .jsx script and the Python code executes correctly. However I'm running into a problem with trying to access items with index of over 255 - it is uniformly over 255. Anything under 255 works fine.

Example (works):

import win32com.client
app = win32com.client.Dispatch('InDesign.Application.CC.2014')
app.Select (app.ActiveDocument.Stories[0].Characters[100]) //index 100

Example (does not work):

import win32com.client
app = win32com.client.Dispatch('InDesign.Application.CC.2014')
app.Select (app.ActiveDocument.Stories[0].Characters[300]) //index 300

There are over 1500 Characters in the Story. The same happens with other DOM objects such as Words or Paragraphs.

The error is uniformly - IndexError: list index out of range

Did anyone else run into this?


Solution

  • Try to change this:

    app.Select (app.ActiveDocument.Stories[0].Characters[300])
    

    with this:

    app.Select (app.ActiveDocument.Stories[0].Characters.Item(300))