-1

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?

Michael
  • 75
  • 9

1 Answers1

0

Try to change this:

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

with this:

app.Select (app.ActiveDocument.Stories[0].Characters.Item(300))
Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23
  • Can't take away the downvote. Upvoted another your question. As for the 'why can't index' — because 'Characters' is one of the internal 'collections' that mimic Arrays, not entirely successfully for some edge cases like this, I suppose. – Yuri Khristich Aug 10 '23 at 07:52
  • Thanks. I wonder how ItemByRange() is supposed to work without normal indexes... I guess I'll try passing actual Character objects as range limiters. Hopefully this will work. – Michael Aug 12 '23 at 06:36