0

The type of a Note’s parent or storyOffset property depends on whether the note was obtained from a Text or a Story. Why? How to deal cleanly with this in code working on a Note without knowing where it came from?

The following scripts expose the situation.

// INDESIGN CS6 8.1 VERSION

var doc = app.documents.add();
doc.pages.item(0).textFrames.add();
var story = doc.stories[0];
story.insertionPoints[0].contents = "x";
story.insertionPoints[0].notes.add();
var range = story.texts.itemByRange(story.characters.item(0),
                                    story.characters.item(1));

alert(  story  .notes[0].parent.constructor.name);      // "InsertionPoint"
alert(  range  .notes[0].parent.constructor.name);      // "Array"

alert(  story  .notes[0].storyOffset.constructor.name); // "InsertionPoint"
alert(  range  .notes[0].storyOffset.constructor.name); // "Array"

 

// INCOPY CS6 8.1 VERSION

app.documents.add();
var story = app.selection[0].parentStory;
story.insertionPoints[0].contents = "x";
story.insertionPoints[0].notes.add();
var range = story.texts.itemByRange(story.characters.item(0),
                                    story.characters.item(1));

alert(  story  .notes[0].parent.constructor.name);      // "InsertionPoint"
alert(  range  .notes[0].parent.constructor.name);      // "Array"

alert(  story  .notes[0].storyOffset.constructor.name); // "InsertionPoint"
alert(  range  .notes[0].storyOffset.constructor.name); // "Array"
RobC
  • 22,977
  • 20
  • 73
  • 80

1 Answers1

0

You have to test for every parent constructor that you want to handle. See the documentation for the class hierarchy of a Text object. For example, use a function like this:

var isText = function(text) {
   var c = text.constructor;
   return c === Paragraph || c === Line || c === Word
      || c === Text || c === TextStyleRange || c === Story
      || c === InsertionPoint || c === TextColumn;
}

isText(story.notes[0].parent) // => true
Josh Voigts
  • 4,114
  • 1
  • 18
  • 43