• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Footnote number manipulation! …

LEGEND ,
Dec 08, 2016 Dec 08, 2016

Copy link to clipboard

Copied

Hi all Scripters,

If I suppose a very simple situation: 1 doc, 1 story, the first footnote beginning at 1, I can imagine It could be simple to insert a label to each footnote, the label corresponding to its real number (as its index+1 … but I'm not interested by playing with the "index").

I'm totally new about the "label" feature. If I understood well it, I could do "maths" with it!

In the code below, I've inserted the number "18" as label to the first note and, in the alert, I've added "15". So the result is "33"! as expected!

var myDoc = app.activeDocument;

var myNotes = myDoc.stories.everyItem().footnotes.everyItem().getElements();

var myNote = myNotes[0];

var X = 18;

var myX = String(X);

myNote.insertLabel("Obi-wan", myX); 

alert(Number(myNote.extractLabel("Obi-wan"))+15); // = 33!  😉

At this step, my simple question is:

How could I write code to insert this number "before" (or after) the corresponding footnote character?

No idea! 

Thanks in advance!

(^/)

TOPICS
Scripting

Views

954

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 09, 2016 Dec 09, 2016

Hi Obi-wan,

sorry again. That was a big, big lapse on my side.

Don't know how this could happen:

I linked to the right property storyOffset and wrote about documentOffset, which is dead wrong.

So my answer above should read:

Hi Obi-wan,

Footnote Objects have the property storyOffset.

That's an insertionPoint object.

That insertionPoint has an index property with a value, that denotes its position in regards of its parent, the story.

To add contents before the footnote you simply do this:

myFootnote.storyO

...

Votes

Translate

Translate
Community Expert ,
Dec 08, 2016 Dec 08, 2016

Copy link to clipboard

Copied

Hi Obi-wan,

Footnote Objects have the property documentOffset.

That's an insertionPoint object.

That insertionPoint has an index property with a value, that denotes its position in regards of its parent, the story.

To add contents before the footnote you simply do this:

myFootnote.documentOffset.content = "New Contents";

To add contents after the footnote is a bit more complicated:

myFootnote.parent.insertionPoints[myFootnote.storyOffset.index+1].contents = "New Contents";

Note: If you insert contents after the footnote, be aware of its formatting.

The new contents will be formatted like the footnote.

See also here:

Adobe InDesign CS6 (8.0) Object Model JS: Footnote

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

Thanks Uwe! 

About adding contents "after", the code works cool! I'll use it in my project!

… but the code about adding contents "before" doesn't work and I can't find info about "documentOffset"!!!

More questions:

My deal is to add a label to some footnote markers and insert its value after it, as here, for the notes 1 & 2:

Capture d’écran 2016-12-09 à 12.03.22.png

Can I make a kind of "link" between the value label defined by the script and the number inserted in ID, as:

"Hey ID, this "number" i've inserted in the text is the label of a footnote! If its value [the value of the footnote label] changes, you'll be very cool to change the "number" too!"

I mean that if the numbering changes, can I "update" this "number"?

Here, it could be easy to fix it because the "number" is just "after" the footnote marker, but, in reality, it won't be!!!

In the same way, could I give a label to a "character" in text?

Thanks in advance! 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

Obi-wan Kenobi wrote:

… About adding contents "after", the code works cool! I'll use it in my project!

… but the code about adding contents "before" doesn't work and I can't find info about "documentOffset"!!!

Why did it not work?
What happened exactly?

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

Obi-wan Kenobi wrote:

… In the same way, could I give a label to a "character" in text?

No, you can't.

You can give a Footnote a label, a Story, a Note, even a Table or a Cell, but you cannot give a Text a label.

Maybe you could work with a HiddenText object?

Just download Jongware's excellent iChm files and search for label .
That will give you a good overview what objects contain the label property.

Indesign JavaScript Help

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

Uwe,

I corrected it before answering but it doesn't work for me! 

About "Label" limitation not to text, grrr!

About the formatting, when I add "after", I have the "footnote marker" style applied: good!

When the deal is finished, this marker becomes "invisible" by a grep style! Good too!!

So, it's totally OK for me!

Thanks Uwe!

More explanations later when I'll be more advanced on my project! 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

Michel,

> In the same way, could I give a label to a "character" in text?

By now you should be aware of (one or more incarnations of) the object-model viewer. . .

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

Hi Peter,

Yeap!    It's my personal bible now + your great book (Scripting InDesign CS3/4 with JavaScript - O'Reilly Media  read thousands of times now!)

+ :

JavaScript | MDN

InDesign ExtendScript API (11.0)

Adobe InDesign CS5.5 (7.5) Object Model JS: FootnoteOption

As I said to Uwe, I found nothing about "documentOffset" and it doesn't work for me! 

As usual, without knowing it, maybe you gave me a way to answer to my question:

Use text anchors! whose name is the footnote label calculated by the script!

If the script recalculates the label (= footnote number), I'll only need the cross-references to be updated!

[ … More explanations later about this new baby!  ]

(^/) 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

Hi Obi-wan,

sorry again. That was a big, big lapse on my side.

Don't know how this could happen:

I linked to the right property storyOffset and wrote about documentOffset, which is dead wrong.

So my answer above should read:

Hi Obi-wan,

Footnote Objects have the property storyOffset.

That's an insertionPoint object.

That insertionPoint has an index property with a value, that denotes its position in regards of its parent, the story.

To add contents before the footnote you simply do this:

myFootnote.storyOffset.content = "New Contents";

To add contents after the footnote is a bit more complicated:

myFootnote.parent.insertionPoints[myFootnote.storyOffset.index+1].contents = "New Contents";

Note: If you insert contents after the footnote, be aware of its formatting.

The new contents will be formatted like the footnote.

See also here:

Adobe InDesign CS6 (8.0) Object Model JS: Footnote

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 10, 2016 Dec 10, 2016

Copy link to clipboard

Copied

LATEST

Hi Uwe,

You are totally forgiven and I should have corrected myself!

… I'm too concentrate on the script globally!!

(^/) 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

Before answering any questions that you raised after my answer in # 1 I did some notes that I want to add.

Also note:

1. If you want to add both,

new contents before and after the footnote,

first do the after,

then the before.

Otherwise the added contents before the footnote will shift the footnote away from its original index value in the story and you end with all the text—before and after—positioned before the footnote.

Maybe obsolete, maybe not:

2. Now we can debate how the added text should be formatted.

Be aware, that you are always using the formatting of the insertionPoint if you are assigning a string to the property contents.

If you do not like this and want more control over formatting:

a. Create a temp text frame

b. Assign the string to the first insertion point there

c. Format the text by whatever means you like,

but best use the applied paragraph style of myFootnote.storyOffset

d. finally move the text to the insertionPoint with e.g.

tempTextFrame.parentStory.move( LocationOptions.AT_BEGINNING , myFootnote.storyOffset);

( and don't forget to remove the temp text frame )

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

Made a typo in my first reply:

myFootnote.documentOffset.content

should be:

myFootnote.documentOffset.contents

Sorry for this,

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines