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

Convert text to Footnote with an applied style

Explorer ,
Jun 16, 2018 Jun 16, 2018

Copy link to clipboard

Copied

Hi,

I tried to use the below script written by Jump_Over​ (Big thanks to him for easing up this time consuming task) to convert text to footnote.

var  

    myDoc = app.activeDocument, 

mStory = app.selection[0].texts[0].parentStory, 

    mEndNotes = myDoc.textFrames.add( {name:"EndNotes"} ), 

    k, len, cIP, currPara, currFoot, mMarkers; 

 

app.findGrepPreferences = app.changeGrepPreferences = null; 

//--------------------------------------------- 

// edit doc.footnoteOption here 

with (myDoc.footnoteOptions)  

    { 

    showPrefixSuffix = FootnotePrefixSuffix.PREFIX_SUFFIX_BOTH; 

    prefix = "["; 

    suffix = "]"; 

    separatorText = "\t"; 

    markerPositioning = FootnoteMarkerPositioning.NORMAL_MARKER; 

    } 

//------------------------------------------------------------ 

// move endnotes to a separate textFrame 

for (k=mStory.paragraphs.length - 1; k >=0; k--)  

    { 

    if (mStory.paragraphs.contents.search(/^\[\d+\]/) == 0)  

        { 

        currPara = mStory.paragraphs.move(LocationOptions.AT_BEGINNING, mEndNotes.parentStory); 

        currPara.words[0].remove(); 

        } 

    } 

//-------------------------------------- 

// create footnote markers 

app.findGrepPreferences.findWhat = "\\[\\d+\\]"; 

mMarkers = mStory.findGrep(); 

len = mMarkers.length; 

while (len-->0) { 

    cIP = mMarkers[len].insertionPoints[0].index; 

    mMarkers[len].remove(); 

    mStory.footnotes.add( LocationOptions.AFTER, mStory.insertionPoints[cIP] ); 

    } 

//------------------------------------------------------- 

// fill footnote contents with proper text 

for (k=0; k < mStory.footnotes.length; k++) { 

    currFoot = mStory.footnotes

    mEndNotes.paragraphs[0].texts[0].move(LocationOptions.AT_END, currFoot.texts[0]); 

    if (mStory.footnotes.characters[-1].contents == "\r") mStory.footnotes.characters[-1].remove(); 

    } 

 

mEndNotes.remove(); 

Before applying the script:

1. All the notes had a different paragraph style say, "Body Text" having a particular style.

2. In order to apply my own style, I dropped down "Footnote Para Style" for Paragraph Style under Footnote Formatting and "Footnote Ref Style" for Character Style under Footnote Reference in Document Footnote Options.

After doing this, I ran the above script.

The script placed all the footnotes perfectly but the Document Footnotes Options did not force the user defined Para and Char Style and went ahead with the earlier Para Style of notes ("Body Text"). I had to manually override all the footnotes to apply user defined paragraph style; which becomes a tedious task if there are 400 or more footnotes in the story.

Is there a way to tweak the script in such a way that it applies Document Footnote Options defined Para and Char styles without over-riding local styles. Any help would be greatly appreciated.

Regards,

Aman Mittal

TOPICS
Scripting

Views

322

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
no replies

Have something to add?

Join the conversation