Skip to main content
robm79025330
Participating Frequently
January 21, 2020
Answered

My modified script don't work anymore in CC2020

  • January 21, 2020
  • 2 replies
  • 1162 views

I've got a script that put footnotes to the end of the text file as plain text, so I can use it on other places in the document. in CC2019 it works but now it won't work. I've try to debug it with "ExtendScript Toolkit", but that don't work (error: "Cannot execute script in target engine 'main'! (#1116) Can't start debug session.")

the script is as follows:

//DESCRIPTION: convert footnotes to dynamic (cross-referenced) endnotes
// Peter Kahrel -- www.kahrel.plus.com
 
// June 2010 fix: script now deals all stories with footnotes or a single selected story
// and with footnotes with more than one paragraph.
 
#target indesign;
 
// Only CS4 and later
if (parseInt (app.version) > 5 && app.documents.length > 0)
    try {foot_to_end (app.documents[0], "endnote___")}
        catch (e) {alert (e.message + " (line " + e.line + ")")};
 
//-----------------------------------------------------------------------------------------------
 
function foot_to_end (doc, stylename)
    {
    var endnote, footn, endnote_link, cue;
    var note_styles = add_styles (stylename);
    var stories = find_stories (doc);
for (var j = 0; j < stories.length; j++)
{
if (stories[j].footnotes.length > 0)
{
footn = stories[j].footnotes;
for (var i = 0; i < footn.length; i++)
{
stories[j].insertionPoints[-1].contents = '\r';
endnote = footn[i].texts[0].move (LocationOptions.after, stories[j].insertionPoints[-1]);
endnote.applyParagraphStyle (note_styles.first, false);
if (endnote.paragraphs.length > 1)
endnote.paragraphs.itemByRange (1,-1).applyParagraphStyle (note_styles.next, false);
endnote_link = doc.paragraphDestinations.add (endnote.insertionPoints[0]);
cue = doc.crossReferenceSources.add (footn[i].storyOffset, note_styles.cr_format);
doc.hyperlinks.add (cue, endnote_link, {visible: false});
} // for
delete_notemarkers (stories[j]);
} //if
} // for
    doc.crossReferenceSources.everyItem().update();
}
 
 
 
function find_stories (doc)
{
var array = [];
// no selection: return all stories
if (app.selection.length == 0)
return doc.stories.everyItem().getElements();
else
try {app.selection[0].parentStory; return [app.selection[0].parentStory]}
catch (e) {alert ("Invalid selection", "Convert footnotes", true); exit ()}
}
 
 
function delete_notemarkers (scope)
    {
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findChangeGrepOptions.includeFootnotes = true;
    app.findGrepPreferences.findWhat = '~F';
    scope.changeGrep ();
    }
 
 
function add_styles (n)
    {
// Create styles and cross-ref format or return them if they exist
    try
        {
        var char_style = app.activeDocument.characterStyles.add ({name: n});
        char_style.position = Position.superscript;
        }
catch (_){char_style = app.activeDocument.characterStyles.item (n)};
 
    try {var p = app.activeDocument.paragraphStyles.add ({name: n + "nonum"})}
catch (_) {var p = app.activeDocument.paragraphStyles.item (n + "nonum")};
 
    try
        {
        var par_style = app.activeDocument.paragraphStyles.add ({name: n, basedOn: p});
        par_style.bulletsAndNumberingListType = ListType.numberedList;
        }
catch (_) {var par_style = app.activeDocument.paragraphStyles.item (n)};
 
    try
        {
        var cr = app.activeDocument.crossReferenceFormats.add ({name: n});
        cr.appliedCharacterStyle = app.activeDocument.characterStyles.item (n);
        cr.buildingBlocks.add (BuildingBlockTypes.paragraphNumberBuildingBlock);
        }
catch (_){cr = app.activeDocument.crossReferenceFormats.item (n)}
return {first: par_style, next: p, cr_format: cr}
    }

Who can help me?

 

This topic has been closed for replies.
Correct answer Peter Kahrel

Oké?!?

Than I have to search further into other areas for what courses the problem.

Thanks for your support.

 


Rob -- The script you showed is very old, there's a newer version here:
https://creativepro.com/files/kahrel/indesign/foot_to_endnote.html

This one still converts footnotes to using cross-references for numbers, but it's fairly straightforward to convert those cross-references to plain text:

1. Select the endnotes, then convert the automatic numbers to text (Type > Bulleted & Numbered lists ? Convert to text).

2. In the cross-references panel, delete the cross-references used for notes. This converts them to plain text.

 

Peter

2 replies

Community Expert
January 21, 2020

Seems to be working for me, i created a simple document with a single story and 2 footnotes and it seems to have converted the footnotes into cross references. See the screengrab of what i get at my end and let me know how this differs from whats happening at your end

https://www.dropbox.com/s/vyub3hl6jyby3q0/screen%20recording%202020-01-21%20at%206.45.28%20pm.mov?dl=0

 

-Manan

-Manan
robm79025330
Participating Frequently
January 21, 2020

Hi Manan,

Is it exectly the script I given, because its not working at all and the footnotes must be plain text not crossreferences.

Community Expert
January 21, 2020

Yes Rob, its exactly the script you have posted, and the script does have code to add cross references look at the following line from the code you posted that adds the crossreference

doc.crossReferenceSources.add (footn[i].storyOffset, note_styles.cr_format)

  

-Manan

-Manan
Community Expert
January 21, 2020

Hi Rob,

 

The issue that you are getting while debugging is a known problem in MAC and it can be fixed, see the following discussion

https://community.adobe.com/t5/photoshop/cannot-execute-script-in-target-engine-main-1116-can-t-start-debug-session/td-p/10201477

 

Now regarding the script error, you would have to give us more information than just saying its not working.

  • Does it error out? What is the error message
  • Does it die silently, does nothing?
  • Does it do something but its a new behaviour
  • Does it happen on all the documents or some special cases

 

-Manan

-Manan
robm79025330
Participating Frequently
January 21, 2020

Hi Manam,

Thanks for fast reaction.

 

The Script "die silently" and it happen to every document.

 

The bug in "ExtendScript Toolkit" is fixed now.

It won't help for resolving the script problem 😞

robm79025330
Participating Frequently
January 21, 2020

Sorry for write your name wrong, "Manan"