Skip to main content
priyasreek
Known Participant
August 3, 2017
Question

processing instructions paragraphs

  • August 3, 2017
  • 3 replies
  • 849 views

I need to store some value for each and every paragraphs in the file.

Any user defined property available for paragraphs.

This topic has been closed for replies.

3 replies

priyasreek
Known Participant
August 5, 2017

good

priyasreek
Known Participant
August 4, 2017

I want to append a unique value to the end of paragraph for identification purposes

Community Expert
August 4, 2017

Hi,

you could add a Note object.


See into this:

Adobe InDesign CS6 (8.0) Object Model JS: Note

Adobe InDesign CS6 (8.0) Object Model JS: Notes

Two ways to go:

1. Your unique value could be stored to the label property of the Note object. Use note.insertLabel( "keystring" , "valuestring") for providing a string. Read out its value by using note.extractLabel( "keystring" ) .


2. You can even add formatted text ( plus anchored frames etc.pp.) with the Note object itself.
Just provide some text in a text frame and move or duplicate it to the note.

Whatever fit your needs.

Search the forum for some code adding and using note objects to an insertion point.

Regards,
Uwe

Community Expert
August 4, 2017

Here a snippet that will add a Note object to the end of a paragraph.
Just select an insertion point and run the snippet:

// Insertion point of some text selected:

var paragraph = app.selection[0].paragraphs[0];

// Two cases:

// 1. Paragraph ends with a paragraph marker:

if(paragraph.characters[-1].contents == "\r")

{

    var lastInsertionPoint = paragraph.insertionPoints[-2];

}

else

// 2. Paragraph does not end with a paragraph marker:

{

    var lastInsertionPoint = paragraph.insertionPoints[-1];

}

// Add a note at last insertion point:

var note = lastInsertionPoint.notes.add({ collapsed : false });

// Add some instructions inside the note, that can be read in Story Editor Window:

note.texts[0].contents =

Date.now().toString() +"\r"+

"Processing Instruction: Do something with that paragraph!";

If you open the the text in Story Window you'll see this:

One could debate if Date.now().toString() will create a unique string, but for the moment it will fit.

Regards,
Uwe

Participating Frequently
August 3, 2017

Need a bit more information.

Are you wanting to make a data file with some unique value for each paragraph? Or append a unique value to the end of paragraph for identification purposes?

A text frame can have multiple paragraphs as well (plus hard and soft return paragraphs present another issue), do you need the id of the text frame each and every paragraph is associated with as well?

What is the end goal for such a script? What will and how will this be used?